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

Ron Sigal ron_sigal at yahoo.com
Wed Aug 22 22:51:59 EDT 2007


  User: rsigal  
  Date: 07/08/22 22:51:59

  Modified:    src/main/org/jboss/remoting  Tag: remoting_2_2_0_GA
                        Client.java
  Log:
  JBREM-641, JBREM-743, JBREM-755, JBREM-757:  Merged changes from remoting_2_2_2_experimental branch.
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.53.2.29.2.2 +98 -14    JBossRemoting/src/main/org/jboss/remoting/Client.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: Client.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossRemoting/src/main/org/jboss/remoting/Client.java,v
  retrieving revision 1.53.2.29.2.1
  retrieving revision 1.53.2.29.2.2
  diff -u -b -r1.53.2.29.2.1 -r1.53.2.29.2.2
  --- Client.java	11 Apr 2007 23:45:26 -0000	1.53.2.29.2.1
  +++ Client.java	23 Aug 2007 02:51:59 -0000	1.53.2.29.2.2
  @@ -50,6 +50,8 @@
   import java.io.ObjectOutput;
   import java.io.StreamCorruptedException;
   import java.net.InetAddress;
  +import java.net.SocketTimeoutException;
  +import java.rmi.MarshalException;
   import java.util.ArrayList;
   import java.util.HashMap;
   import java.util.HashSet;
  @@ -66,7 +68,7 @@
    * @author <a href="mailto:telrod at e2technologies.net">Tom Elrod</a>
    * @author <a href="mailto:ovidiu at jboss.org">Ovidiu Feodorov</a>
    *
  - * @version $Revision: 1.53.2.29.2.1 $
  + * @version $Revision: 1.53.2.29.2.2 $
    */
   public class Client implements Externalizable
   {
  @@ -149,6 +151,8 @@
       */
      public static final int DEFAULT_DISCONNECT_TIMEOUT = -1;
   
  +   public static final String THROW_CALLBACK_EXCEPTION = "throwCallbackException";
  +
      private static final Logger log = Logger.getLogger(Client.class);
   
      private static final long serialVersionUID = 5679279425009837934L;
  @@ -346,6 +350,20 @@
       */
      public void addConnectionListener(ConnectionListener listener, int pingPeriod)
      {
  +      HashMap metadata = new HashMap();
  +      metadata.put(ConnectionValidator.VALIDATOR_PING_PERIOD, Integer.toString(pingPeriod));
  +      addConnectionListener(listener, metadata);
  +   }
  +   
  +   /**
  +    * Adds a connection listener that will be notified if/when the connection to the server fails
  +    * while the client is idle (no calls being made). The current behavior is to ping the server
  +    * periodically.  Various parameters may be specified in metadata.
  +    * 
  +    * @see org.jboss.remoting.ConnectionValidator
  +    */
  +   public void addConnectionListener(ConnectionListener listener, Map metadata)
  +   {
         if (invoker == null)
         {
            throw new RuntimeException("Can not add connection listener to remoting client " +
  @@ -362,7 +380,7 @@
   
         if (connectionValidator == null)
         {
  -         connectionValidator = new ConnectionValidator(this, pingPeriod);
  +         connectionValidator = new ConnectionValidator(this, metadata);
         }
         connectionValidator.addConnectionListener(listener);
      }
  @@ -900,17 +918,23 @@
                  callbackServerConnector.start();
                  // have to use the locator from the server as can be modified internally
                  callbackLocator = callbackServerConnector.getServerInvoker().getLocator();
  +               addCallbackListener(callbackhandler, metadata, callbackLocator, callbackHandlerObject);
               }
               else
               {
  +               if (callbackPollers.get(callbackhandler) != null)
  +               {
  +                  log.debug(callbackhandler + " already registered");
  +                  return;
  +               }
  +               
                  //need to setup poller to get callbacks from the server
                  CallbackPoller poller =
                     new CallbackPoller(this, callbackhandler, metadata, callbackHandlerObject);
                  callbackPollers.put(callbackhandler, poller);
  +               addCallbackListener(callbackhandler, metadata, callbackLocator, callbackHandlerObject);
                  poller.start();
               }
  -
  -            addCallbackListener(callbackhandler, metadata, callbackLocator, callbackHandlerObject);
            }
            else
            {
  @@ -1000,9 +1024,24 @@
               if(listenerId != null)
               {
                  // have a pull callback handler
  +               // If disconnectTimeout == 0, skip network i/o.
  +               if (disconnectTimeout != 0)
  +               {
                  Map metadata = new HashMap();
                  metadata.put(LISTENER_ID_KEY, listenerId);
  +                  
  +                  if (disconnectTimeout > 0)
  +                     metadata.put(ServerInvoker.TIMEOUT, Integer.toString(disconnectTimeout));
  +
  +                  try
  +                  {
                  invoke(new InternalInvocation(InternalInvocation.REMOVELISTENER, null), metadata);
  +                  }
  +                  catch (Exception e)
  +                  {
  +                     log.warn("unable to remove remote callback handler: " + e.getMessage());
  +                  }
  +               }
   
                  // clean up callback poller if one exists
                  CallbackPoller callbackPoller = (CallbackPoller) callbackPollers.remove(callbackHandler);
  @@ -1099,25 +1138,70 @@
       */
      public List getCallbacks(InvokerCallbackHandler callbackHandler) throws Throwable
      {
  +      return getCallbacks(callbackHandler, null);
  +   }
  +   
  +   /**
  +    * Gets the callbacks for specified callback handler. The handler is required because an id is
  +    * generated for each handler.  So if have two callback handlers registered with the same server,
  +    * no other way to know for which handler to get the callbacks for.
  +    * 
  +    * The metadata map can be used to set callback blocking mode and blocking timeout
  +    * value.
  +    */
  +   public List getCallbacks(InvokerCallbackHandler callbackHandler, Map metadata) throws Throwable
  +   {
         if (callbackHandler != null)
         {
            String listenerId = (String)listeners.get(callbackHandler);
   
            if(listenerId != null)
            {
  -            Map metadata = new HashMap();
  +            if (metadata == null)
  +               metadata = new HashMap();
  +            
               metadata.put(LISTENER_ID_KEY, listenerId);
  -            return
  -               (List)invoke(new InternalInvocation(InternalInvocation.GETCALLBACKS, null), metadata);
  +            InternalInvocation invocation = new InternalInvocation(InternalInvocation.GETCALLBACKS, null);
  +
  +            try
  +            {
  +               List response = (List) invoke(invocation, metadata);
  +               return response;
  +            }
  +            catch (MarshalException e)
  +            {
  +               if (e.getCause() != null && e.getCause() instanceof SocketTimeoutException)
  +               {
  +                  if (log.isTraceEnabled()) log.trace(this + ": getCallbacks() timed out: returning empty list");
  +                  return new ArrayList();
  +               }
  +               throw e;
  +            }
  +            finally
  +            {
  +               metadata.remove(LISTENER_ID_KEY);
  +            }
            }
            else
            {
  -            log.error("Could not find listener id for InvokerCallbackHandler (" + callbackHandler +
  -                      "), please verify handler has been registered as listener.");
  +            String errorMessage = "Could not find listener id for InvokerCallbackHandler (" +
  +                                  callbackHandler +
  +                                  "), please verify handler has been registered as listener.";
  +
  +            String errorMode = (String) metadata.get(THROW_CALLBACK_EXCEPTION);
  +            boolean throwError = Boolean.valueOf(errorMode).booleanValue();
   
  +            if (throwError)
  +            {
  +               throw new IOException(errorMessage);
  +            }
  +            else
  +            {
  +               log.error(errorMessage);
               return null;
            }
         }
  +      }
         else
         {
            throw new NullPointerException("Can not remove null InvokerCallbackHandler listener.");
  
  
  



More information about the jboss-cvs-commits mailing list