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/db DatabasePsmlManagerService.java
Date Sat, 28 Aug 2004 19:05:36 GMT
jford       2004/08/28 12:05:36

  Modified:    src/java/org/apache/jetspeed/services/psmlmanager/db
                        DatabasePsmlManagerService.java
  Log:
  Added support for messaging
  
  Revision  Changes    Path
  1.36      +161 -4    jakarta-jetspeed/src/java/org/apache/jetspeed/services/psmlmanager/db/DatabasePsmlManagerService.java
  
  Index: DatabasePsmlManagerService.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/services/psmlmanager/db/DatabasePsmlManagerService.java,v
  retrieving revision 1.35
  retrieving revision 1.36
  diff -u -r1.35 -r1.36
  --- DatabasePsmlManagerService.java	23 Feb 2004 03:32:19 -0000	1.35
  +++ DatabasePsmlManagerService.java	28 Aug 2004 19:05:36 -0000	1.36
  @@ -20,10 +20,12 @@
   
   // PSML Manager Service interface
   import org.apache.jetspeed.services.psmlmanager.PsmlManagerService;
  +import org.apache.jetspeed.services.psmlmanager.PsmlMessage;
   
   
   // Jetspeed Security service
   import org.apache.jetspeed.services.JetspeedSecurity;
  +import org.apache.jetspeed.services.Messenger;
   
   // Profile and ProfileLocator interface
   import org.apache.jetspeed.om.profile.Profile;
  @@ -32,6 +34,7 @@
   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;
   
   //Castor defined API
   import org.apache.jetspeed.om.profile.Portlets;
  @@ -59,6 +62,10 @@
   import org.apache.jetspeed.services.security.JetspeedSecurityException;
   
   //Servlet API
  +import javax.jms.JMSException;
  +import javax.jms.Message;
  +import javax.jms.MessageListener;
  +import javax.jms.ObjectMessage;
   import javax.servlet.ServletConfig;
   
   // Torque generated classes
  @@ -79,6 +86,7 @@
   import java.util.HashMap;
   import java.io.FileReader;
   import java.io.File;
  +import java.io.Serializable;
   
   import org.exolab.castor.mapping.Mapping;
   import org.xml.sax.InputSource;
  @@ -94,7 +102,8 @@
    * @version $Id$
    */
   public class DatabasePsmlManagerService extends TurbineBaseService
  -                                     implements DatabasePsmlManager
  +                                     implements DatabasePsmlManager,
  +                                     MessageListener
   {
       /**
        * Static initialization of the logger for this class
  @@ -131,6 +140,8 @@
   
       /** The pool name to use for database requests. */
       private String poolName = null;
  +    
  +    private boolean enableMessaging = false;
   
       /**
        * This is the early initialization method called by the
  @@ -163,6 +174,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, DatabasePsmlManagerService.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.");
  +            }
  +        }
   
           ResourceService serviceConf =
                         ((TurbineServices)TurbineServices.getInstance())
  @@ -638,6 +664,12 @@
                       psmlCache.put(locatorToString(profile), profile.getDocument());
                   }
               }
  +            
  +            if(enableMessaging)
  +            {
  +                Message msg = createMessage(profile);
  +                Messenger.sendMessage(msg, MessagingService.PSML_UPDATE_SUBJECT);
  +            }
   
               return profile.getDocument();
           }
  @@ -703,6 +735,12 @@
                       psmlCache.remove(locatorToString(locator));
                   }
               }
  +            
  +            if(enableMessaging)
  +            {
  +                Message msg = createMessage(locator);
  +                Messenger.sendMessage(msg, MessagingService.PSML_UPDATE_SUBJECT);
  +            }
           }
           catch (Exception e) // insert failed
           {
  @@ -1019,6 +1057,23 @@
               if (user != null)
               {
                   new JetspeedUserProfilePeer().delete(user, dbCon);
  +                
  +                if (cachingOn)
  +                {
  +                    synchronized (psmlCache)
  +                    {
  +                        psmlCache.clear();
  +                    }
  +                }
  +                
  +                if(enableMessaging)
  +                {
  +                    PsmlMessage psmlMessage = new PsmlMessage();
  +                    psmlMessage.setUser(user.getUserName());
  +                    psmlMessage.setAction(PsmlMessage.REMOVE_ACTION);
  +                    Message message = createMessage(psmlMessage);
  +                    Messenger.sendMessage(message, MessagingService.PSML_UPDATE_SUBJECT);
  +                }
               }
           }
           catch (Exception e) // delete failed
  @@ -1031,7 +1086,6 @@
               // make sure to release the database connection
               releaseDbConnection(dbCon);
           }
  -
       }
   
       /** Removes all documents for a given role.
  @@ -1047,6 +1101,23 @@
               if (role != null)
               {
                   new JetspeedRoleProfilePeer().delete(role, dbCon);
  +                
  +                if (cachingOn)
  +                {
  +                    synchronized (psmlCache)
  +                    {
  +                        psmlCache.clear();
  +                    }
  +                }
  +                
  +                if(enableMessaging)
  +                {
  +                    PsmlMessage psmlMessage = new PsmlMessage();
  +                    psmlMessage.setRole(role.getName());
  +                    psmlMessage.setAction(PsmlMessage.REMOVE_ACTION);
  +                    Message message = createMessage(psmlMessage);
  +                    Messenger.sendMessage(message, MessagingService.PSML_UPDATE_SUBJECT);
  +                }
               }
           }
           catch (Exception e) // delete failed
  @@ -1074,6 +1145,23 @@
               if (group != null)
               {
                   new JetspeedGroupProfilePeer().delete(group, dbCon);
  +                
  +                if (cachingOn)
  +                {
  +                    synchronized (psmlCache)
  +                    {
  +                        psmlCache.clear();
  +                    }
  +                }
  +                
  +                if(enableMessaging)
  +                {
  +                    PsmlMessage psmlMessage = new PsmlMessage();
  +                    psmlMessage.setGroup(group.getName());
  +                    psmlMessage.setAction(PsmlMessage.REMOVE_ACTION);
  +                    Message message = createMessage(psmlMessage);
  +                    Messenger.sendMessage(message, MessagingService.PSML_UPDATE_SUBJECT);
  +                }
               }
           }
           catch (Exception e) // delete failed
  @@ -1272,5 +1360,74 @@
       {
           Torque.closeConnection(connection);
       }
  -}
  +    
  +    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();
  +
  +	                if(user != null || role != null || group != null)
  +	                {
  +	                    if(PsmlMessage.REMOVE_ACTION.equals(action))
  +	                    {
  +	                        if (cachingOn)
  +	                        {
  +	                            synchronized (psmlCache)
  +	                            {
  +	                                psmlCache.clear();
  +	                            }
  +	                        }
  +	                    }
  +	                }
  +	            }
  +            }
  +        }
  +    }
  +}
  
  
  

---------------------------------------------------------------------
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