[jboss-remoting-commits] JBoss Remoting SVN: r5221 - remoting2/branches/2.x/src/main/org/jboss/remoting.

jboss-remoting-commits at lists.jboss.org jboss-remoting-commits at lists.jboss.org
Thu May 14 22:58:30 EDT 2009


Author: ron.sigal at jboss.com
Date: 2009-05-14 22:58:30 -0400 (Thu, 14 May 2009)
New Revision: 5221

Modified:
   remoting2/branches/2.x/src/main/org/jboss/remoting/ServerInvoker.java
Log:
JBREM-1132: Introduced "useClientConnectionIdentity".

Modified: remoting2/branches/2.x/src/main/org/jboss/remoting/ServerInvoker.java
===================================================================
--- remoting2/branches/2.x/src/main/org/jboss/remoting/ServerInvoker.java	2009-05-15 02:49:58 UTC (rev 5220)
+++ remoting2/branches/2.x/src/main/org/jboss/remoting/ServerInvoker.java	2009-05-15 02:58:30 UTC (rev 5221)
@@ -277,6 +277,8 @@
    protected ServerSocketFactory serverSocketFactory = null;
    
    protected boolean registerCallbackListeners = true;
+   
+   protected boolean useClientConnectionIdentity;
 
    // Constructors ---------------------------------------------------------------------------------
 
@@ -293,6 +295,17 @@
    public ServerInvoker(InvokerLocator locator, Map configuration)
    {
       super(locator, configuration);
+
+      if (configuration != null)
+      {
+         this.configuration.putAll(configuration);
+      }
+
+      Map locatorParams = locator.getParameters();
+      if(locatorParams != null)
+      {
+         this.configuration.putAll(locator.getParameters());
+      }
    }
 
    // Public ---------------------------------------------------------------------------------------
@@ -322,6 +335,11 @@
    {
       return timeout;
    }
+   
+   public ConnectionNotifier getConnectionNotifier()
+   {
+      return connectionNotifier;
+   }
 
    public boolean isLeaseActivated()
    {
@@ -726,6 +744,16 @@
       return (ServerInvocationHandler) handlers.get(subsystem.toUpperCase());
    }
 
+   protected boolean isUseClientConnectionIdentity()
+   {
+      return useClientConnectionIdentity;
+   }
+
+   protected void setUseClientConnectionIdentity(boolean useClientConnectionIdentity)
+   {
+      this.useClientConnectionIdentity = useClientConnectionIdentity;
+   }
+
    public Object invoke(Object invoke) throws IOException
    {
       InvocationRequest request = null;
@@ -1117,6 +1145,13 @@
          }
       }
       
+      // config for useClientConnectionIdentity
+      String useClientConnectionIdentityString = (String)config.get(Remoting.USE_CLIENT_CONNECTION_IDENTITY);
+      if(useClientConnectionIdentityString != null)
+      {
+         useClientConnectionIdentity = Boolean.parseBoolean(useClientConnectionIdentityString);
+      }
+      
       // Inject ConnectionListener
       String connectionListener = (String)config.get(CONNECTION_LISTENER);
       if (connectionListener != null)
@@ -1879,6 +1914,7 @@
    {
       if (invocation != null)
       {
+         // clientSessionId == MicroRemoteClientInvoker.invokerSessionID.
          String clientSessionId = invocation.getSessionId();
          Lease clientLease = (Lease)clientLeases.get(clientSessionId);
 
@@ -1914,7 +1950,7 @@
          else
          {
              String type = "invoker";
-        	 Map reqMap = invocation.getRequestPayload();
+        	    Map reqMap = invocation.getRequestPayload();
              if (reqMap != null)
              {
                 Object holderObj = reqMap.get(ClientHolder.CLIENT_HOLDER_KEY);
@@ -1923,8 +1959,9 @@
                 	type = "client";
                 }
              }
-             log.warn("Asked to terminate " + type + " lease for client session id " + clientSessionId +
-                       ", but lease for this id could not be found." + ": " + clientLeases);
+             log.debug("Asked to terminate " + type + " lease for invoker session id "
+                       + clientSessionId + ", but lease for this id could not be found." +"" +
+                       "Probably has been removed due to connection failure.");
          }
       }
    }
@@ -1941,7 +1978,7 @@
          }
          if(clientSessionId != null)
          {
-            if(trace) { log.trace("Getting lease for client session id: " + clientSessionId); }
+            if(trace) { log.trace("Getting lease for invoker session id: " + clientSessionId); }
 
             Lease clientLease = (Lease)clientLeases.get(clientSessionId);
             if(clientLease == null)
@@ -1954,15 +1991,48 @@
 
                clientLeases.put(clientSessionId, newClientLease);
                newClientLease.startLease();
-
-               if(trace) { log.trace("No lease established for client session id (" + clientSessionId + "), so starting a new one."); }
+               
+               if(trace) { log.trace("No lease established for invoker session id (" + clientSessionId + 
+                                    "), so starting a new one:" + newClientLease); }
             }
             else
             {
-               // including request payload from invocation as may contain updated list of clients.
-               clientLease.updateLease(leasePeriod, invocation.getRequestPayload());
+               if (useClientConnectionIdentity)
+               {
+                  String leasePingerId = (String) invocation.getRequestPayload().get(LeasePinger.LEASE_PINGER_ID);;
+                  if (leasePingerId.equals(clientLease.getLeasePingerId()))
+                  {
+                     // including request payload from invocation as may contain updated list of clients.
+                     if (trace) log.trace(clientLease + " matches: leasePingerId: " + leasePingerId);
+                     clientLease.updateLease(leasePeriod, invocation.getRequestPayload());
+                     if(trace) { log.trace("Updated lease for invoker session id (" + clientSessionId + ")"); }
+                  }
+                  else
+                  {
+                     if (trace) log.trace(clientLease + " does not match: leasePingerId: " + leasePingerId);
+                     if (trace) log.trace("terminating invoker lease: " + clientLease);
+                     clientLease.terminateLeaseUponFailure(clientSessionId);
+                     clientLeases.remove(clientSessionId);
 
-               if(trace) { log.trace("Updated lease for client session id (" + clientSessionId + ")"); }
+                     Lease newClientLease = new Lease(clientSessionId, leasePeriod,
+                                                      locator.getLocatorURI(),
+                                                      invocation.getRequestPayload(),
+                                                      connectionNotifier,
+                                                      clientLeases);
+
+                     clientLeases.put(clientSessionId, newClientLease);
+                     newClientLease.startLease();
+
+                     if(trace) { log.trace("starting a new lease:" + newClientLease); }
+                  }
+               }
+               else
+               {
+                  // including request payload from invocation as may contain updated list of clients.
+                  clientLease.updateLease(leasePeriod, invocation.getRequestPayload());
+
+                  if(trace) { log.trace("Updated lease for client session id (" + clientSessionId + ")"); }
+               }
             }
          }
       }
@@ -1972,7 +2042,7 @@
    {
       if(leaseManagement && invokerSessionId != null)
       {
-         if(trace) { log.trace("Checking lease for client session id: " + invokerSessionId); }
+         if(trace) { log.trace("Checking lease for invoker session id: " + invokerSessionId); }
 
          Lease clientLease = (Lease)clientLeases.get(invokerSessionId);
          if(clientLease == null)
@@ -2064,6 +2134,7 @@
       {
          callbackHandler = (ServerInvokerCallbackHandler) callbackHandlers.remove(id);
       }
+      log.debug(this + " removed " + callbackHandler);
       return callbackHandler;
    }
    




More information about the jboss-remoting-commits mailing list