[jboss-cvs] JBossRemoting/src/main/org/jboss/remoting ...

Timothy Fox tim.fox at jboss.com
Wed Jan 31 06:10:22 EST 2007


  User: timfox  
  Date: 07/01/31 06:10:22

  Modified:    src/main/org/jboss/remoting  Tag: remoting_2_x
                        ServerInvoker.java
  Log:
  Added optimisation in ServerInvoker for the case when there is only one invocation handler
  Also fixed broken build (SocketWrapper.TEMP_TIMEOUT was missing)
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.52.2.25 +43 -10    JBossRemoting/src/main/org/jboss/remoting/ServerInvoker.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: ServerInvoker.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossRemoting/src/main/org/jboss/remoting/ServerInvoker.java,v
  retrieving revision 1.52.2.24
  retrieving revision 1.52.2.25
  diff -u -b -r1.52.2.24 -r1.52.2.25
  --- ServerInvoker.java	25 Jan 2007 01:07:09 -0000	1.52.2.24
  +++ ServerInvoker.java	31 Jan 2007 11:10:22 -0000	1.52.2.25
  @@ -65,7 +65,7 @@
    * @author <a href="mailto:tom.elrod at jboss.com">Tom Elrod</a>
    * @author <a href="mailto:ovidiu at jboss.org">Ovidiu Feodorov</a>
    *
  - * @version $Revision: 1.52.2.24 $
  + * @version $Revision: 1.52.2.25 $
    */
   public abstract class ServerInvoker extends AbstractInvoker implements ServerInvokerMBean
   {
  @@ -197,6 +197,11 @@
   
   
      protected Map handlers = new HashMap();
  +   
  +   //If there is only one handler we store a direct reference to it, as an optimisation
  +   //to avoid lookup in this common case - TLF
  +   protected ServerInvocationHandler singleHandler;
  +      
      protected Map callbackHandlers = new HashMap();
      protected Map clientCallbackListener = new HashMap();
      protected boolean started = false;
  @@ -516,6 +521,15 @@
         log.debug(this + " added " + handler + " for subsystem '" + subsystem + "'" +
            (oldHandler == null ? "" : ", replacing old handler " + oldHandler));
   
  +      if (handlers.size() == 1)
  +      {
  +         singleHandler = handler;
  +      }
  +      else
  +      {
  +         singleHandler = null;
  +      }
  +
         return oldHandler;
      }
   
  @@ -531,6 +545,15 @@
            " tried to remove handler for " + subsystem + " but no handler found" :
            " removed handler " + handler + " for subsystem '" + subsystem + "'"));
   
  +      if (handlers.size() == 1)
  +      {
  +         singleHandler = (ServerInvocationHandler)handlers.values().iterator().next();
  +      }
  +      else
  +      {
  +         singleHandler = null;
  +      }
  +
         return handler;
      }
   
  @@ -641,9 +664,18 @@
               String subsystem = invocation.getSubsystem();
               String clientId = invocation.getSessionId();
   
  -            // too bad we can't optimize this a little better, since we take a lookup hit for
  -            // each invocation -JGH
  +            //I have optimised this, so that if there is only one handler set (a very common case)
  +            //then it will just use that without having to do a lookup or HashMap iteration over
  +            //values
  +            
               ServerInvocationHandler handler = null;
  +                        
  +            if (singleHandler != null)
  +            {
  +               handler = singleHandler;
  +            }
  +            else
  +            {               
               if (subsystem != null)
               {
                  handler = (ServerInvocationHandler)handlers.get(subsystem.toUpperCase());
  @@ -657,6 +689,7 @@
                     handler = (ServerInvocationHandler)handlers.values().iterator().next();
                  }
               }
  +            }
   
               if (param instanceof InternalInvocation)
               {
  
  
  



More information about the jboss-cvs-commits mailing list