incubator-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hamm...@apache.org
Subject cvs commit: incubator-altrmi/src/test/org/apache/altrmi/test/messenger SynchronousMessengerTestCase.java
Date Fri, 18 Apr 2003 09:41:48 GMT
hammant     2003/04/18 02:41:48

  Modified:    .        build.xml
               lib/optional bcel.jar
               src/java/org/apache/altrmi/client/impl/messenger
                        SynchronousMessengerClientInvocationHandler.java
               src/java/org/apache/altrmi/server/impl/messenger
                        SynchronousMessengerServer.java
               src/test/org/apache/altrmi/test/messenger
                        SynchronousMessengerTestCase.java
  Log:
  Patch from James Strachan.  over JMS trasport now works.
  
  Revision  Changes    Path
  1.12      +0 -1      incubator-altrmi/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/incubator-altrmi/build.xml,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- build.xml	15 Apr 2003 22:15:59 -0000	1.11
  +++ build.xml	18 Apr 2003 09:41:45 -0000	1.12
  @@ -344,7 +344,6 @@
   
                       <include name="**/${test.filter}.class"/>
                       <exclude name="**/Abstract*"/>
  -                    <exclude name="**/SynchronousMessengerTestCase.class"/>
                       <exclude name="**/JSXObjectStreamTestCase.class"/> 
                   </fileset>
               </batchtest>
  
  
  
  1.3       +1358 -1359incubator-altrmi/lib/optional/bcel.jar
  
  	<<Binary file>>
  
  
  1.2       +20 -8     incubator-altrmi/src/java/org/apache/altrmi/client/impl/messenger/SynchronousMessengerClientInvocationHandler.java
  
  Index: SynchronousMessengerClientInvocationHandler.java
  ===================================================================
  RCS file: /home/cvs/incubator-altrmi/src/java/org/apache/altrmi/client/impl/messenger/SynchronousMessengerClientInvocationHandler.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- SynchronousMessengerClientInvocationHandler.java	25 Mar 2003 08:07:29 -0000	1.1
  +++ SynchronousMessengerClientInvocationHandler.java	18 Apr 2003 09:41:47 -0000	1.2
  @@ -79,7 +79,8 @@
    * Class SynchronousMessengerClientInvocationHandler
    *
    *
  - * @author Paul Hammant & Mauro Talevi
  + * @author Paul Hammant & Mauro Talevi (pairing)
  + * @author James Strachan
    * @version $Revision$
    */
   public final class SynchronousMessengerClientInvocationHandler extends AbstractClientInvocationHandler
  @@ -90,6 +91,9 @@
       private Messenger m_clientMessenger;
       private String m_subject;
       private Destination m_destination;
  +    
  +    /** timeout of requests in milliseconds or negative to disable */
  +    private long timeout = 4000L;
   
       /**
        * Constructor SynchronousMessengerClientInvocationHandler
  @@ -210,12 +214,20 @@
           {
               ObjectMessage message = m_clientMessenger.createObjectMessage(request);
   
  -            JFrame jf = new JFrame("hello");
  -            jf.setVisible(true);
  -            Message response = m_clientMessenger.call(m_destination, message);
  -            jf = new JFrame("hello2");
  -            jf.setVisible(true);
  -
  +            //JFrame jf = new JFrame("hello");
  +            //jf.setVisible(true);
  +            Message response = (timeout > 0 ) 
  +                ? m_clientMessenger.call(m_destination, message, timeout)
  +                : m_clientMessenger.call(m_destination, message);
  +            //jf = new JFrame("hello2");
  +            //jf.setVisible(true);
  +
  +            System.out.println("<<<< client has received: " + response);
  +            
  +            if (response == null) 
  +            {
  +                throw new AltrmiRuntimeException("Request timed out");
  +            }
               if (response instanceof ObjectMessage)
               {
                   ObjectMessage objectMessage = (ObjectMessage) response;
  
  
  
  1.6       +45 -29    incubator-altrmi/src/java/org/apache/altrmi/server/impl/messenger/SynchronousMessengerServer.java
  
  Index: SynchronousMessengerServer.java
  ===================================================================
  RCS file: /home/cvs/incubator-altrmi/src/java/org/apache/altrmi/server/impl/messenger/SynchronousMessengerServer.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- SynchronousMessengerServer.java	28 Mar 2003 07:44:20 -0000	1.5
  +++ SynchronousMessengerServer.java	18 Apr 2003 09:41:47 -0000	1.6
  @@ -69,20 +69,24 @@
   import javax.jms.Message;
   import javax.jms.ObjectMessage;
   import javax.jms.MessageConsumer;
  +import javax.jms.MessageListener;
   
  +import javax.swing.JOptionPane;
   
   /**
    * Class SynchronousMessengerServer
    *
    *
  - * @author Paul Hammant & Mauro Talevi
  + * @author Paul Hammant & Mauro Talevi (pairing)
  + * @author James Strachan
    * @version $Revision$
    */
  -public class SynchronousMessengerServer extends AbstractServer implements Runnable {
  +public class SynchronousMessengerServer extends AbstractServer implements MessageListener
{
       private Messenger m_messenger;
       private String m_subject;
       private Destination m_destination;
       private ThreadContext m_threadContext;
  +    private boolean useThreadPool = false;
   
       public SynchronousMessengerServer(Messenger messenger, String subject) {
           super(new InvocationHandlerAdapter());
  @@ -95,23 +99,26 @@
           try
           {
               m_destination = m_messenger.getDestination( m_subject );
  +            m_messenger.addListener(m_destination, this);
           }
           catch (JMSException e)
           {
  +            // NAUGHTY NAUGHTY! SHOULD DO SOMETHING HERE!
           }
           if ( m_destination == null ) {
               throw new ServerException( "Could not find JMS destination: " + m_subject );
           }
   
  -        m_threadContext = getThreadPool().getThreadContext(this);
  -        m_threadContext.start();
  +        //m_threadContext = getThreadPool().getThreadContext(this);
  +        //m_threadContext.start();
       }
   
       public void stop() {
  -        m_threadContext.interrupt();
  -        m_threadContext = null;
  +        //m_threadContext.interrupt();
  +        //m_threadContext = null;
           try
           {
  +            m_messenger.removeListener(m_destination, this);
               m_messenger.close();
           } catch (JMSException e)
           {
  @@ -120,14 +127,12 @@
       }
   
       /**
  -     * Daemon Thread
  +     * MessageListener
        */
  -    public void run() {
  -
  -        try
  -        {
  -            final Message message = m_messenger.receive( m_destination );
  -
  +    public void onMessage(final Message message) {
  +            System.out.println(">>>> server received inbound message: " + message);
  +            //JOptionPane.showInputDialog("receved inbound message: " + message);
  +            
               Runnable runnable = new Runnable() {
                   public void run() {
                       try
  @@ -136,34 +141,45 @@
                           {
                               ObjectMessage objectMessage = (ObjectMessage) message;
                               Object obj = objectMessage.getObject();
  -                            if (obj instanceof byte[])
  +                            if (obj instanceof Request)
                               {
  -                                byte[] requestBytes = (byte[]) obj;
  -                                Request req = (Request) SerializationHelper.getInstanceFromBytes(requestBytes);
  +                                //byte[] requestBytes = (byte[]) obj;
  +                                //Request req = (Request) SerializationHelper.getInstanceFromBytes(requestBytes);
  +                                Request req = (Request) obj;
                                   Reply reply = handleInvocation(req, "JMS:" + message.getJMSReplyTo().toString());
                                   Destination dest = message.getJMSReplyTo();
                                   String correlationID = message.getJMSCorrelationID();
  -                                byte[] replyBytes = SerializationHelper.getBytesFromInstance(reply);
  -                                ObjectMessage om = m_messenger.createObjectMessage( replyBytes
);
  +                                //byte[] replyBytes = SerializationHelper.getBytesFromInstance(reply);
  +                                ObjectMessage om = m_messenger.createObjectMessage( reply
);
  +                                //ObjectMessage om = m_messenger.createObjectMessage( replyBytes
);
                                   om.setJMSCorrelationID(correlationID);
  +                                
  +                                System.out.println("**** sending reply to client: " + om);
  +                                //JOptionPane.showInputDialog("**** sending message: "
+ om);
  +            
                                   m_messenger.send(dest, om);
                               }
  +                            else {
  +                                System.out.println("Invalid message!");
  +                            }
  +                        }
  +                        else {
  +                            System.out.println("Not an ObjectMessage!");
                           }
                       } catch (JMSException e)
                       {
                           getServerMonitor().unexpectedException(this.getClass(),"SynchronousMessengerServer.run()
JMSException #1",e);
  -                    } catch (ClassNotFoundException e)
  -                    {
  -                        getServerMonitor().classNotFound(this.getClass(),e);
                       }
                   }
               };
  -            getThreadPool().getThreadContext(runnable);
  +            
  +            if (useThreadPool) {
  +                getThreadPool().getThreadContext(runnable);            
  +            }
  +            else {
  +                runnable.run();
  +            }
   
  -        }
  -        catch (JMSException e)
  -        {
  -            getServerMonitor().unexpectedException(this.getClass(),"SynchronousMessengerServer.run()
JMSException #2",e);
  -        }
  -    }
  +           
  +     }
   }
  
  
  
  1.3       +14 -8     incubator-altrmi/src/test/org/apache/altrmi/test/messenger/SynchronousMessengerTestCase.java
  
  Index: SynchronousMessengerTestCase.java
  ===================================================================
  RCS file: /home/cvs/incubator-altrmi/src/test/org/apache/altrmi/test/messenger/SynchronousMessengerTestCase.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- SynchronousMessengerTestCase.java	28 Mar 2003 07:44:20 -0000	1.2
  +++ SynchronousMessengerTestCase.java	18 Apr 2003 09:41:47 -0000	1.3
  @@ -70,7 +70,8 @@
    * Class SynchronousMessengerTestCase
    *
    *
  - * @author Paul Hammant & Mauro Talevi
  + * @author Paul Hammant & Mauro Talevi (pairing)
  + * @author James Strachan
    * @version $Revision$
    */
   public class SynchronousMessengerTestCase extends AbstractHelloTestCase
  @@ -92,8 +93,14 @@
           // TODO this needed?
           Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
   
  -        serverMessenger = MessengerManager.get("cacheTopicConnection");
  -        server = new SynchronousMessengerServer(serverMessenger, "ASubject");
  +        // lets create new connections each time
  +        MessengerManager manager = MessengerManager.load(getClass().getClassLoader().getResource("Messenger.xml").toString());
  +        serverMessenger = manager.getMessenger("cacheQueueConnection");
  +        
  +        // use a different subject per test
  +        String subject = getClass().getName() + "." + getName();
  +        server = new SynchronousMessengerServer(serverMessenger, subject);
  +        
           testServer = new TestInterfaceImpl();
           PublicationDescription pd = new PublicationDescription(TestInterface.class,
                   new Class[]{TestInterface3.class, TestInterface2.class});
  @@ -102,10 +109,8 @@
   
           // Client side setup
           altrmiFactory = new ClientSideClassFactory();
  -        clientMessenger = MessengerManager.get("cacheTopicConnection");
  -        //TODO-JAMES - gets here
  -        altrmiFactory.setHostContext(new SynchronousMessengerHostContext(clientMessenger,
"ASubject"), false);
  -        //TODO-JAMES - but not here
  +        clientMessenger = manager.getMessenger("cacheQueueConnection");
  +        altrmiFactory.setHostContext(new SynchronousMessengerHostContext(clientMessenger,
subject), false);
           testClient = (TestInterface) altrmiFactory.lookup("Hello");
   
           // just a kludge for unit testing given we are intrinsically dealing with
  @@ -126,6 +131,7 @@
           server = null;
           testServer = null;
           super.tearDown();
  +        clientMessenger.close();
       }
   
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: cvs-unsubscribe@incubator.apache.org
For additional commands, e-mail: cvs-help@incubator.apache.org


Mime
View raw message