if (log.isTraceEnabled()) log.trace("MethodName=" + methodName + " declaringclass=" + m.getDeclaringClass());
   public Object invoke(Invocation invocation) throws Throwable   {            if (invocation instanceof MethodInvocation)      {         MethodInvocation mi = (MethodInvocation)invocation;         Method m = mi.getMethod();         String methodName = m.getName();                  JMSAdvisor jmsAdvisor = (JMSAdvisor)mi.getAdvisor();         if ("createConnectionDelegate".equals(methodName))         {            // I only need a ConnectionFactoryDelegate instance, since it doesn't hold state,            // so I will always use the ServerPeer's one            ConnectionFactoryDelegate d = jmsAdvisor.getServerPeer().getConnectionFactoryDelegate();            invocation.setTargetObject(d);         }         else if ("createSessionDelegate".equals(methodName) ||                  "start".equals(methodName) ||                  "stop".equals(methodName) ||                  (("close".equals(methodName) || "closing".equals(methodName)) &&                         m.getDeclaringClass().equals(ServerConnectionDelegate.class)))         {            // look up the corresponding ServerConnectionDelegate and use that instance            String clientID = (String)invocation.getMetaData().                  getMetaData(JMSAdvisor.JMS, JMSAdvisor.CLIENT_ID);            ServerConnectionDelegate scd =                  jmsAdvisor.getServerPeer().getClientManager().getConnectionDelegate(clientID);            if (scd == null)            {               throw new Exception("The server doesn't know of any connection with clientID=" +                                   clientID);               // TODO log error            }            invocation.setTargetObject(scd);         }         else if ("createProducerDelegate".equals(methodName) ||                  "createConsumer".equals(methodName) ||                  "sendTransaction".equals(methodName) ||                  (("close".equals(methodName) || "closing".equals(methodName)) &&                      m.getDeclaringClass().equals(ServerSessionDelegate.class)))         {            // lookup the corresponding ServerSessionDelegate and use it as target for the invocation            String clientID =                  (String)invocation.getMetaData().getMetaData(JMSAdvisor.JMS,JMSAdvisor.CLIENT_ID);            ServerConnectionDelegate scd =                  jmsAdvisor.getServerPeer().getClientManager().getConnectionDelegate(clientID);            if (scd == null)            {               throw new Exception("The server doesn't know of any connection with clientID=" +                                   clientID);               // TODO log error            }            String sessionID = (String)invocation.getMetaData().                  getMetaData(JMSAdvisor.JMS, JMSAdvisor.SESSION_ID);            ServerSessionDelegate ssd = scd.getSessionDelegate(sessionID);            if (scd == null)            {               throw new Exception("The connection " + clientID + "  doesn't know of any session " +                                   "with sessionID=" + sessionID);               // TODO log error            }            // Inject the callback handler reference            InvokerCallbackHandler callbackHandler = (InvokerCallbackHandler)invocation.                  getMetaData(JMSAdvisor.JMS, JMSAdvisor.CALLBACK_HANDLER);            try            {               ssd.lock();               ssd.setCallbackHandler(callbackHandler);               invocation.setTargetObject(ssd);               return invocation.invokeNext();            }            finally            {               ssd.setCallbackHandler(null);               ssd.unlock();            }         }         else if ("send".equals(methodName) ||               (("close".equals(methodName) || "closing".equals(methodName)) &&                      m.getDeclaringClass().equals(ServerProducerDelegate.class)))         {            // lookup the corresponding ServerProducerDelegate and use it as target for the invocation            String clientID =                  (String)invocation.getMetaData().getMetaData(JMSAdvisor.JMS,JMSAdvisor.CLIENT_ID);            ServerConnectionDelegate scd =                  jmsAdvisor.getServerPeer().getClientManager().getConnectionDelegate(clientID);            if (scd == null)            {               throw new Exception("The server doesn't know of any connection with clientID=" +                                   clientID);               // TODO log error            }            String sessionID = (String)invocation.getMetaData().                  getMetaData(JMSAdvisor.JMS, JMSAdvisor.SESSION_ID);            ServerSessionDelegate ssd = scd.getSessionDelegate(sessionID);            if (scd == null)            {               throw new Exception("The connection " + clientID + "  doesn't know of any session " +                                   "with sessionID=" + sessionID);               // TODO log error            }            String producerID = (String)invocation.getMetaData().                  getMetaData(JMSAdvisor.JMS, JMSAdvisor.PRODUCER_ID);            ServerProducerDelegate spd = ssd.getProducerDelegate(producerID);            if (spd == null)            {               throw new Exception("The session " + sessionID + "  doesn't know of any producer " +                                   "with producerID=" + producerID);               // TODO log error            }            invocation.setTargetObject(spd);         }         else if ("acknowledge".equals(methodName))         {            // lookup the corresponding Consumer and use it as target for the invocation            String clientID =                  (String)invocation.getMetaData().getMetaData(JMSAdvisor.JMS,JMSAdvisor.CLIENT_ID);            ServerConnectionDelegate scd =                  jmsAdvisor.getServerPeer().getClientManager().getConnectionDelegate(clientID);            if (scd == null)            {               throw new Exception("The server doesn't know of any connection with clientID=" +                                   clientID);               // TODO log error            }            String sessionID = (String)invocation.getMetaData().                  getMetaData(JMSAdvisor.JMS, JMSAdvisor.SESSION_ID);            ServerSessionDelegate ssd = scd.getSessionDelegate(sessionID);            if (scd == null)            {               throw new Exception("The connection " + clientID + "  doesn't know of any session " +                                   "with sessionID=" + sessionID);               // TODO log error            }            String consumerID = (String)invocation.getMetaData().                  getMetaData(JMSAdvisor.JMS, JMSAdvisor.CONSUMER_ID);            Consumer c  = ssd.getConsumer(consumerID);            if (c == null)            {               throw new Exception("The session " + sessionID + "  doesn't know of any consumer " +                                   "with consumerID=" + consumerID);               // TODO log error            }            invocation.setTargetObject(c);         }      }      return invocation.invokeNext();   }