portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jf...@apache.org
Subject cvs commit: jakarta-jetspeed/src/java/org/apache/jetspeed/services/psmlmanager CastorPsmlManagerService.java
Date Sat, 28 Aug 2004 19:07:00 GMT
jford       2004/08/28 12:07:00

  Modified:    src/java/org/apache/jetspeed/services/psmlmanager
                        CastorPsmlManagerService.java
  Log:
  Added support for messaging
  
  Revision  Changes    Path
  1.46      +171 -8    jakarta-jetspeed/src/java/org/apache/jetspeed/services/psmlmanager/CastorPsmlManagerService.java
  
  Index: CastorPsmlManagerService.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/services/psmlmanager/CastorPsmlManagerService.java,v
  retrieving revision 1.45
  retrieving revision 1.46
  diff -u -r1.45 -r1.46
  --- CastorPsmlManagerService.java	27 Apr 2004 21:41:36 -0000	1.45
  +++ CastorPsmlManagerService.java	28 Aug 2004 19:07:00 -0000	1.46
  @@ -21,11 +21,14 @@
   import org.apache.jetspeed.om.profile.QueryLocator;
   import org.apache.jetspeed.util.FileCopy;
   import org.apache.jetspeed.util.DirectoryUtils;
  +import org.apache.jetspeed.services.Messenger;
   import org.apache.jetspeed.services.Profiler;
   import org.apache.jetspeed.services.logging.JetspeedLogFactoryService;
   import org.apache.jetspeed.services.logging.JetspeedLogger;
  +import org.apache.jetspeed.services.messaging.MessagingService;
   import org.apache.jetspeed.services.JetspeedSecurity;
   import org.apache.jetspeed.services.resources.JetspeedResources;
  +import org.apache.jetspeed.services.security.JetspeedSecurityException;
   
   //Castor defined API
   import org.apache.jetspeed.om.profile.Portlets;
  @@ -67,6 +70,7 @@
   import java.io.File;
   import java.io.Reader;
   import java.io.FileReader;
  +import java.io.Serializable;
   import java.io.Writer;
   import java.io.FileOutputStream;
   import java.io.OutputStreamWriter;
  @@ -74,6 +78,11 @@
   import java.util.Iterator;
   import java.util.List;
   import java.util.LinkedList;
  +
  +import javax.jms.JMSException;
  +import javax.jms.Message;
  +import javax.jms.MessageListener;
  +import javax.jms.ObjectMessage;
   import javax.servlet.ServletConfig;
   import javax.xml.parsers.DocumentBuilder;
   import javax.xml.parsers.DocumentBuilderFactory;
  @@ -94,7 +103,8 @@
    */
   public class CastorPsmlManagerService extends TurbineBaseService
                                         implements FileCacheEventListener,
  -                                                 PsmlManagerService
  +                                                 PsmlManagerService,
  +                                                 MessageListener
   {
       /**
        * Static initialization of the logger for this class
  @@ -151,6 +161,8 @@
   
       /** The default encoding used to serialize PSML files to disk */
       protected String defaultEncoding = JetspeedResources.getString(JetspeedResources.CONTENT_ENCODING_KEY,
"utf-8");
  +    
  +    private boolean enableMessaging = false;
   
       /**
        * This is the early initialization method called by the
  @@ -165,6 +177,21 @@
   
           //Ensure that the servlet service is initialized
           TurbineServices.getInstance().initService(ServletService.SERVICE_NAME, conf);
  +        
  +        this.enableMessaging = getConfiguration().getBoolean("enable_messaging", false);
  +        if(enableMessaging)
  +        {
  +            try
  +            {
  +                TurbineServices.getInstance().initService(MessagingService.SERVICE_NAME,
conf);
  +                Messenger.addMessageListener(this, CastorPsmlManagerService.class.getName(),
MessagingService.PSML_UPDATE_SUBJECT);
  +            }
  +            catch(Exception e)
  +            {
  +                enableMessaging = false;
  +                logger.warn("Messaging support has been disabled due to a failure to initialize
the service or add a listener.");
  +            }
  +        }
   
           // get configuration parameters from Jetspeed Resources
           ResourceService serviceConf = ((TurbineServices)TurbineServices.getInstance())
  @@ -520,6 +547,12 @@
                   logger.error("Error storing document", e);
               }
           }
  +        
  +        if(ok && enableMessaging)
  +        {
  +            Message msg = createMessage(profile);
  +            Messenger.sendMessage(msg, MessagingService.PSML_UPDATE_SUBJECT);
  +        }
   
           return ok;
       }
  @@ -765,6 +798,11 @@
        */
       public void removeDocument( ProfileLocator locator )
       {
  +        removeDocument(locator, enableMessaging);
  +    }
  +    
  +    public void removeDocument(ProfileLocator locator, boolean sendMessage)
  +    {
           // remove a single document
           String fileName = mapLocatorToFile(locator);
   
  @@ -781,21 +819,30 @@
               logger.error("PSMLManager: unable to resolve file path for "+ file);
           }
   
  -
           synchronized (documents)
           {
               documents.remove(name);
           }
   
           file.delete();
  -
  +        
  +        if(sendMessage)
  +        {
  +            Message msg = createMessage(locator);
  +            Messenger.sendMessage(msg, MessagingService.PSML_UPDATE_SUBJECT);
  +        }
       }
   
       /** Removes all documents for a given user.
        *
        * @param user The user object.
        */
  -    public void removeUserDocuments( JetspeedUser user )
  +    public void removeUserDocuments(JetspeedUser user)
  +    {
  +        removeUserDocuments(user, enableMessaging);
  +    }
  +    
  +    public void removeUserDocuments( JetspeedUser user, boolean sendMessage)
       {
           ProfileLocator locator = Profiler.createLocator();
           locator.setUser(user);
  @@ -823,7 +870,6 @@
               logger.error("PSMLManager: unable to resolve file path for "+ file);
           }
   
  -
           synchronized (documents)
           {
               DirectoryUtils.rmdir(name);
  @@ -848,13 +894,26 @@
               }
           }
   
  +        if(sendMessage)
  +        {
  +            PsmlMessage psmlMessage = new PsmlMessage();
  +            psmlMessage.setUser(user.getUserName());
  +            psmlMessage.setAction(PsmlMessage.REMOVE_ACTION);
  +            Message message = createMessage(psmlMessage);
  +            Messenger.sendMessage(message, MessagingService.PSML_UPDATE_SUBJECT);
  +        }
       }
   
       /** Removes all documents for a given role.
        *
        * @param role The role object.
        */
  -    public void removeRoleDocuments( Role role )
  +    public void removeRoleDocuments(Role role)
  +    {
  +        removeRoleDocuments(role, enableMessaging);
  +    }
  +    
  +    public void removeRoleDocuments(Role role, boolean sendMessage)
       {
           ProfileLocator locator = Profiler.createLocator();
           locator.setRole(role);
  @@ -906,6 +965,15 @@
                   }
               }
           }
  +        
  +        if(sendMessage)
  +        {
  +            PsmlMessage psmlMessage = new PsmlMessage();
  +            psmlMessage.setRole(role.getName());
  +            psmlMessage.setAction(PsmlMessage.REMOVE_ACTION);
  +            Message message = createMessage(psmlMessage);
  +            Messenger.sendMessage(message, MessagingService.PSML_UPDATE_SUBJECT);
  +        }
       }
   
       /** Removes all documents for a given group.
  @@ -914,6 +982,11 @@
        */
       public void removeGroupDocuments( Group group )
       {
  +        removeGroupDocuments(group, enableMessaging);
  +    }
  +    
  +    public void removeGroupDocuments(Group group, boolean sendMessage)
  +    {
           ProfileLocator locator = Profiler.createLocator();
           locator.setGroup(group);
           StringBuffer buffer = new StringBuffer();
  @@ -964,7 +1037,15 @@
                   }
               }
           }
  -
  +        
  +        if(sendMessage)
  +        {
  +            PsmlMessage psmlMessage = new PsmlMessage();
  +            psmlMessage.setGroup(group.getName());
  +            psmlMessage.setAction(PsmlMessage.REMOVE_ACTION);
  +            Message message = createMessage(psmlMessage);
  +            Messenger.sendMessage(message, MessagingService.PSML_UPDATE_SUBJECT);
  +        }
       }
   
   
  @@ -1565,5 +1646,87 @@
           System.out.println("entry is evicting: " + entry.getFile().getName());
       }
   
  +    private Message createMessage(Serializable messageObject)
  +    {
  +        ObjectMessage msg = (ObjectMessage) Messenger.createMessage(MessagingService.OBJECT_MESSAGE);
  +        
  +        try
  +        {
  +            msg.setObject(messageObject);
  +        }
  +        catch (JMSException e)
  +        {
  +            logger.error("Failed to add object to message", e);
  +        }
  +        
  +        return msg;
  +    }
  +
  +
  +    /* (non-Javadoc)
  +     * @see javax.jms.MessageListener#onMessage(javax.jms.Message)
  +     */
  +    public void onMessage(Message message)
  +    {
  +        if(message instanceof ObjectMessage)
  +        {
  +            ObjectMessage objMsg = (ObjectMessage)message;
  +            Object obj = null;
  +            try
  +            {
  +                obj = objMsg.getObject();
  +            }
  +            catch (JMSException e)
  +            {
  +                logger.error("Failed to retrieve object from message.");
  +                return;
  +            }
  +            
  +            if(obj != null)
  +            {
  +                if(obj instanceof ProfileLocator)
  +	            {
  +	                ProfileLocator locator = (ProfileLocator)obj;
  +	                refresh(locator);
  +	            }
  +	            
  +	            if(obj instanceof PsmlMessage)
  +	            {
  +	                PsmlMessage psmlMsg = (PsmlMessage)obj;
  +	                
  +	                String user = psmlMsg.getUser();
  +	                String role = psmlMsg.getRole();
  +	                String group = psmlMsg.getGroup();
  +	                String action = psmlMsg.getAction();
  +	                
  +	                try
  +	                {
  +		                if(user != null)
  +		                {
  +		                    if(PsmlMessage.REMOVE_ACTION.equals(action)) {
  +		                        removeUserDocuments(JetspeedSecurity.getUser(user), false);
  +		                    }
  +		                }
  +		                else if(role != null)
  +		                {
  +		                    if(PsmlMessage.REMOVE_ACTION.equals(action)) {
  +		                        removeRoleDocuments(JetspeedSecurity.getRole(role), false);
  +		                    }
  +		                }
  +		                else if(group != null)
  +		                {
  +		                    if(PsmlMessage.REMOVE_ACTION.equals(action)) {
  +		                        removeGroupDocuments(JetspeedSecurity.getGroup(group), false);
  +		                    }
  +		                }
  +	                }
  +	                catch(JetspeedSecurityException e)
  +	                {
  +	                    logger.error(e);
  +	                }
  +	            }
  +            }
  +        }
  +    }
   }
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jetspeed-dev-help@jakarta.apache.org


Mime
View raw message