User: weave   
  Date: 02/01/11 12:18:57

  Modified:    src/main/org/jboss/mq/il/oil OILClientIL.java
                        OILClientILService.java OILServerIL.java
                        OILServerILService.java
  Added:       src/main/org/jboss/mq/il/oil OILConstants.java
  Log:
  Created a new "constants" file so that there is only one definition
  of the bytecodes for the object communications.
  
  Reworked the OILServerILService class and defined a new inner class
  that is used to process client transactions. It makes the logic
  in the OILServerILService's run() method easier to follow. The
  server logic is in one run() method, the client processing logic
  is in another run() method encapsulated in the original class.
  
  Also, added 'vim' tag comments at the end of the files so that vim
  will automagically set the appropriate options for editing JBoss
  source files
  
  Will propagate the changes to the UIL files when time permits.
  
  Revision  Changes    Path
  1.6       +7 -13     jbossmq/src/main/org/jboss/mq/il/oil/OILClientIL.java
  
  Index: OILClientIL.java
  ===================================================================
  RCS file: /cvsroot/jboss/jbossmq/src/main/org/jboss/mq/il/oil/OILClientIL.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- OILClientIL.java  2002/01/10 13:38:17     1.5
  +++ OILClientIL.java  2002/01/11 20:18:57     1.6
  @@ -31,20 +31,13 @@
    *
    * @author    Norbert Lataille ([EMAIL PROTECTED])
    * @author    Hiram Chirino ([EMAIL PROTECTED])
  - * @version   $Revision: 1.5 $
  + * @version   $Revision: 1.6 $
    * @created   August 16, 2001
    */
   public final class OILClientIL
      implements ClientIL,
         java.io.Serializable
   {
  -   private final static int DELETE_TEMPORARY_DESTINATION   = 1;
  -   private final static int CLOSE                          = 2;
  -   private final static int RECEIVE                        = 3;
  -   private final static int PONG                           = 4;
  -
  -   private final static int EXCEPTION_CODE                 = 1;
  -
      private final static Logger log = Logger.getLogger(OILClientIL.class);
   
      private InetAddress addr;
  @@ -68,7 +61,7 @@
             throws Exception
      {
         checkSocket();
  -      out.writeByte(CLOSE);
  +      out.writeByte(OILConstants.CLOSE);
         waitAnswer();
         try
         {
  @@ -93,7 +86,7 @@
             throws Exception
      {
         checkSocket();
  -      out.writeByte(DELETE_TEMPORARY_DESTINATION);
  +      out.writeByte(OILConstants.DELETE_TEMPORARY_DESTINATION);
         out.writeObject(dest);
         waitAnswer();
      }
  @@ -108,7 +101,7 @@
             throws Exception
      {
         checkSocket();
  -      out.writeByte(PONG);
  +      out.writeByte(OILConstants.PONG);
         out.writeLong(serverTime);
         waitAnswer();
      }
  @@ -128,7 +121,7 @@
         checkSocket();
         if( trace )
            log.trace("Writing request");
  -      out.writeByte(RECEIVE);
  +      out.writeByte(OILConstants.RECEIVE);
         out.writeInt(messages.length);
         for (int i = 0; i < messages.length; ++i)
         {
  @@ -194,7 +187,7 @@
            int val = in.readByte();
            switch (val)
            {
  -            case EXCEPTION_CODE:
  +            case OILConstants.EXCEPTION:
                  Exception e = (Exception)in.readObject();
                  throwException = new RemoteException("", e);
                  break;
  @@ -211,3 +204,4 @@
         }
      }
   }
  +// vim:expandtab:tabstop=3:shiftwidth=3
  
  
  
  1.7       +9 -13     jbossmq/src/main/org/jboss/mq/il/oil/OILClientILService.java
  
  Index: OILClientILService.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jbossmq/src/main/org/jboss/mq/il/oil/OILClientILService.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- OILClientILService.java   2002/01/10 13:38:17     1.6
  +++ OILClientILService.java   2002/01/11 20:18:57     1.7
  @@ -30,7 +30,7 @@
    *
    * @author    Norbert Lataille ([EMAIL PROTECTED])
    * @author    Hiram Chirino ([EMAIL PROTECTED])
  - * @version   $Revision: 1.6 $
  + * @version   $Revision: 1.7 $
    * @created   August 16, 2001
    */
   public final class OILClientILService
  @@ -39,11 +39,6 @@
   {
      private final static org.jboss.logging.Logger cat = 
org.jboss.logging.Logger.getLogger(OILClientILService.class);
   
  -   private final static int DELETE_TEMPORARY_DESTINATION = 1;
  -   private final static int CLOSE = 2;
  -   private final static int RECEIVE = 3;
  -   private final static int PONG = 4;
  -
      //the client IL
      private OILClientIL clientIL;
   
  @@ -185,7 +180,7 @@
   
               switch (code)
               {
  -               case RECEIVE:
  +               case OILConstants.RECEIVE:
                     int numReceives = in.readInt();
                     org.jboss.mq.ReceiveRequest[] messages = new 
org.jboss.mq.ReceiveRequest[numReceives];
                     for (int i = 0; i < numReceives; ++i)
  @@ -196,15 +191,15 @@
                     connection.asynchDeliver(messages);
                     break;
   
  -               case DELETE_TEMPORARY_DESTINATION:
  +               case OILConstants.DELETE_TEMPORARY_DESTINATION:
                     
connection.asynchDeleteTemporaryDestination((SpyDestination)in.readObject());
                     break;
   
  -               case CLOSE:
  +               case OILConstants.CLOSE:
                     connection.asynchClose();
                     break;
   
  -               case PONG:
  +               case OILConstants.PONG:
                     connection.asynchPong(in.readLong());
                     break;
   
  @@ -213,10 +208,10 @@
               }
   
               //Everthing was OK
  -
  +            //
               try
               {
  -               out.writeByte(0);
  +               out.writeByte(OILConstants.SUCCESS);
                  out.flush();
               }
               catch (IOException e)
  @@ -237,7 +232,7 @@
               try
               {
                  cat.error("Exception handling server request", e);
  -               out.writeByte(1);
  +               out.writeByte(OILConstants.EXCEPTION);
                  out.writeObject(e);
                  out.reset();
                  out.flush();
  @@ -296,3 +291,4 @@
         worker.interrupt();
      }
   }
  +// vim:expandtab:tabstop=3:shiftwidth=3
  
  
  
  1.6       +23 -44    jbossmq/src/main/org/jboss/mq/il/oil/OILServerIL.java
  
  Index: OILServerIL.java
  ===================================================================
  RCS file: /cvsroot/jboss/jbossmq/src/main/org/jboss/mq/il/oil/OILServerIL.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- OILServerIL.java  2002/01/10 13:38:17     1.5
  +++ OILServerIL.java  2002/01/11 20:18:57     1.6
  @@ -37,7 +37,7 @@
    *
    * @author    Hiram Chirino ([EMAIL PROTECTED])
    * @author    Norbert Lataille ([EMAIL PROTECTED])
  - * @version   $Revision: 1.5 $
  + * @version   $Revision: 1.6 $
    * @created   August 16, 2001
    */
   public final class OILServerIL
  @@ -45,27 +45,6 @@
         java.lang.Cloneable,
         org.jboss.mq.il.ServerIL
   {
  -   private final static int ACKNOWLEDGE = 1;
  -   private final static int ADDMESSAGE = 2;
  -   private final static int BROWSE = 3;
  -   private final static int CHECKID = 4;
  -   private final static int CONNECTIONCLOSING = 5;
  -   private final static int CREATEQUEUE = 6;
  -   private final static int CREATETOPIC = 7;
  -   private final static int DELETETEMPORARYDESTINATION = 8;
  -   private final static int GETID = 9;
  -   private final static int GETTEMPORARYQUEUE = 10;
  -   private final static int GETTEMPORARYTOPIC = 11;
  -   private final static int RECEIVE = 13;
  -   private final static int SETENABLED = 14;
  -   private final static int SETSPYDISTRIBUTEDCONNECTION = 15;
  -   private final static int SUBSCRIBE = 16;
  -   private final static int TRANSACT = 17;
  -   private final static int UNSUBSCRIBE = 18;
  -   private final static int DESTROYSUBSCRIPTION = 19;
  -   private final static int CHECKUSER = 20;
  -   private final static int PING = 21;
  -
      /**
       * Description of the Field
       */
  @@ -112,7 +91,7 @@
             throws Exception
      {
         checkConnection();
  -      out.writeByte(SETSPYDISTRIBUTEDCONNECTION);
  +      out.writeByte(OILConstants.SET_SPY_DISTRIBUTED_CONNECTION);
         out.writeObject(dest);
         waitAnswer();
      }
  @@ -129,7 +108,7 @@
             throws JMSException, Exception
      {
         checkConnection();
  -      out.writeByte(SETENABLED);
  +      out.writeByte(OILConstants.SET_ENABLED);
         out.writeBoolean(enabled);
         waitAnswer();
      }
  @@ -144,7 +123,7 @@
             throws Exception
      {
         checkConnection();
  -      out.writeByte(GETID);
  +      out.writeByte(OILConstants.GET_ID);
         return (String)waitAnswer();
      }
   
  @@ -160,7 +139,7 @@
             throws JMSException, Exception
      {
         checkConnection();
  -      out.writeByte(GETTEMPORARYQUEUE);
  +      out.writeByte(OILConstants.GET_TEMPORARY_QUEUE);
         return (TemporaryQueue)waitAnswer();
      }
   
  @@ -176,7 +155,7 @@
             throws JMSException, Exception
      {
         checkConnection();
  -      out.writeByte(GETTEMPORARYTOPIC);
  +      out.writeByte(OILConstants.GET_TEMPORARY_TOPIC);
         return (TemporaryTopic)waitAnswer();
      }
   
  @@ -192,7 +171,7 @@
             throws JMSException, Exception
      {
         checkConnection();
  -      out.writeByte(ACKNOWLEDGE);
  +      out.writeByte(OILConstants.ACKNOWLEDGE);
         item.writeExternal(out);
         waitAnswer();
      }
  @@ -208,7 +187,7 @@
             throws Exception
      {
         checkConnection();
  -      out.writeByte(ADDMESSAGE);
  +      out.writeByte(OILConstants.ADD_MESSAGE);
         SpyMessage.writeMessage(val, out);
         waitAnswer();
      }
  @@ -227,7 +206,7 @@
             throws JMSException, Exception
      {
         checkConnection();
  -      out.writeByte(BROWSE);
  +      out.writeByte(OILConstants.BROWSE);
         out.writeObject(dest);
         out.writeObject(selector);
         return (SpyMessage[])waitAnswer();
  @@ -244,7 +223,7 @@
             throws JMSException, Exception
      {
         checkConnection();
  -      out.writeByte(CHECKID);
  +      out.writeByte(OILConstants.CHECK_ID);
         out.writeObject(ID);
         waitAnswer();
      }
  @@ -262,7 +241,7 @@
             throws JMSException, Exception
      {
         checkConnection();
  -      out.writeByte(CHECKUSER);
  +      out.writeByte(OILConstants.CHECK_USER);
         out.writeObject(userName);
         out.writeObject(password);
         return (String)waitAnswer();
  @@ -304,7 +283,7 @@
             throws JMSException, Exception
      {
         checkConnection();
  -      out.writeByte(CONNECTIONCLOSING);
  +      out.writeByte(OILConstants.CONNECTION_CLOSING);
         waitAnswer();
         destroyConnection();
      }
  @@ -322,7 +301,7 @@
             throws JMSException, Exception
      {
         checkConnection();
  -      out.writeByte(CREATEQUEUE);
  +      out.writeByte(OILConstants.CREATE_QUEUE);
         out.writeObject(dest);
         return (Queue)waitAnswer();
      }
  @@ -340,7 +319,7 @@
             throws JMSException, Exception
      {
         checkConnection();
  -      out.writeByte(CREATETOPIC);
  +      out.writeByte(OILConstants.CREATE_TOPIC);
         out.writeObject(dest);
         return (Topic)waitAnswer();
      }
  @@ -357,7 +336,7 @@
             throws JMSException, Exception
      {
         checkConnection();
  -      out.writeByte(DELETETEMPORARYDESTINATION);
  +      out.writeByte(OILConstants.DELETE_TEMPORARY_DESTINATION);
         out.writeObject(dest);
         waitAnswer();
      }
  @@ -373,7 +352,7 @@
             throws JMSException, Exception
      {
         checkConnection();
  -      out.writeByte(DESTROYSUBSCRIPTION);
  +      out.writeByte(OILConstants.DESTROY_SUBSCRIPTION);
         out.writeObject(id);
         waitAnswer();
      }
  @@ -389,7 +368,7 @@
             throws Exception
      {
         checkConnection();
  -      out.writeByte(PING);
  +      out.writeByte(OILConstants.PING);
         out.writeLong(clientTime);
         waitAnswer();
      }
  @@ -407,7 +386,7 @@
             throws Exception, Exception
      {
         checkConnection();
  -      out.writeByte(RECEIVE);
  +      out.writeByte(OILConstants.RECEIVE);
         out.writeInt(subscriberId);
         out.writeLong(wait);
         return (SpyMessage)waitAnswer();
  @@ -425,7 +404,7 @@
             throws JMSException, Exception
      {
         checkConnection();
  -      out.writeByte(SUBSCRIBE);
  +      out.writeByte(OILConstants.SUBSCRIBE);
         out.writeObject(s);
         waitAnswer();
      }
  @@ -442,7 +421,7 @@
             throws JMSException, Exception
      {
         checkConnection();
  -      out.writeByte(TRANSACT);
  +      out.writeByte(OILConstants.TRANSACT);
         t.writeExternal(out);
         waitAnswer();
      }
  @@ -459,7 +438,7 @@
             throws JMSException, Exception
      {
         checkConnection();
  -      out.writeByte(UNSUBSCRIBE);
  +      out.writeByte(OILConstants.UNSUBSCRIBE);
         out.writeInt(subscriptionId);
         waitAnswer();
      }
  @@ -517,11 +496,11 @@
         out.reset();
         out.flush();
         int val = in.readByte();
  -      if (val == 0)
  +      if (val == OILConstants.SUCCESS)
         {
            return null;
         }
  -      if (val == 1)
  +      if (val == OILConstants.SUCCESS_OBJECT)
         {
            return in.readObject();
         }
  
  
  
  1.16      +369 -231  jbossmq/src/main/org/jboss/mq/il/oil/OILServerILService.java
  
  Index: OILServerILService.java
  ===================================================================
  RCS file: 
/cvsroot/jboss/jbossmq/src/main/org/jboss/mq/il/oil/OILServerILService.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- OILServerILService.java   2002/01/10 13:38:17     1.15
  +++ OILServerILService.java   2002/01/11 20:18:57     1.16
  @@ -48,53 +48,332 @@
    * Implements the ServerILJMXService which is used to manage the JVM IL.
    *
    * @author    Hiram Chirino ([EMAIL PROTECTED])
  - * @version   $Revision: 1.15 $
  + * @version   $Revision: 1.16 $
    */
   public final class OILServerILService
      extends org.jboss.mq.il.ServerILJMXService
      implements java.lang.Runnable,
         OILServerILServiceMBean
   {
  -   //The server implementation
      /**
  -    * Description of the Field
  +    * The default timeout for the server socket. This is
  +    * set so the socket will periodically return to check
  +    * the running flag.
       */
  -   private static JMSServer server;
  +   private final static int SO_TIMEOUT = 5000;
   
  -   private final static int ACKNOWLEDGE = 1;
  -   private final static int ADDMESSAGE = 2;
  -   private final static int BROWSE = 3;
  -   private final static int CHECKID = 4;
  -   private final static int CONNECTIONCLOSING = 5;
  -   private final static int CREATEQUEUE = 6;
  -   private final static int CREATETOPIC = 7;
  -   private final static int DELETETEMPORARYDESTINATION = 8;
  -   private final static int GETID = 9;
  -   private final static int GETTEMPORARYQUEUE = 10;
  -   private final static int GETTEMPORARYTOPIC = 11;
  -   private final static int RECEIVE = 13;
  -   private final static int SETENABLED = 14;
  -   private final static int SETSPYDISTRIBUTEDCONNECTION = 15;
  -   private final static int SUBSCRIBE = 16;
  -   private final static int TRANSACT = 17;
  -   private final static int UNSUBSCRIBE = 18;
  -   private final static int DESTROYSUBSCRIPTION = 19;
  -   private final static int CHECKUSER = 20;
  -   private final static int PING = 21;
  +   /**
  +    * The JMS server where requests are forwarded to.
  +    */
  +   private static JMSServer server;
   
  -   private final static int SO_TIMEOUT = 5000;
      /**
  -    * Description of the Field
  +    * The listening socket that receives incomming connections
  +    * for servicing.
       */
      private ServerSocket serverSocket;
  +
  +   /**
  +    * The managed serverIL.
  +    */
      private OILServerIL serverIL;
   
  +   /**
  +    * The running flag that all worker and server
  +    * threads check to determine if the service should
  +    * be stopped.
  +    */
      private volatile boolean running;
  +
  +   /**
  +    * The server port to bind to.
  +    */
      private int serverBindPort = 0;
  +
  +   /**
  +    * The internet address to bind to by
  +    * default.
  +    */
      private InetAddress bindAddress = null;
  -   private Thread worker;
   
      /**
  +    * This class is used to encapsulate the basic connection and
  +    * work for a connected client thread. The run() method of this
  +    * class processes requests and sends responses to and from a 
  +    * single client. All requests are forwarded to the outer class'
  +    * JMS server instance.
  +    *
  +    * @author Brian Weaver ([EMAIL PROTECTED])
  +    */
  +   private final class Client
  +      implements Runnable
  +   {
  +      /**
  +       * The TCP/IP socket for communications.
  +       */
  +      private Socket sock;
  +
  +      /**
  +       * The object output stream running on top of the
  +       * socket's output stream.
  +       */
  +      private ObjectOutputStream out;
  +
  +      /**
  +       * The objec5t input stream running on top of the
  +       * socket's input stream
  +       */
  +      private ObjectInputStream in;
  +
  +      /**
  +       * Allocates a new runnable instance to process requests from
  +       * the server's client and pass them to the JMS server. The
  +       * passed socket is used for all communications between the 
  +       * service and the client.
  +       *
  +       * @param s The socket used for communications.
  +       *
  +       * @throws java.io.IOException Thrown if an I/O error occurs
  +       *    constructing the object streams.
  +       */
  +      Client(Socket s)
  +         throws IOException
  +      {
  +         this.sock = s;
  +         this.out= new ObjectOutputStream(new 
BufferedOutputStream(this.sock.getOutputStream()));
  +         this.out.flush();
  +         this.in = new ObjectInputStream(new 
BufferedInputStream(this.sock.getInputStream()));
  +      }
  +
  +      /**
  +       * The main threads processing routine. This loop processes
  +       * requests from the server and sends the appropriate responses
  +       * based upon the results.
  +       */
  +      public void run()
  +      {
  +         int code = 0;
  +         boolean closed = false;
  +         ConnectionToken connectionToken = null;
  +
  +         while (!closed && running)
  +         {
  +            try
  +            {
  +               // read in the next request/directive
  +               // from the client
  +               //
  +               code = in.readByte();
  +            }
  +            catch (EOFException e)
  +            {
  +               // end of file, exit processing loop
  +               //
  +               break;
  +            }
  +            catch (IOException e)
  +            {
  +               if(closed || !running)
  +               {
  +                  // exit out of the loop if the connection
  +                  // is closed or the service is shutdown
  +                  //
  +                  break;
  +               }
  +               log.warn("Connection failure (1).", e);
  +               break;
  +            }
  +
  +            // now based upon the input directive, preform the 
  +            // requested action. Any exceptions are processed
  +            // and potentially returned to the client.
  +            //
  +            try
  +            {
  +               Object result = null;
  +
  +               switch (code)
  +               {
  +                  case OILConstants.SET_SPY_DISTRIBUTED_CONNECTION:
  +                     connectionToken = (ConnectionToken)in.readObject();
  +                     break;
  +
  +                  case OILConstants.ACKNOWLEDGE:
  +                     AcknowledgementRequest ack = new AcknowledgementRequest();
  +                     ack.readExternal(in);
  +                     server.acknowledge(connectionToken, ack);
  +                     break;
  +
  +                  case OILConstants.ADD_MESSAGE:
  +                     server.addMessage(connectionToken, SpyMessage.readMessage(in));
  +                     break;
  +
  +                  case OILConstants.BROWSE:
  +                     result = server.browse(connectionToken, 
(Destination)in.readObject(), (String)in.readObject());
  +                     break;
  +
  +                  case OILConstants.CHECK_ID:
  +                     server.checkID((String)in.readObject());
  +                     break;
  +
  +                  case OILConstants.CONNECTION_CLOSING:
  +                     server.connectionClosing(connectionToken);
  +                     closed = true;
  +                     break;
  +
  +                  case OILConstants.CREATE_QUEUE:
  +                     result = (Queue)server.createQueue(connectionToken, 
(String)in.readObject());
  +                     break;
  +
  +                  case OILConstants.CREATE_TOPIC:
  +                     result = (Topic)server.createTopic(connectionToken, 
(String)in.readObject());
  +                     break;
  +
  +                  case OILConstants.DELETE_TEMPORARY_DESTINATION:
  +                     server.deleteTemporaryDestination(connectionToken, 
(SpyDestination)in.readObject());
  +                     break;
  +
  +                  case OILConstants.GET_ID:
  +                     result = server.getID();
  +                     break;
  +
  +                  case OILConstants.GET_TEMPORARY_QUEUE:
  +                     result = 
(TemporaryQueue)server.getTemporaryQueue(connectionToken);
  +                     break;
  +
  +                  case OILConstants.GET_TEMPORARY_TOPIC:
  +                     result = 
(TemporaryTopic)server.getTemporaryTopic(connectionToken);
  +                     break;
  +
  +                  case OILConstants.RECEIVE:
  +                     result = server.receive(connectionToken, in.readInt(), 
in.readLong());
  +                     break;
  +
  +                  case OILConstants.SET_ENABLED:
  +                     server.setEnabled(connectionToken, in.readBoolean());
  +                     break;
  +
  +                  case OILConstants.SUBSCRIBE:
  +                     server.subscribe(connectionToken, 
(Subscription)in.readObject());
  +                     break;
  +
  +                  case OILConstants.TRANSACT:
  +                     TransactionRequest trans = new TransactionRequest();
  +                     trans.readExternal(in);
  +                     server.transact(connectionToken, trans);
  +                     break;
  +
  +                  case OILConstants.UNSUBSCRIBE:
  +                     server.unsubscribe(connectionToken, in.readInt());
  +                     break;
  +
  +                  case OILConstants.DESTROY_SUBSCRIPTION:
  +                     
server.destroySubscription((DurableSubcriptionID)in.readObject());
  +                     break;
  +
  +                  case OILConstants.CHECK_USER:
  +                     result = server.checkUser((String)in.readObject(), 
(String)in.readObject());
  +                     break;
  +
  +                  case OILConstants.PING:
  +                     server.ping(connectionToken, in.readLong());
  +                     break;
  +
  +                  default:
  +                     throw new RemoteException("Bad method code !");
  +               }
  +
  +               //Everthing was OK, otherwise
  +               //an exception would have prevented us from getting
  +               //to this point in the code ;-)
  +               //
  +               try
  +               {
  +                  if (result == null)
  +                  {
  +                     out.writeByte(OILConstants.SUCCESS);
  +                  }
  +                  else
  +                  {
  +                     out.writeByte(OILConstants.SUCCESS_OBJECT);
  +                     out.writeObject(result);
  +                     out.reset();
  +                  }
  +                  out.flush();
  +               }
  +               catch (IOException e)
  +               {
  +                  if(closed)
  +                     break;
  +
  +                  log.warn("Connection failure (2).", e);
  +                  break;
  +               }
  +
  +            }
  +            catch (Exception e)
  +            {
  +               // this processes any exceptions from the actually switch
  +               // statement processing
  +               //
  +               if (closed)
  +                  break;
  +
  +               log.info("Client request resulted in a server exception: ", e);
  +
  +               try
  +               {
  +                  out.writeByte(OILConstants.EXCEPTION);
  +                  out.writeObject(e);
  +                  out.reset();
  +                  out.flush();
  +               }
  +               catch (IOException e2)
  +               {
  +                  if (closed)
  +                     break;
  +
  +                  log.warn("Connection failure (3).", e);
  +                  break;
  +               }
  +            } // end catch of try { switch(code) ... }
  +         } // end whlie loop
  +
  +         try
  +         {
  +            if(!closed)
  +            {
  +               try
  +               {
  +                  server.connectionClosing(connectionToken);
  +               }
  +               catch (JMSException e)
  +               {
  +                  // do nothing
  +               }
  +            }
  +            in.close();
  +            out.close();
  +         }
  +         catch (IOException e)
  +         {
  +            log.warn("Connection failure during connection close.", e);
  +         }
  +         finally
  +         {
  +            try
  +            {
  +               sock.close();
  +            }
  +            catch(IOException e)
  +            {
  +               log.warn("Connection failure during connection close.", e);
  +            }
  +         }
  +      } // end run method
  +   }
  +
  +   /**
       * Used to construct the GenericConnectionFactory (bindJNDIReferences()
       * builds it) Sets up the connection properties need by a client to use this
       * IL
  @@ -135,48 +414,54 @@
       */
      public void run()
      {
  -
  -      Socket socket = null;
  -      int code = 0;
  -      ObjectOutputStream out = null;
  -      ObjectInputStream in = null;
  -      ConnectionToken connectionToken = null;
  -      boolean closed = false;
  -
         try
         {
  -         while (running && socket == null)
  +         while (running)
            {
  +            Socket socket = null;
               try
               {
                  socket = serverSocket.accept();
               }
               catch (java.io.InterruptedIOException e)
               {
  -               // do nothing!
  +               continue;
               }
  -         }
   
  -         if (!running)
  -         {
  +            // it's possible that the service is no longer
  +            // running but it got a connection, no point in
  +            // starting up a thread!
  +            //
  +            if (!running)
  +            {
  +               if(socket != null)
  +               {
  +                  try
  +                  {
  +                     socket.close();
  +                  }
  +                  catch(Exception e)
  +                  {
  +                     // do nothing
  +                  }
  +               }
  +               return;
  +            }
  +
               try
               {
  -               serverSocket.close();
  +               socket.setSoTimeout(0);
  +               new Thread(new Client(socket), "OIL Worker").start();
               }
  -            catch(Exception e)
  +            catch(IOException ie)
               {
  -               log.debug("error closing server socket", e);
  +               if(log.isDebugEnabled())
  +               {
  +                  log.debug("IOException processing client connection", ie);
  +                  log.debug("Dropping client connection, server will not 
terminate");
  +               }
               }
  -            return;
            }
  -
  -         socket.setSoTimeout(0);
  -         new Thread(this, "OIL Worker").start();
  -
  -         out = new ObjectOutputStream(new 
BufferedOutputStream(socket.getOutputStream()));
  -         out.flush();
  -         in = new ObjectInputStream(new 
BufferedInputStream(socket.getInputStream()));
  -
         }
         catch (SocketException e)
         {
  @@ -185,188 +470,23 @@
            // reset by peer. In this case, it's okay to ignore both
            // SocketException and IOException.
            log.warn("SocketException occured (Connection reset by peer?). Cannot 
initialize the OILServerILService.");
  -         return;
         }
         catch (IOException e)
         {
            log.warn("IOException occured. Cannot initialize the OILServerILService.");
  -         return;
         }
  -
  -      while (!closed && running)
  +      finally
         {
  -
            try
            {
  -            code = in.readByte();
  +            serverSocket.close();
            }
  -         catch (EOFException e)
  -         {
  -            break;
  -         }
  -         catch (IOException e)
  +         catch(Exception e)
            {
  -            if (closed || !running)
  -            {
  -               break;
  -            }
  -            log.warn("Connection failure (1).", e);
  -            break;
  +            log.debug("error closing server socket", e);
            }
  -
  -         try
  -         {
  -
  -            Object result = null;
  -
  -            switch (code)
  -            {
  -               case SETSPYDISTRIBUTEDCONNECTION:
  -                  connectionToken = (ConnectionToken)in.readObject();
  -                  log.debug("The OILClientIL Connection is set up");
  -                  break;
  -               case ACKNOWLEDGE:
  -                  AcknowledgementRequest ack = new AcknowledgementRequest();
  -                  ack.readExternal(in);
  -                  server.acknowledge(connectionToken, ack);
  -                  break;
  -               case ADDMESSAGE:
  -                  server.addMessage(connectionToken, SpyMessage.readMessage(in));
  -                  break;
  -               case BROWSE:
  -                  result = server.browse(connectionToken, 
(Destination)in.readObject(), (String)in.readObject());
  -                  break;
  -               case CHECKID:
  -                  server.checkID((String)in.readObject());
  -                  break;
  -               case CONNECTIONCLOSING:
  -                  server.connectionClosing(connectionToken);
  -                  closed = true;
  -                  break;
  -               case CREATEQUEUE:
  -                  result = (Queue)server.createQueue(connectionToken, 
(String)in.readObject());
  -                  break;
  -               case CREATETOPIC:
  -                  result = (Topic)server.createTopic(connectionToken, 
(String)in.readObject());
  -                  break;
  -               case DELETETEMPORARYDESTINATION:
  -                  server.deleteTemporaryDestination(connectionToken, 
(SpyDestination)in.readObject());
  -                  break;
  -               case GETID:
  -                  result = server.getID();
  -                  break;
  -               case GETTEMPORARYQUEUE:
  -                  result = 
(TemporaryQueue)server.getTemporaryQueue(connectionToken);
  -                  break;
  -               case GETTEMPORARYTOPIC:
  -                  result = 
(TemporaryTopic)server.getTemporaryTopic(connectionToken);
  -                  break;
  -               case RECEIVE:
  -                  result = server.receive(connectionToken, in.readInt(), 
in.readLong());
  -                  break;
  -               case SETENABLED:
  -                  server.setEnabled(connectionToken, in.readBoolean());
  -                  break;
  -               case SUBSCRIBE:
  -                  server.subscribe(connectionToken, (Subscription)in.readObject());
  -                  break;
  -               case TRANSACT:
  -                  TransactionRequest trans = new TransactionRequest();
  -                  trans.readExternal(in);
  -                  server.transact(connectionToken, trans);
  -                  break;
  -               case UNSUBSCRIBE:
  -                  server.unsubscribe(connectionToken, in.readInt());
  -                  break;
  -               case DESTROYSUBSCRIPTION:
  -                  server.destroySubscription((DurableSubcriptionID)in.readObject());
  -                  break;
  -               case CHECKUSER:
  -                  result = server.checkUser((String)in.readObject(), 
(String)in.readObject());
  -                  break;
  -               case PING:
  -                  server.ping(connectionToken, in.readLong());
  -                  break;
  -               default:
  -                  throw new RemoteException("Bad method code !");
  -            }
  -
  -            //Everthing was OK
  -
  -            try
  -            {
  -               if (result == null)
  -               {
  -                  out.writeByte(0);
  -               }
  -               else
  -               {
  -                  out.writeByte(1);
  -                  out.writeObject(result);
  -                  out.reset();
  -               }
  -               out.flush();
  -            }
  -            catch (IOException e)
  -            {
  -               if (closed)
  -               {
  -                  break;
  -               }
  -
  -               log.warn("Connection failure (2).", e);
  -               break;
  -            }
  -
  -         }
  -         catch (Exception e)
  -         {
  -            if (closed)
  -            {
  -               break;
  -            }
  -
  -            log.info("Client request resulted in a server exception: ", e);
  -
  -            try
  -            {
  -               out.writeByte(2);
  -               out.writeObject(e);
  -               out.reset();
  -               out.flush();
  -            }
  -            catch (IOException e2)
  -            {
  -               if (closed)
  -               {
  -                  break;
  -               }
  -
  -               log.warn("Connection failure (3).", e);
  -               break;
  -            }
  -         }
  -      }
  -
  -      try
  -      {
  -         if (!closed)
  -         {
  -            try
  -            {
  -               server.connectionClosing(connectionToken);
  -            }
  -            catch (JMSException e)
  -            {
  -            }
  -         }
  -         socket.close();
  -      }
  -      catch (IOException e)
  -      {
  -         log.warn("Connection failure during connection close.", e);
  +         return;
         }
  -
      }
   
      /**
  @@ -385,9 +505,10 @@
         serverSocket.setSoTimeout(SO_TIMEOUT);
   
         InetAddress socketAddress = serverSocket.getInetAddress();
  -      log.info("JBossMQ OIL service available at : " + socketAddress + ":" + 
serverSocket.getLocalPort());
  -      worker = new Thread(server.threadGroup, this, "OIL Worker");
  -      worker.start();
  +      if(log.isInfoEnabled())
  +         log.info("JBossMQ OIL service available at : " + socketAddress + ":" + 
serverSocket.getLocalPort());
  +
  +      new Thread(server.threadGroup, this, "OIL Worker Server").start();
   
         /* We need to check the socketAddress against "0.0.0.0/0.0.0.0"
            because this is not a valid address on Win32 while it is for
  @@ -402,7 +523,7 @@
      }
   
      /**
  -    * Stops this IL, and unbinds it from JNDI
  +    * Stops this IL, and unbinds it from JNDI.
       */
      public void stopService()
      {
  @@ -413,11 +534,13 @@
         }
         catch (Exception e)
         {
  -         e.printStackTrace();
  +         log.error("Exception unbinding from JNDI", e);
         }
      }
      
  -   /** Getter for property serverBindPort.
  +   /**
  +    * Getter for property serverBindPort.
  +    *
       * @return Value of property serverBindPort.
       */
      public int getServerBindPort()
  @@ -425,7 +548,9 @@
         return serverBindPort;
      }
      
  -   /** Setter for property serverBindPort.
  +   /**
  +    * Setter for property serverBindPort.
  +    *
       * @param serverBindPort New value of property serverBindPort.
       */
      public void setServerBindPort(int serverBindPort)
  @@ -433,7 +558,12 @@
         this.serverBindPort = serverBindPort;
      }
   
  -   /** Get the interface address the OIL server bind its listening port on */
  +   /**
  +    * Get the interface address the OIL server bind its listening port on.
  +    *
  +    * @return The hostname or dotted decimal address that the service is
  +    *    bound to.
  +    */
      public String getBindAddress()
      {
         String addr = "0.0.0.0";
  @@ -441,7 +571,14 @@
            addr = bindAddress.getHostName();
         return addr;
      }
  -   /** Set the interface address the OIL server bind its listening port on */
  +   /**
  +    * Set the interface address the OIL server bind its listening port on.
  +    *
  +    * @param host The host address to bind to, if any.
  +    *
  +    * @throws java.net.UnknownHostException Thrown if the hostname cannot
  +    *    be resolved to an InetAddress object.
  +    */
      public void setBindAddress(String host) throws UnknownHostException
      {
         // If host is null or empty use any address
  @@ -451,3 +588,4 @@
            bindAddress = InetAddress.getByName(host);
      }   
   }
  +// vim:expandtab:tabstop=3:shiftwidth=3
  
  
  
  1.1                  jbossmq/src/main/org/jboss/mq/il/oil/OILConstants.java
  
  Index: OILConstants.java
  ===================================================================
  /*
   * JBoss, the OpenSource J2EE webOS
   *
   * Distributable under LGPL license.
   * See terms of license at gnu.org.
   */
  package org.jboss.mq.il.oil;
  
  /**
   * 
   *
   * @author    Brian Weaver ([EMAIL PROTECTED])
   * @version   $Revision: 1.1 $
   * @created   January 10, 2002
   */
  final class OILConstants
  {
     // Success and error conditions are 
     // defined here
     //
     final static int OK                             = 0;
     final static int SUCCESS                        = 0;
     final static int OK_OBJECT                      = 1;
     final static int SUCCESS_OBJECT                 = 1;
     final static int EXCEPTION                      = 2;
  
     // The "message" codes start here.
     //
     final static int ACKNOWLEDGE                    = 8;
     final static int ADD_MESSAGE                    = 9;
     final static int BROWSE                         = 10;
     final static int CHECK_ID                       = 11;
     final static int CONNECTION_CLOSING             = 12;
     final static int CREATE_QUEUE                   = 13;
     final static int CREATE_TOPIC                   = 14;
     final static int DELETE_TEMPORARY_DESTINATION   = 15;
     final static int GET_ID                         = 16;
     final static int GET_TEMPORARY_QUEUE            = 17;
     final static int GET_TEMPORARY_TOPIC            = 18;
     final static int RECEIVE                        = 19;
     final static int SET_ENABLED                    = 20;
     final static int SET_SPY_DISTRIBUTED_CONNECTION = 21;
     final static int SUBSCRIBE                      = 22;
     final static int TRANSACT                       = 23;
     final static int UNSUBSCRIBE                    = 24;
     final static int DESTROY_SUBSCRIPTION           = 25;
     final static int CHECK_USER                     = 26;
     final static int PING                           = 27;
     final static int PONG                           = 28;
     final static int CLOSE                          = 29;
  }
  /*
  vim:tabstop=3:expandtab:shiftwidth=3
  */
  
  
  

_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development

Reply via email to