[jboss-cvs] JBossAS SVN: r74737 - trunk/cluster/src/main/org/jboss/ha/hasessionstate/server.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Jun 17 17:44:58 EDT 2008


Author: pferraro
Date: 2008-06-17 17:44:58 -0400 (Tue, 17 Jun 2008)
New Revision: 74737

Modified:
   trunk/cluster/src/main/org/jboss/ha/hasessionstate/server/HASessionStateImpl.java
Log:
Cosmetic code cleanup.
Added generics for session and lock maps.

Modified: trunk/cluster/src/main/org/jboss/ha/hasessionstate/server/HASessionStateImpl.java
===================================================================
--- trunk/cluster/src/main/org/jboss/ha/hasessionstate/server/HASessionStateImpl.java	2008-06-17 21:36:48 UTC (rev 74736)
+++ trunk/cluster/src/main/org/jboss/ha/hasessionstate/server/HASessionStateImpl.java	2008-06-17 21:44:58 UTC (rev 74737)
@@ -32,6 +32,7 @@
 import java.util.HashMap;
 import java.util.Hashtable;
 import java.util.Iterator;
+import java.util.Map;
 import java.util.Vector;
 import java.util.zip.Deflater;
 import java.util.zip.DeflaterOutputStream;
@@ -41,10 +42,12 @@
 import javax.naming.InitialContext;
 import javax.naming.Name;
 import javax.naming.NameNotFoundException;
+import javax.naming.NamingException;
 import javax.naming.Reference;
 import javax.naming.StringRefAddr;
 
 import org.jboss.ha.framework.interfaces.HAPartition;
+import org.jboss.ha.hasessionstate.interfaces.HASessionState;
 import org.jboss.ha.hasessionstate.interfaces.PackagedSession;
 import org.jboss.logging.Logger;
 import org.jboss.naming.NonSerializableFactory;
@@ -68,30 +71,26 @@
  */
 
 public class HASessionStateImpl
-   implements org.jboss.ha.hasessionstate.interfaces.HASessionState,
-	      HAPartition.HAPartitionStateTransfer
+   implements HASessionState, HAPartition.HAPartitionStateTransfer
 {
+   private String _sessionStateName;
+   private Logger log;
+   private HAPartition hapGeneral;
+   private String sessionStateIdentifier;
+   private String myNodeName;
    
-   protected String _sessionStateName;
-   protected Logger log;
-   protected HAPartition hapGeneral;
-   protected String sessionStateIdentifier;
-   protected String myNodeName;
+   long beanCleaningDelay;
    
-   protected long beanCleaningDelay;
-   protected String haPartitionName;
+   private static final long MAX_DELAY_BEFORE_CLEANING_UNRECLAIMED_STATE = 30L * 60L * 1000L; // 30 minutes... should be set externally or use cache settings
+   private static final String HA_SESSION_STATE_STATE_TRANSFER = "HASessionStateTransfer";
    
-   protected final long MAX_DELAY_BEFORE_CLEANING_UNRECLAIMED_STATE = 30L * 60L * 1000L; // 30 minutes... should be set externally or use cache settings
-   protected static final String HA_SESSION_STATE_STATE_TRANSFER = "HASessionStateTransfer";
+   private static final Class<?>[] SET_OWNERSHIP_TYPES = new Class[] { String.class, Object.class, String.class, Long.class };
+   private static final Class<?>[] REMOVE_SESSION_TYPES = new Class[]{ String.class, Object.class };
+   private static final Class<?>[] SET_STATE_TYPES = new Class[] { String.class, PackagedSession.class };
    
-   protected HashMap locks = new HashMap ();
-      
-   private HASessionStateImpl ()
-   {}
+   private Map<String, Map<Object, Mutex>> locks = new HashMap<String, Map<Object, Mutex>>();
    
-   public HASessionStateImpl (String sessionStateName,
-                              HAPartition partition,
-                              long beanCleaningDelay)
+   public HASessionStateImpl(String sessionStateName, HAPartition partition, long beanCleaningDelay)
    {
       if (partition == null)
       {
@@ -101,81 +100,89 @@
       this.hapGeneral = partition;
       
       if (sessionStateName == null)
+      {
          this._sessionStateName = org.jboss.metadata.ClusterConfigMetaData.DEFAULT_SESSION_STATE_NAME;
+      }
       else
+      {
          this._sessionStateName = sessionStateName;
+      }
       
       this.sessionStateIdentifier = "SessionState-'" + this._sessionStateName + "'";
       
-      haPartitionName = partition.getPartitionName();      
-      
       if (beanCleaningDelay > 0)
+      {
          this.beanCleaningDelay = beanCleaningDelay;
+      }
       else
+      {
          this.beanCleaningDelay = MAX_DELAY_BEFORE_CLEANING_UNRECLAIMED_STATE;
+      }
    }
    
-   public void init () throws Exception
+   public void init() throws Exception
    {
       this.log = Logger.getLogger(HASessionStateImpl.class.getName() + "." + this._sessionStateName);
       
-      this.hapGeneral.registerRPCHandler (this.sessionStateIdentifier, this);
-      this.hapGeneral.subscribeToStateTransferEvents (HA_SESSION_STATE_STATE_TRANSFER, this);
+      this.hapGeneral.registerRPCHandler(this.sessionStateIdentifier, this);
+      this.hapGeneral.subscribeToStateTransferEvents(HA_SESSION_STATE_STATE_TRANSFER, this);
    }
    
-   public void start () throws Exception
+   public void start() throws Exception
    {
-      this.myNodeName = this.hapGeneral.getNodeName ();
-      log.debug ("HASessionState node name : " + this.myNodeName );
+      this.myNodeName = this.hapGeneral.getNodeName();
+      this.log.debug("HASessionState node name : " + this.myNodeName );
       
-      // BES 4/7/06 clean up lifecycle; move this to start, as it can't be 
+      // BES 4/7/06 clean up lifecycle; move this to start, as it can't be
       // called until startService due to JNDI dependency
-      Context ctx = new InitialContext ();
-      this.bind (this._sessionStateName, this, HASessionStateImpl.class, ctx);
+      Context ctx = new InitialContext();
+      this.bind(this._sessionStateName, this, HASessionStateImpl.class, ctx);
    }
    
-   protected void bind (String jndiName, Object who, Class classType, Context ctx) throws Exception
+   protected void bind(String jndiName, Object who, Class<?> classType, Context ctx) throws Exception
    {
       // Ah ! This service isn't serializable, so we use a helper class
       //
-      NonSerializableFactory.bind (jndiName, who);
-      Name n = ctx.getNameParser ("").parse (jndiName);
-      while (n.size () > 1)
+      org.jboss.util.naming.NonSerializableFactory.bind(jndiName, who);
+      Name n = ctx.getNameParser("").parse(jndiName);
+      while (n.size() > 1)
       {
-         String ctxName = n.get (0);
+         String ctxName = n.get(0);
          try
          {
-            ctx = (Context)ctx.lookup (ctxName);
+            ctx = (Context) ctx.lookup(ctxName);
          }
          catch (NameNotFoundException e)
          {
-            log.debug ("creating Subcontext " + ctxName);
-            ctx = ctx.createSubcontext (ctxName);
+            this.log.debug("creating Subcontext " + ctxName);
+            ctx = ctx.createSubcontext(ctxName);
          }
-         n = n.getSuffix (1);
+         n = n.getSuffix(1);
       }
       
       // The helper class NonSerializableFactory uses address type nns, we go on to
       // use the helper class to bind the service object in JNDI
       //
-      StringRefAddr addr = new StringRefAddr ("nns", jndiName);
-      Reference ref = new Reference ( classType.getName (), addr, NonSerializableFactory.class.getName (), null);
-      ctx.bind (n.get (0), ref);
+      StringRefAddr addr = new StringRefAddr("nns", jndiName);
+      Reference ref = new Reference(classType.getName(), addr, NonSerializableFactory.class.getName(), null);
+      ctx.bind(n.get(0), ref);
    }
    
-   public void stop () throws Exception
+   public void stop()
    {
-       purgeState();
-       
-       // Unbind so we can rebind if restarted
-       try
-       {
-          Context ctx = new InitialContext ();         
-          ctx.unbind (this._sessionStateName);
-          NonSerializableFactory.unbind (this._sessionStateName);
-       }
-       catch (Exception ignored)
-       {}
+      this.purgeState();
+      
+      // Unbind so we can rebind if restarted
+      try
+      {
+         Context ctx = new InitialContext();
+         ctx.unbind(this._sessionStateName);
+         org.jboss.util.naming.NonSerializableFactory.unbind(this._sessionStateName);
+      }
+      catch (NamingException e)
+      {
+         // Ignore
+      }
    }
    
    public void destroy() throws Exception
@@ -185,333 +192,370 @@
       this.hapGeneral.unsubscribeFromStateTransferEvents(HA_SESSION_STATE_STATE_TRANSFER, this);
    }
    
-   public String getNodeName ()
+   public String getNodeName()
    {
-      return this.myNodeName ;
+      return this.myNodeName;
    }
    
    // Used for Session state transfer
    //
-   public Serializable getCurrentState ()
+   public Serializable getCurrentState()
    {
-      log.debug ("Building and returning state of HASessionState");
+      this.log.debug ("Building and returning state of HASessionState");
       
       if (this.appSessions == null)
-         this.appSessions = new Hashtable ();
+      {
+         this.appSessions = new Hashtable<String, Hashtable<Object, PackagedSession>>();
+      }
       
       Serializable result = null;
       
       synchronized (this.lockAppSession)
       {
-         this.purgeState ();
+         this.purgeState();
          
          try
          {
-            result = deflate (this.appSessions);
+            result = this.deflate(this.appSessions);
          }
          catch (Exception e)
          {
-            log.error("operation failed", e);
+            this.log.error("operation failed", e);
          }
       }
       return result;
    }
    
-   public void setCurrentState (Serializable newState)
+   @SuppressWarnings("unchecked")
+   public void setCurrentState(Serializable newState)
    {
-      log.debug ("Receiving state of HASessionState");
+      this.log.debug("Receiving state of HASessionState");
       
       if (this.appSessions == null)
-         this.appSessions = new Hashtable ();
+      {
+         this.appSessions = new Hashtable<String, Hashtable<Object, PackagedSession>>();
+      }
       
       synchronized (this.lockAppSession)
       {
          try
          {
-            this.appSessions.clear (); // hope to facilitate the job of the GC
-            this.appSessions = (Hashtable)inflate ((byte[])newState);
+            this.appSessions.clear(); // hope to facilitate the job of the GC
+            this.appSessions = (Hashtable<String, Hashtable<Object, PackagedSession>>) this.inflate((byte[]) newState);
          }
          catch (Exception e)
          {
-            log.error("operation failed", e);
-         }         
+            this.log.error("operation failed", e);
+         }
       }
    }
    
-   public void purgeState ()
+   public void purgeState()
    {
       synchronized (this.lockAppSession)
       {
-         for (Enumeration keyEnum = this.appSessions.keys (); keyEnum.hasMoreElements ();)
+         for (Enumeration<String> keyEnum = this.appSessions.keys(); keyEnum.hasMoreElements();)
          {
             // trip in apps..
             //
-            Object key = keyEnum.nextElement ();
-            Hashtable value = (Hashtable)this.appSessions.get (key);
-            long currentTime = System.currentTimeMillis ();
+            String key = keyEnum.nextElement();
+            Hashtable<Object, PackagedSession> value = this.appSessions.get(key);
+            long currentTime = System.currentTimeMillis();
             
-            for (Iterator iterSessions = value.values ().iterator (); iterSessions.hasNext ();)
+            for (Iterator<PackagedSession> iterSessions = value.values().iterator(); iterSessions.hasNext();)
             {
-               PackagedSession ps = (PackagedSession)iterSessions.next ();
-               if ( (currentTime - ps.unmodifiedExistenceInVM ()) > beanCleaningDelay )
-                  iterSessions.remove ();
+               PackagedSession ps = iterSessions.next();
+               if ((currentTime - ps.unmodifiedExistenceInVM()) > this.beanCleaningDelay)
+               {
+                  iterSessions.remove();
+               }
             }
          }
       }
-      
    }
    
-   protected byte[] deflate (Object object) throws IOException
+   protected byte[] deflate(Object object) throws IOException
    {
-      ByteArrayOutputStream baos = new ByteArrayOutputStream ();
-      Deflater def = new Deflater (java.util.zip.Deflater.BEST_COMPRESSION);
-      DeflaterOutputStream dos = new DeflaterOutputStream (baos, def);
+      ByteArrayOutputStream baos = new ByteArrayOutputStream();
+      Deflater def = new Deflater(java.util.zip.Deflater.BEST_COMPRESSION);
+      DeflaterOutputStream dos = new DeflaterOutputStream(baos, def);
       
-      ObjectOutputStream out = new ObjectOutputStream (dos);
-      out.writeObject (object);
-      out.close ();
-      dos.finish ();
-      dos.close ();
+      ObjectOutputStream out = new ObjectOutputStream(dos);
+      out.writeObject(object);
+      out.close();
+      dos.finish();
+      dos.close();
       
-      return baos.toByteArray ();
+      return baos.toByteArray();
    }
    
-   protected Object inflate (byte[] compressedContent) throws IOException
+   protected Object inflate(byte[] compressedContent) throws IOException
    {
-      if (compressedContent==null)
-         return null;
+      if (compressedContent == null) return null;
       
       try
       {
-         ObjectInputStream in = new ObjectInputStream (new InflaterInputStream (new ByteArrayInputStream (compressedContent)));
+         ObjectInputStream in = new ObjectInputStream(new InflaterInputStream(new ByteArrayInputStream(compressedContent)));
          
-         Object object = in.readObject ();
-         in.close ();
+         Object object = in.readObject();
+         in.close();
          return object;
       }
       catch (Exception e)
       {
-         throw new IOException (e.toString ());
+         throw new IOException(e.toString());
       }
    }
    
-   protected Hashtable appSessions = new Hashtable ();
-   protected Object lockAppSession = new Object ();
+   protected Hashtable<String, Hashtable<Object, PackagedSession>> appSessions = new Hashtable<String, Hashtable<Object, PackagedSession>>();
+   protected Object lockAppSession = new Object();
    
-   protected Hashtable getHashtableForApp (String appName)
+   protected Hashtable<Object, PackagedSession> getHashtableForApp(String appName)
    {
       if (this.appSessions == null)
-         this.appSessions = new Hashtable (); // should never happen though...
+      {
+         this.appSessions = new Hashtable<String, Hashtable<Object, PackagedSession>>(); // should never happen though...
+      }
       
-      Hashtable result = null;
+      Hashtable<Object, PackagedSession> result = null;
       
       synchronized (this.lockAppSession)
       {
-         result = (Hashtable)this.appSessions.get (appName);
+         result = this.appSessions.get(appName);
          if (result == null)
          {
-            result = new Hashtable ();
-            this.appSessions.put (appName, result);
+            result = new Hashtable<Object, PackagedSession>();
+            this.appSessions.put(appName, result);
          }
       }
       return result;
    }
    
-   public void createSession (String appName, Object keyId)
+   public void createSession(String appName, Object keyId)
    {
-      this._createSession (appName, keyId);
+      this._createSession(appName, keyId);
    }
    
-   public PackagedSessionImpl _createSession (String appName, Object keyId)
+   public PackagedSessionImpl _createSession(String appName, Object keyId)
    {
-      Hashtable app = this.getHashtableForApp (appName);
-      PackagedSessionImpl result = new PackagedSessionImpl ((Serializable)keyId, null, this.myNodeName);
-      app.put (keyId, result);
+      Hashtable<Object, PackagedSession> app = this.getHashtableForApp(appName);
+      PackagedSessionImpl result = new PackagedSessionImpl((Serializable) keyId, null, this.myNodeName);
+      app.put(keyId, result);
       return result;
    }
    
-   public void setState (String appName, Object keyId, byte[] state)
+   public void setState(String appName, Object keyId, byte[] state)
       throws java.rmi.RemoteException
    {
-      Hashtable app = this.getHashtableForApp (appName);
-      PackagedSession ps = (PackagedSession)app.get (keyId);
+      Hashtable<Object, PackagedSession> app = this.getHashtableForApp(appName);
+      PackagedSession ps = app.get(keyId);
       
       if (ps == null)
       {
-         ps = _createSession (appName, keyId);
+         ps = this._createSession(appName, keyId);
       }
             
       boolean isStateIdentical = false;
       
-      Mutex mtx = getLock (appName, keyId);
-      try { 
-         if (!mtx.attempt (0))
+      Mutex mtx = this.getLock(appName, keyId);
+      try
+      {
+         if (!mtx.attempt(0))
+         {
             throw new java.rmi.RemoteException ("Concurent calls on session object.");
-      } 
-      catch (InterruptedException ie) { log.info (ie); return; }
+         }
+      }
+      catch (InterruptedException ie)
+      {
+         this.log.info(ie);
+         return;
+      }
       
       try
       {
          isStateIdentical = ps.setState(state);
          if (!isStateIdentical)
          {
-            Object[] args =
-               {appName, ps};
+            Object[] args = { appName, ps };
+            
             try
             {
-               this.hapGeneral.callMethodOnCluster (this.sessionStateIdentifier,
-                                                    "_setState",
-                                                    args,
-                                                    new Class[]{String.class, PackagedSession.class}, true);
+               this.hapGeneral.callMethodOnCluster(this.sessionStateIdentifier,
+                                                   "_setState",
+                                                   args,
+                                                   SET_STATE_TYPES,
+                                                   true);
             }
             catch (Exception e)
             {
-               log.error("operation failed", e);
+               this.log.error("operation failed", e);
             }
          }
       }
       finally
       {
-         mtx.release ();
+         mtx.release();
       }
    }
    
    /*
-   public void _setStates (String appName, Hashtable packagedSessions)
+   public void _setStates(String appName, Hashtable packagedSessions)
    {
       synchronized (this.lockAppSession)
       {
-         Hashtable app = this.getHashtableForApp (appName);
+         Hashtable<Object, PackagedSession> app = this.getHashtableForApp(appName);
          
          if (app == null)
          {
-            app = new Hashtable (packagedSessions.size ());
-            this.appSessions.put (appName, app);
+            app = new Hashtable<Object, PackagedSession>(packagedSessions.size());
+            this.appSessions.put(appName, app);
          }
-         app.putAll (packagedSessions);
+         app.putAll(packagedSessions);
       }
    }*/
    
-   public void _setState (String appName, PackagedSession session)
+   public void _setState(String appName, PackagedSession session)
    {
-      Hashtable app = this.getHashtableForApp (appName);
-      PackagedSession ps = (PackagedSession)app.get (session.getKey ());
+      Hashtable<Object, PackagedSession> app = this.getHashtableForApp(appName);
+      PackagedSession ps = app.get(session.getKey());
       
       if (ps == null)
       {
          ps = session;
          synchronized (app)
          {
-            app.put (ps.getKey (), ps);
+            app.put(ps.getKey(), ps);
          }
       }
       else
       {
-         Mutex mtx = getLock (appName, session.getKey ());
-         try { mtx.acquire (); } catch (InterruptedException ie) { log.info (ie); return; }
+         Mutex mtx = this.getLock(appName, session.getKey());
          
          try
          {
-            if (ps.getOwner ().equals (this.myNodeName))
+            mtx.acquire();
+         }
+         catch (InterruptedException ie)
+         {
+            this.log.info(ie);
+            return;
+         }
+         
+         try
+         {
+            if (ps.getOwner().equals(this.myNodeName))
             {
                // a modification has occured externally while we were the owner
                //
-               ownedObjectExternallyModified (appName, session.getKey (), ps, session);
+               this.ownedObjectExternallyModified(appName, session.getKey(), ps, session);
             }
-            ps.update (session);
+            ps.update(session);
          }
          finally
          {
-            mtx.release ();
+            mtx.release();
          }
       }
-      
    }
    
-   public PackagedSession getState (String appName, Object keyId)
+   public PackagedSession getState(String appName, Object keyId)
    {
-      Hashtable app = this.getHashtableForApp (appName);
-      return (PackagedSession)app.get (keyId);
+      Hashtable<Object, PackagedSession> app = this.getHashtableForApp(appName);
+      return app.get(keyId);
    }
    
-   public PackagedSession getStateWithOwnership (String appName, Object keyId) throws java.rmi.RemoteException
+   public PackagedSession getStateWithOwnership(String appName, Object keyId) throws java.rmi.RemoteException
    {
-      return this.localTakeOwnership (appName, keyId);
+      return this.localTakeOwnership(appName, keyId);
    }
    
-   public PackagedSession localTakeOwnership (String appName, Object keyId) throws java.rmi.RemoteException
+   public PackagedSession localTakeOwnership(String appName, Object keyId) throws java.rmi.RemoteException
    {
-      Hashtable app = this.getHashtableForApp (appName);
-      PackagedSession ps = (PackagedSession)app.get (keyId);
+      Hashtable<Object, PackagedSession> app = this.getHashtableForApp(appName);
+      PackagedSession ps = app.get(keyId);
       
       // if the session is not yet available, we simply return null. The persistence manager
       // will have to take an action accordingly
       //
       if (ps == null)
+      {
          return null;
+      }
       
-      Mutex mtx = getLock (appName, keyId);
+      Mutex mtx = this.getLock (appName, keyId);
       
-      try { 
-         if (!mtx.attempt (0))
-            throw new java.rmi.RemoteException ("Concurent calls on session object.");
-      } 
-      catch (InterruptedException ie) { log.info (ie); return null; }
+      try
+      {
+         if (!mtx.attempt(0))
+         {
+            throw new java.rmi.RemoteException("Concurent calls on session object.");
+         }
+      }
+      catch (InterruptedException ie)
+      {
+         this.log.info(ie);
+         return null;
+      }
       
       try
       {
-         if (!ps.getOwner ().equals (this.myNodeName))
+         if (!ps.getOwner().equals(this.myNodeName))
          {
-            Object[] args =
-            {appName, keyId, this.myNodeName, new Long (ps.getVersion ())};
-            ArrayList answers = null;
+            Object[] args = { appName, keyId, this.myNodeName, new Long(ps.getVersion()) };
+            ArrayList<?> answers = null;
             try
             {
-               answers = this.hapGeneral.callMethodOnCluster (this.sessionStateIdentifier,
-                                                              "_setOwnership",
-                                                              args,
-                                                              new Class[]{String.class, Object.class,
-                                                                          String.class, Long.class},
-                                                              true);
+               answers = this.hapGeneral.callMethodOnCluster(this.sessionStateIdentifier,
+                                                             "_setOwnership",
+                                                             args,
+                                                             SET_OWNERSHIP_TYPES,
+                                                             true);
             }
             catch (Exception e)
             {
-               log.error("operation failed", e);
+               this.log.error("operation failed", e);
             }
             
-            if (answers != null && answers.contains (Boolean.FALSE))
-               throw new java.rmi.RemoteException ("Concurent calls on session object.");
-            else
+            if ((answers != null) && answers.contains(Boolean.FALSE))
             {
-               ps.setOwner (this.myNodeName);
-               return ps;
+               throw new java.rmi.RemoteException("Concurent calls on session object.");
             }
+
+            ps.setOwner(this.myNodeName);
+            return ps;
          }
-         else
-            return ps;
+
+         return ps;
       }
       finally
       {
-         mtx.release ();
+         mtx.release();
       }
    }
    
-   public Boolean _setOwnership (String appName, Object keyId, String newOwner, Long remoteVersion)
+   public Boolean _setOwnership(String appName, Object keyId, String newOwner, Long remoteVersion)
    {
-      Hashtable app = this.getHashtableForApp (appName);
-      PackagedSession ps = (PackagedSession)app.get (keyId);
+      Hashtable<Object, PackagedSession> app = this.getHashtableForApp(appName);
+      PackagedSession ps = app.get(keyId);
       Boolean answer = Boolean.TRUE;
-      Mutex mtx = getLock (appName, keyId);
+      Mutex mtx = this.getLock(appName, keyId);
       
-      try { 
-         if (!mtx.attempt (0))
+      try
+      {
+         if (!mtx.attempt(0))
+         {
             return Boolean.FALSE;
-      } 
-      catch (InterruptedException ie) { log.info (ie); return Boolean.FALSE; }
+         }
+      }
+      catch (InterruptedException ie)
+      {
+         this.log.info(ie);
+         return Boolean.FALSE;
+      }
 
       try
       {
-         if (!ps.getOwner ().equals (this.myNodeName))
+         if (!ps.getOwner().equals(this.myNodeName))
          {
             // this is not our business... we don't care
             // we do not update the owner of ps as another host may refuse the _setOwnership call
@@ -520,7 +564,7 @@
             //ps.setOwner (newOwner);
             answer = Boolean.TRUE;
          }
-         else if (ps.getVersion () > remoteVersion.longValue ())
+         else if (ps.getVersion() > remoteVersion.longValue())
          {
             // we are concerned and our version is more recent than the one of the remote host!
             // it means that we have concurrent calls on the same state that has not yet been updated
@@ -533,147 +577,157 @@
             // the remote host has the same version as us (or more recent? possible?)
             // we need to update the ownership. We can do this because we know that no other
             // node can refuse the _setOwnership call
-            ps.setOwner (newOwner);
-            ownedObjectExternallyModified (appName, keyId, ps, ps);
+            ps.setOwner(newOwner);
+            this.ownedObjectExternallyModified(appName, keyId, ps, ps);
             answer = Boolean.TRUE;
          }
       }
       finally
       {
-         mtx.release ();
+         mtx.release();
       }
       return answer;
    }
    
-   public void takeOwnership (String appName, Object keyId) throws java.rmi.RemoteException
+   public void takeOwnership(String appName, Object keyId) throws java.rmi.RemoteException
    {
-      this.localTakeOwnership (appName, keyId);
+      this.localTakeOwnership(appName, keyId);
    }
    
-   public void removeSession (String appName, Object keyId)
+   public void removeSession(String appName, Object keyId)
    {
-      Hashtable app = this.getHashtableForApp (appName);
+      Hashtable<Object, PackagedSession> app = this.getHashtableForApp(appName);
       if (app != null)
       {
-         PackagedSession ps = (PackagedSession)app.remove (keyId);
+         PackagedSession ps = app.remove(keyId);
          if (ps != null)
          {
-            removeLock (appName, keyId);
-            Object[] args =
-               { appName, keyId };
+            this.removeLock(appName, keyId);
+            Object[] args = { appName, keyId };
             try
             {
                this.hapGeneral.callMethodOnCluster (this.sessionStateIdentifier,
                                                     "_removeSession",
                                                     args,
-                                                    new Class[]{String.class, Object.class},
+                                                    REMOVE_SESSION_TYPES,
                                                     true);
             }
             catch (Exception e)
-            { log.error("operation failed", e); }
+            {
+               this.log.error("operation failed", e);
+            }
          }
       }
    }
    
-   public void _removeSession (String appName, Object keyId)
+   public void _removeSession(String appName, Object keyId)
    {
-      Hashtable app = this.getHashtableForApp (appName);
-      PackagedSession ps = null;
-      ps = (PackagedSession)app.remove (keyId);
-      if (ps != null && ps.getOwner ().equals (this.myNodeName))
-         ownedObjectExternallyModified (appName, keyId, ps, ps);
+      Hashtable<Object, PackagedSession> app = this.getHashtableForApp(appName);
+      PackagedSession ps = app.remove(keyId);
+      if (ps != null && ps.getOwner().equals(this.myNodeName))
+      {
+         this.ownedObjectExternallyModified(appName, keyId, ps, ps);
+      }
       
-      removeLock (appName, keyId);
+      this.removeLock(appName, keyId);
    }
    
-   protected Hashtable listeners = new Hashtable ();
+   protected Hashtable<String, Vector<HASessionStateListener>> listeners = new Hashtable<String, Vector<HASessionStateListener>>();
    
-   public synchronized void subscribe (String appName, HASessionStateListener listener)
+   public synchronized void subscribe(String appName, HASessionStateListener listener)
    {
-      Vector members = (Vector)listeners.get (appName);
+      Vector<HASessionStateListener> members = this.listeners.get(appName);
       if (members == null)
       {
-         members = new Vector ();
-         listeners.put (appName, members);
+         members = new Vector<HASessionStateListener>();
+         this.listeners.put(appName, members);
       }
-      if (!members.contains (listener))
+      if (!members.contains(listener))
       {
-         members.add (listener);
+         members.add(listener);
       }
-
    }
    
-   public synchronized void unsubscribe (String appName, HASessionStateListener listener)
+   public synchronized void unsubscribe(String appName, HASessionStateListener listener)
    {
-      Vector members = (Vector)listeners.get (appName);
-      if ((members != null) && members.contains (listener))
-         members.remove (listener);
+      Vector<HASessionStateListener> members = this.listeners.get(appName);
+      if ((members != null) && members.contains(listener))
+      {
+         members.remove(listener);
+      }
    }
    
-   public void ownedObjectExternallyModified (String appName, Object key, PackagedSession oldSession, PackagedSession newSession)
+   public void ownedObjectExternallyModified(String appName, Object key, PackagedSession oldSession, PackagedSession newSession)
    {
-      Vector members = (Vector)listeners.get (appName);
+      Vector<HASessionStateListener> members = this.listeners.get(appName);
       if (members != null)
-         for (int i=0; i<members.size (); i++)
-         try
+      {
+         for (int i = 0; i < members.size(); i++)
          {
-            ((HASessionStateListener)members.elementAt (i)).sessionExternallyModified (newSession);
+            try
+            {
+               members.elementAt(i).sessionExternallyModified(newSession);
+            }
+            catch (Throwable t)
+            {
+               this.log.debug(t);
+            }
          }
-         catch (Throwable t)
-         {
-            log.debug (t);
-         }
+      }
    }
    
-   public HAPartition getCurrentHAPartition ()
+   public HAPartition getCurrentHAPartition()
    {
       return this.hapGeneral;
    }
    
    
-   protected boolean lockExists (String appName, Object key)
+   protected boolean lockExists(String appName, Object key)
    {
       synchronized (this.locks)
       {
-         HashMap ls = (HashMap)this.locks.get (appName);
+         Map<Object, Mutex> ls = this.locks.get(appName);
          if (ls == null)
+         {
             return false;
+         }
          
-         return (ls.get(key)!=null);
+         return (ls.get(key) != null);
       }
    }
 
-   protected Mutex getLock (String appName, Object key)
+   protected Mutex getLock(String appName, Object key)
    {
       synchronized (this.locks)
       {
-         HashMap ls = (HashMap)this.locks.get (appName);
+         Map<Object, Mutex> ls = this.locks.get(appName);
          if (ls == null)
          {
-            ls = new HashMap ();
-            this.locks.put (appName, ls);
+            ls = new HashMap<Object, Mutex>();
+            this.locks.put(appName, ls);
          }
           
-         Mutex mutex = (Mutex)ls.get(key);
+         Mutex mutex = ls.get(key);
          if (mutex == null)
          {
-            mutex = new Mutex ();
-            ls.put (key, mutex);
+            mutex = new Mutex();
+            ls.put(key, mutex);
          }
          
-         return mutex;         
+         return mutex;
       }
    }
 
-   protected void removeLock (String appName, Object key)
+   protected void removeLock(String appName, Object key)
    {
       synchronized (this.locks)
       {
-         HashMap ls = (HashMap)this.locks.get (appName);
+         Map<Object, Mutex> ls = this.locks.get(appName);
          if (ls == null)
+         {
             return;
-         ls.remove (key);
+         }
+         ls.remove(key);
       }
-   }
-   
+   }   
 }




More information about the jboss-cvs-commits mailing list