[jboss-remoting-commits] JBoss Remoting SVN: r5171 - remoting2/branches/2.2/src/main/org/jboss/remoting.

jboss-remoting-commits at lists.jboss.org jboss-remoting-commits at lists.jboss.org
Sun May 10 01:46:18 EDT 2009


Author: ron.sigal at jboss.com
Date: 2009-05-10 01:46:17 -0400 (Sun, 10 May 2009)
New Revision: 5171

Modified:
   remoting2/branches/2.2/src/main/org/jboss/remoting/MicroRemoteClientInvoker.java
Log:
JBREM-1128: (1) Adopted use of leasePingerId; (2) establishLease() can call Client.addConnectionListener().

Modified: remoting2/branches/2.2/src/main/org/jboss/remoting/MicroRemoteClientInvoker.java
===================================================================
--- remoting2/branches/2.2/src/main/org/jboss/remoting/MicroRemoteClientInvoker.java	2009-05-10 05:40:51 UTC (rev 5170)
+++ remoting2/branches/2.2/src/main/org/jboss/remoting/MicroRemoteClientInvoker.java	2009-05-10 05:46:17 UTC (rev 5171)
@@ -337,14 +337,26 @@
 
    public void terminateLease(String sessionId, int disconnectTimeout)
    {
+      terminateLease(sessionId, disconnectTimeout, null);
+   }
+   
+   public void terminateLease(String sessionId, int disconnectTimeout, LeasePinger passedLeasePinger)
+   {
       synchronized(clientLeaseLock)
       {
+         if (passedLeasePinger != null && passedLeasePinger != leasePinger)
+         {
+            if (trace) log.trace(this + ": " + passedLeasePinger + " != " + leasePinger);
+            return;
+         }
+         if (trace) log.trace(this + " entering terminateLease() for " + leasePinger);
          if(leasePinger != null)
          {
             leasePinger.setDisconnectTimeout(disconnectTimeout);
             
             if (sessionId == null)
             {
+               if (trace) log.trace(this + " shutting down LeasePinger: " + leasePinger);
                // Independent of any particular Client - force LeasePinger shutdown.
                // Should be called only if there is a reasonable belief that the lease
                // has already stopped on the server side.
@@ -354,16 +366,19 @@
                }
                catch (Exception e)
                {
-                  log.debug("error shutting down lease pinger");
+                  log.debug("error shutting down lease pinger" + e.getMessage());
+                  log.trace("error shutting down lease pinger", e);
                }
                leasePinger = null;
             }
             else
             {
                // Remove a particular Client.
+               if (trace) log.trace(this + " removing client " + sessionId + " from LeasePinger: " + leasePinger);
                boolean isLastClientLease = leasePinger.removeClient(sessionId);
                if(isLastClientLease)
                {
+                  if (trace) log.trace(this + " shutting down LeasePinger, " + sessionId + " was last client lease: " + leasePinger);
                   try
                   {
                      leasePinger.stopPing();
@@ -376,6 +391,11 @@
                }
             }
          }
+         else
+         {
+            if (trace) log.trace(this + " leasePinger is null: must have been shut down already");
+         }
+         if (trace) log.trace(this + " leaving terminateLease() for " + leasePinger);
       }
    }
 
@@ -395,6 +415,22 @@
    public void establishLease(String clientSessionID, Map configuration, long leasePeriod)
       throws Throwable
    {
+      Client client = (Client) configuration.get(Client.CLIENT);
+      ConnectionListener listener = (ConnectionListener) configuration.remove(Client.CONNECTION_LISTENER);
+      boolean useClientConnectionIdentity = false;
+      if (configuration != null)
+      {
+         Object o = configuration.get(Remoting.USE_CLIENT_CONNECTION_IDENTITY);
+         if (o instanceof String)
+         {
+            useClientConnectionIdentity = Boolean.valueOf((String) o).booleanValue();
+         }
+         else if (o != null)
+         {
+            log.warn("value of " + Remoting.USE_CLIENT_CONNECTION_IDENTITY + " must be a String: " + o); 
+         }
+      }
+
       synchronized (clientLeaseLock)
       {
          // if already have a lease pinger, then already have a client with an established
@@ -402,55 +438,68 @@
          if (leasePinger != null)
          {
             leasePinger.addClient(clientSessionID, configuration, leasePeriod);
-            log.debug(this + " added client with session ID " + clientSessionID + " to the lease pinger");
-            return;
+            if (trace) log.trace(this + " added client with session ID " + clientSessionID + " to " + leasePinger);
          }
-
-         try
+         else
          {
-            if(trace) { log.trace(this + " sending initial lease ping to server to determine if server has leasing enabled."); }
+            try
+            {
+               if(trace) { log.trace(this + " sending initial lease ping to server to determine if server has leasing enabled."); }
 
-            // configuration should NOT be passed as want ping to be specific to client invoker
-            // and NOT to the client.
+               // configuration should NOT be passed as want ping to be specific to client invoker
+               // and NOT to the client.
 
-            InvocationRequest ir =
-               new InvocationRequest(invokerSessionID, null, "$PING$", null, new HashMap(), null);
+               String leasePingerId = new GUID().toString();
+               Map requestMap = new HashMap();
+               requestMap.put(LeasePinger.LEASE_PINGER_ID, leasePingerId);
+               requestMap.put(LeasePinger.TIME_STAMP, Long.toString(System.currentTimeMillis()));
+               if (trace) log.trace(this + " initiating lease for leasePingerId " + leasePingerId);
+               InvocationRequest ir = new InvocationRequest(invokerSessionID, null, "$PING$", requestMap, new HashMap(), null);
 
-            Object ret = invoke(ir);
+               Object ret = invoke(ir);
 
-            if (ret instanceof InvocationResponse)
-            {
-               InvocationResponse resp = (InvocationResponse) ret;
-               Boolean shouldLease = (Boolean)resp.getResult();
-
-               if (shouldLease.booleanValue())
+               if (ret instanceof InvocationResponse)
                {
-                  long defaultLeasePeriod = LeasePinger.DEFAULT_LEASE_PERIOD;
-                  Map respMap = resp.getPayload();
+                  InvocationResponse resp = (InvocationResponse) ret;
+                  Boolean shouldLease = (Boolean)resp.getResult();
 
-                  if (respMap != null)
+                  if (shouldLease.booleanValue())
                   {
-                     Long leaseTimeoutValue = (Long)respMap.get("clientLeasePeriod");
-                     long serverDefaultLeasePeriod = leaseTimeoutValue.longValue();
-                     if(serverDefaultLeasePeriod > 0)
+                     long defaultLeasePeriod = LeasePinger.DEFAULT_LEASE_PERIOD;
+                     Map respMap = resp.getPayload();
+
+                     if (respMap != null)
                      {
-                        defaultLeasePeriod = serverDefaultLeasePeriod;
+                        Long leaseTimeoutValue = (Long)respMap.get("clientLeasePeriod");
+                        long serverDefaultLeasePeriod = leaseTimeoutValue.longValue();
+                        if(serverDefaultLeasePeriod > 0)
+                        {
+                           defaultLeasePeriod = serverDefaultLeasePeriod;
+                        }
                      }
-                  }
 
-                  if(trace) { log.trace("server does have leasing enabled (with default lease period of " + defaultLeasePeriod + ") and will start a new lease pinger."); }
+                     if(trace) { log.trace("server does have leasing enabled (with default lease period of " + defaultLeasePeriod + ") and will start a new lease pinger."); }
 
-                  leasePinger = new LeasePinger(this, invokerSessionID, defaultLeasePeriod);
-                  leasePinger.addClient(clientSessionID, configuration, leasePeriod);
-                  leasePinger.startPing();
+                     leasePinger = new LeasePinger(this, invokerSessionID, defaultLeasePeriod);
+                     leasePinger.setLeasePingerId(leasePingerId);
+                     leasePinger.setUseClientConnectionIdentity(useClientConnectionIdentity);
+                     leasePinger.addClient(clientSessionID, configuration, leasePeriod);
+                     leasePinger.startPing();
+                  }
                }
             }
+            catch (Throwable throwable)
+            {
+               Exception e = new Exception("Error setting up client lease");
+               e.initCause(throwable);
+               throw e;
+            }
          }
-         catch (Throwable throwable)
+
+         if (trace) log.trace(this + ": client = " + client + ", listener = " + listener);
+         if (client != null && listener != null)
          {
-            Exception e = new Exception("Error setting up client lease");
-            e.initCause(throwable);
-            throw e;
+            client.addConnectionListener(listener, configuration);
          }
       }
    }
@@ -580,4 +629,11 @@
       super.finalize();
    }
 
+   protected LeasePinger getLeasePinger()
+   {
+      synchronized(clientLeaseLock)
+      {
+         return leasePinger;
+      }
+   }
 }




More information about the jboss-remoting-commits mailing list