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

Ron Sigal ron_sigal at yahoo.com
Thu Nov 16 05:24:49 EST 2006


  User: rsigal  
  Date: 06/11/16 05:24:49

  Modified:    src/main/org/jboss/remoting/samples/callback/acknowledgement  
                        Tag: remoting_2_x CallbackAcknowledgeClient.java
                        CallbackAcknowledgeServer.java
  Log:
  JBREM-605:  Changed in accordance to removal of postprocess acknowledgements and acknowledgeme
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.3   +99 -82    JBossRemoting/src/main/org/jboss/remoting/samples/callback/acknowledgement/CallbackAcknowledgeClient.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: CallbackAcknowledgeClient.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossRemoting/src/main/org/jboss/remoting/samples/callback/acknowledgement/CallbackAcknowledgeClient.java,v
  retrieving revision 1.1.2.2
  retrieving revision 1.1.2.3
  diff -u -b -r1.1.2.2 -r1.1.2.3
  --- CallbackAcknowledgeClient.java	6 Nov 2006 07:22:37 -0000	1.1.2.2
  +++ CallbackAcknowledgeClient.java	16 Nov 2006 10:24:49 -0000	1.1.2.3
  @@ -22,7 +22,7 @@
   
   
   /**
  - * Tests Callback acknowledgements.
  + * Demonstrates Callback acknowledgements.
    * 
    * @author <a href="mailto:ron.sigal at jboss.com">Ron Sigal</a>
    * <p/>
  @@ -33,6 +33,7 @@
   
   import java.net.InetAddress;
   import java.net.UnknownHostException;
  +import java.util.ArrayList;
   import java.util.HashMap;
   import java.util.Iterator;
   import java.util.List;
  @@ -77,19 +78,18 @@
            return;
         }
         String locatorURI = transport + "://" + host + ":" + port;
  -      CallbackAcknowledgeClient client = new CallbackAcknowledgeClient();
  +      CallbackAcknowledgeClient acknowledgeClient = new CallbackAcknowledgeClient();
         try
         {
  -         client.createRemotingClient(locatorURI);
  +         acknowledgeClient.createRemotingClient(locatorURI);
   
  -         client.testPullCallbackPreprocessAcknowledgement();
  -         client.testPullCallbackPostprocessAcknowledgement();
  -         client.testPollCallbackPreprocessAcknowledgement();
  -         client.testPollCallbackPostprocessAcknowledgement();
  -         client.testPushCallbackPreprocessAcknowledgement();
  -         client.testPushCallbackPostprocessAcknowledgement();
  +         acknowledgeClient.testPullCallbackAcknowledgements();
  +         acknowledgeClient.testPolledCallbackApplicationAcknowledgements();
  +         acknowledgeClient.testPolledCallbackRemotingAcknowledgements();
  +         acknowledgeClient.testPushCallbackApplicationAcknowledgements();
  +         acknowledgeClient.testPushCallbackRemotingAcknowledgements();
            
  -         client.disconnectRemotingClient();
  +         acknowledgeClient.disconnectRemotingClient();
         }
         catch(Throwable e)
         {
  @@ -114,64 +114,38 @@
   
      
      /**
  -    * In this test the connection is configured for true pull callbacks, and
  -    * the acknowledgement should be made implicitly by ServerInvokerCallbackHandler
  -    * during the call to getCallbacks() (before the callbacks are retrieved by
  -    * the client).
  +    * In this test, the connection is configured for pull callbacks, and
  +    * acknowledgements are made by an explicit call to Client.acknowledgeCallback()
  +    * after the callbacks have been received.
       */
  -   public void testPullCallbackPreprocessAcknowledgement()
  +   public void testPullCallbackAcknowledgements()
      {
         try
         {
  -         TestCallbackHandler callbackHandler = new TestCallbackHandler();
  +         // Register callback handler.
  +         InvokerCallbackHandler callbackHandler = new NonAcknowledgingCallbackHandler();
            client.addListener(callbackHandler);
  -         client.invoke(CallbackAcknowledgeServer.PREPROCESS_TEST);
  -         Thread.sleep(2000);
  -         List callbacks = client.getCallbacks(callbackHandler);
  -         Iterator it = callbacks.iterator();
  -         while (it.hasNext())
  -         {
  -            Callback callback = (Callback) it.next();
  -            System.out.println("received pull callback: " + callback.getParameter());
  -         }
  -         client.removeListener(callbackHandler);
  -      }
  -      catch (Throwable e)
  -      {
  -         System.out.println("failure: " + e.getMessage());
  -      }
  -   }
      
  +         // Request callbacks from server.
  +         client.invoke(CallbackAcknowledgeServer.APPLICATION_ACKNOWLDEGEMENTS);
      
  -   /**
  -    * In this test, the connection is configured for true pull callbacks, and the 
  -    * acknowledgement should be made by an explicit call to Client.acknowledgeCallback()
  -    * after the callback has been retrieved and (presumably) processed.
  -    */
  -   public void testPullCallbackPostprocessAcknowledgement()
  -   {
  -      try
  -      {
  -         TestCallbackHandler callbackHandler = new TestCallbackHandler();
  -         client.addListener(callbackHandler);
  -         client.invoke(CallbackAcknowledgeServer.POSTPROCESS_TEST);
  +         // Get callbacks.
            List callbacks = client.getCallbacks(callbackHandler);
  -         Thread.sleep(2000);
  +         
  +         // Create responses.
  +         ArrayList responses = new ArrayList(callbacks.size());
            Iterator it = callbacks.iterator();
            while (it.hasNext())
            {
               Callback callback = (Callback) it.next();
               System.out.println("received pull callback: " + callback.getParameter());
  -            
  -            // Could acknowledge individual callbacks:
  -//            ArrayList list = new ArrayList(1);
  -//            list.add(callback);
  -//            client.acknowledgeCallbacks(callbackHandler, list);
  +            responses.add(callback.getParameter() + ": acknowledged");
            }
            
  -         // Acknowledge pull callbacks.
  -         client.acknowledgeCallbacks(callbackHandler, callbacks);
  +         // Acknowledge callbacks.
  +         client.acknowledgeCallbacks(callbackHandler, callbacks, responses);
            
  +         // Unregister callback handler.
            client.removeListener(callbackHandler);
         }
         catch (Throwable e)
  @@ -184,20 +158,25 @@
      /**
       * In this test the connection is configured for push callbacks implemented in
       * Remoting by polling the server for callbacks and pushing them (on the client 
  -    * side) to the InvokerCallbackHandler.  The acknowledgement should be made
  -    * implicitly by ServerInvokerCallbackHandler during the call to getCallbacks()
  -    * (before the callbacks are retrieved by the client).
  +    * side) to the InvokerCallbackHandler.  Acknowledgements are made from 
  +    * TestCallbackHandler.handleCallback() by an explicit call to
  +    * Client.acknowledgeCallback() after the callbacks have been received.
       */
  -   public void testPollCallbackPreprocessAcknowledgement()
  +   public void testPolledCallbackApplicationAcknowledgements()
      {
         try
         {
  -         TestCallbackHandler callbackHandler = new TestCallbackHandler();
  +         // Register callback handler.
  +         InvokerCallbackHandler callbackHandler = new AcknowledgingCallbackHandler(client);
            HashMap metadata = new HashMap();
  -         metadata.put(CallbackPoller.CALLBACK_POLL_PERIOD, "100");
  +         metadata.put(CallbackPoller.CALLBACK_POLL_PERIOD, "1000");
            client.addListener(callbackHandler, metadata);
  -         client.invoke(CallbackAcknowledgeServer.PREPROCESS_TEST);
  +         
  +         // Request callbacks from server.
  +         client.invoke(CallbackAcknowledgeServer.APPLICATION_ACKNOWLDEGEMENTS);
            Thread.sleep(2000);
  +         
  +         // Unregister callback handler.
            client.removeListener(callbackHandler);
         }
         catch (Throwable e)
  @@ -210,20 +189,24 @@
      /**
       * In this test the connection is configured for push callbacks implemented in
       * Remoting by polling the server for callbacks and pushing them (on the client 
  -    * side) to the InvokerCallbackHandler.  The acknowledgement should be made
  -    * implicitly by CallbackPoller, which it does by calling Client.acknowledgeCallback()
  -    * after it has pushed the callback to the InvokerCallbackHandler.
  +    * side) to the InvokerCallbackHandler.  Acknowledgements are handled implicitly
  +    * by Remoting.
       */
  -   public void testPollCallbackPostprocessAcknowledgement()
  +   public void testPolledCallbackRemotingAcknowledgements()
      {
         try
         {
  -         TestCallbackHandler callbackHandler = new TestCallbackHandler();
  +         // Register callback handler.
  +         InvokerCallbackHandler callbackHandler = new NonAcknowledgingCallbackHandler();
            HashMap metadata = new HashMap();
  -         metadata.put(CallbackPoller.CALLBACK_POLL_PERIOD, "100");
  +         metadata.put(CallbackPoller.CALLBACK_POLL_PERIOD, "1000");
            client.addListener(callbackHandler, metadata);
  -         client.invoke(CallbackAcknowledgeServer.POSTPROCESS_TEST);
  +         
  +         // Request callbacks from server.
  +         client.invoke(CallbackAcknowledgeServer.REMOTING_ACKNOWLDEGEMENTS);
            Thread.sleep(2000);
  +         
  +         // Unregister callback handler.
            client.removeListener(callbackHandler);
         }
         catch (Throwable e)
  @@ -234,18 +217,23 @@
      
      
      /**
  -    * In this test the connection is configured for true push callbacks, and the
  -    * acknowledgement should be made by ServerInvokerCallbackHandler.handleCallback()
  -    * after it has pushed the Callback to the client.
  +    * In this test the connection is configured for true push callbacks.
  +    * Acknowledgements are made from TestCallbackHandler.handleCallback()
  +    * by an explicit call to Client.acknowledgeCallback() after the callbacks
  +    * have been received.
       */
  -   public void testPushCallbackPreprocessAcknowledgement()
  +   public void testPushCallbackApplicationAcknowledgements()
      {
         try
         {
  -         TestCallbackHandler callbackHandler = new TestCallbackHandler();
  +         // Register callback handler.
  +         InvokerCallbackHandler callbackHandler = new AcknowledgingCallbackHandler(client);
            client.addListener(callbackHandler, null, null, true);
  -         client.invoke(CallbackAcknowledgeServer.PREPROCESS_TEST);
  -         Thread.sleep(2000);
  +         
  +         // Request callbacks from servrr.
  +         client.invoke(CallbackAcknowledgeServer.APPLICATION_ACKNOWLDEGEMENTS);
  +         
  +         // Unregister callback handler.
            client.removeListener(callbackHandler);
         }
         catch (Throwable e)
  @@ -256,17 +244,21 @@
      
      
      /**
  -    * In this test the connection is configured for true push callbacks, and the
  -    * acknowledgement should be made by ServerInvokerCallbackHandler.handleCallback()
  -    * after it has pushed the Callback to the client.
  +    * In this test the connection is configured for true push callbacks, and
  +    * Acknowledgements are handled implicitly by Remoting.
       */
  -   public void testPushCallbackPostprocessAcknowledgement()
  +   public void testPushCallbackRemotingAcknowledgements()
      {
         try
         {
  -         TestCallbackHandler callbackHandler = new TestCallbackHandler();
  +         // Register callback handler.
  +         InvokerCallbackHandler callbackHandler = new NonAcknowledgingCallbackHandler();
            client.addListener(callbackHandler, null, null, true);
  -         client.invoke(CallbackAcknowledgeServer.POSTPROCESS_TEST);
  +         
  +         // Request callbacks from server.
  +         client.invoke(CallbackAcknowledgeServer.REMOTING_ACKNOWLDEGEMENTS);
  +         
  +         // Unregister callback handler.
            client.removeListener(callbackHandler);
         }
         catch (Throwable e)
  @@ -276,11 +268,36 @@
      }
      
      
  -   static class TestCallbackHandler implements InvokerCallbackHandler
  +   static class NonAcknowledgingCallbackHandler implements InvokerCallbackHandler
  +   {  
  +      public void handleCallback(Callback callback) throws HandleCallbackException
  +      {
  +         System.out.println("received push callback: " + callback.getParameter());
  +      }
  +   }
  +   
  +   
  +   static class AcknowledgingCallbackHandler implements InvokerCallbackHandler
      {  
  +      private Client client;
  +      
  +      public AcknowledgingCallbackHandler(Client client)
  +      {
  +         this.client = client;
  +      }
  +      
         public void handleCallback(Callback callback) throws HandleCallbackException
         {
            System.out.println("received push callback: " + callback.getParameter());
  +         Object response = callback.getParameter() + ": acknowledged";
  +         try
  +         {
  +            client.acknowledgeCallback(this, callback, response);
  +         }
  +         catch (Throwable e)
  +         {
  +            System.out.println("Unable to acknowledge callback: " + callback.getParameter());
  +         }
         }
      }
   }
  
  
  
  1.1.2.3   +22 -38    JBossRemoting/src/main/org/jboss/remoting/samples/callback/acknowledgement/CallbackAcknowledgeServer.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: CallbackAcknowledgeServer.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossRemoting/src/main/org/jboss/remoting/samples/callback/acknowledgement/CallbackAcknowledgeServer.java,v
  retrieving revision 1.1.2.2
  retrieving revision 1.1.2.3
  diff -u -b -r1.1.2.2 -r1.1.2.3
  --- CallbackAcknowledgeServer.java	6 Nov 2006 07:22:37 -0000	1.1.2.2
  +++ CallbackAcknowledgeServer.java	16 Nov 2006 10:24:49 -0000	1.1.2.3
  @@ -22,7 +22,7 @@
   
   
   /**
  - * Tests Callback acknowledgements.
  + * Demonstrates Callback acknowledgements.
    * 
    * @author <a href="mailto:ron.sigal at jboss.com">Ron Sigal</a>
    * <p/>
  @@ -46,12 +46,13 @@
   import org.jboss.remoting.callback.InvokerCallbackHandler;
   import org.jboss.remoting.callback.ServerInvokerCallbackHandler;
   import org.jboss.remoting.transport.Connector;
  +import org.jboss.util.id.GUID;
   
   
   public class CallbackAcknowledgeServer
   {
  -   public static final String PREPROCESS_TEST = "preprocessTest";
  -   public static final String POSTPROCESS_TEST = "postprocessTest";
  +   public static final String APPLICATION_ACKNOWLDEGEMENTS = "applicationAcknowledgements";
  +   public static final String REMOTING_ACKNOWLDEGEMENTS = "remotingAcknowledgements";
      
      private static String transport = "socket";
      private static String host;
  @@ -111,6 +112,7 @@
      static class TestInvoocationHandler implements ServerInvocationHandler, CallbackListener
      {
         InvokerCallbackHandler callbackHandler;
  +      int counter;
         
         public void setMBeanServer(MBeanServer server) {}
   
  @@ -118,36 +120,23 @@
   
         public Object invoke(InvocationRequest invocation) throws Throwable
         {
  -
            String command = (String) invocation.getParameter();
            System.out.println("command: " + command);
  -         if (PREPROCESS_TEST.equals(command))
  -         {
  -            Callback cb = new Callback(PREPROCESS_TEST);
               
  -            // Register as preprocess listener and pass callback id.
  -            HashMap returnPayload = new HashMap();
  -            returnPayload.put(ServerInvokerCallbackHandler.CALLBACK_PREPROCESS_LISTENER, this);
  -            returnPayload.put(ServerInvokerCallbackHandler.CALLBACK_ID, "preprocess");
  -            cb.setReturnPayload(returnPayload);
  -            callbackHandler.handleCallback(cb);
  -         }
  -         else if (POSTPROCESS_TEST.equals(command))
  -         {
  -            Callback cb = new Callback(POSTPROCESS_TEST);
  +         Callback cb = new Callback("callback " + ++counter);
               
  -            // Register as preprocess listener and pass callback id.
  +         // Register as listener and pass callback id.
               HashMap returnPayload = new HashMap();
  -            returnPayload.put(ServerInvokerCallbackHandler.CALLBACK_POSTPROCESS_LISTENER, this);
  -            returnPayload.put(ServerInvokerCallbackHandler.CALLBACK_ID, "postprocess");
  +         returnPayload.put(ServerInvokerCallbackHandler.CALLBACK_LISTENER, this);
  +         returnPayload.put(ServerInvokerCallbackHandler.CALLBACK_ID, new GUID());
               cb.setReturnPayload(returnPayload);
  -            callbackHandler.handleCallback(cb);
  -         }
  -         else 
  +         
  +         if (REMOTING_ACKNOWLDEGEMENTS.equals(command))
            {
  -            throw new Exception("unrecognized test command");
  +            returnPayload.put(ServerInvokerCallbackHandler.REMOTING_ACKNOWLEDGES_PUSH_CALLBACKS, "true");
            }
            
  +         callbackHandler.handleCallback(cb);         
            return null;
         }
   
  @@ -161,16 +150,11 @@
         /**
          * callbackSent() is called to acknowledgement the sending of a callback.
          */
  -      public void callbackSent(Object callbackId, int preOrPost)
  -      {
  -         if (ServerInvokerCallbackHandler.CALLBACK_ACK_PREPROCESS == preOrPost)
  +      public void acknowledgeCallback(InvokerCallbackHandler callbackHandler, Object callbackId, Object response)
            {
  -            System.out.println("received preprocess acknowledgment for callback: " + callbackId);
  -         }
  -         else  if (ServerInvokerCallbackHandler.CALLBACK_ACK_POSTPROCESS == preOrPost)
  -         {
  -            System.out.println("received postprocess acknowledgment for callback: " + callbackId);
  -         }
  +         System.out.println("received acknowledgment for callback: " + callbackId);
  +         System.out.println("response: " + response);
  +         System.out.println("");
         }
      }
   }
  
  
  



More information about the jboss-cvs-commits mailing list