User: hiram   
  Date: 00/11/16 14:46:21

  Added:       src/java/org/spydermq/distributed/server
                        ConnectionReceiverUIL.java
                        ConnectionReceiverUILClient.java
                        DistributedJMSServerUIL.java
                        DistributedJMSServerUILClient.java
                        DistributedJMSServerUILMBean.java
  Log:
  These classes work almost exactly like thier OIL counterparts
  except the the JMSServer and ConnectionReciver share the
  same Socket for communications.  This allows us to connect
  to a server from a client that is behind a firewall
  
  Revision  Changes    Path
  1.1                  
spyderMQ/src/java/org/spydermq/distributed/server/ConnectionReceiverUIL.java
  
  Index: ConnectionReceiverUIL.java
  ===================================================================
  /*
   * spyderMQ, the OpenSource JMS implementation
   *
   * Distributable under GPL license.
   * See terms of license at gnu.org.
   */
  package org.spydermq.distributed.server;
  
  import javax.jms.Destination;
  import javax.jms.JMSException;
  import org.spydermq.SpyConnection;
  import org.spydermq.ConnectionQueue;
  import org.spydermq.SpyMessage;
  import org.spydermq.SpySession;
  import org.spydermq.SessionQueue;
  import org.spydermq.SpyDestination;
  import org.spydermq.SpyTopicConnection;
  import org.spydermq.SpyQueueSession;
  import org.spydermq.Log;
  import org.spydermq.NoReceiverException;
  import org.spydermq.distributed.interfaces.ConnectionReceiver;
  import org.spydermq.distributed.interfaces.ConnectionReceiverSetup;
  import java.util.Hashtable;
  import java.util.HashSet;
  import java.util.Iterator;
  import java.rmi.RemoteException; 
  import java.net.ServerSocket;
  import java.net.Socket;
  import java.net.InetAddress;
  import java.io.InputStream;
  import java.io.OutputStream;
  import java.io.BufferedOutputStream;
  import java.io.BufferedInputStream;
  import java.io.ObjectInputStream;
  import java.io.ObjectOutputStream;
  import java.io.IOException;
  
  /**
   *    The OIL implementation of the ConnectionReceiver object
   *      
   *    @author Norbert Lataille ([EMAIL PROTECTED])
   *    @author Hiram Chirino ([EMAIL PROTECTED])
   * 
   *    @version $Revision: 1.1 $
   */
  public class ConnectionReceiverUIL 
        implements Runnable, ConnectionReceiverSetup
  {
        // Attributes ----------------------------------------------------
  
        //A link on my connection
        private SpyConnection connection;
        //Is my connection closed ?
        private boolean closed;
  
        // Constructor ---------------------------------------------------
           
        public ConnectionReceiverUIL() 
        {
                closed=false;
        }
  
        // Internals -----------------------------------------------------
        
        static final int RECEIVE = 1;
        static final int RECEIVE_MULTIPLE = 2;
        static final int DELETE_TEMPORARY_DESTINATION = 3;
        static final int CLOSE = 4;             
        
  
  
        void exportObject()     
        {                       
                 new Thread(this).start();
        }
        
        public void run()
        {
                Socket socket = null;
                int code = 0;
  
                ObjectOutputStream out=null;
                ObjectInputStream in=null;
                      
                try {
                        DistributedJMSServerUILClient uilClient = 
(DistributedJMSServerUILClient)connection.getProvider();
  
                        out = new ObjectOutputStream(new 
BufferedOutputStream(uilClient.mSocket.getOutputStream(2)));
                        out.flush();
                        in = new ObjectInputStream(new 
BufferedInputStream(uilClient.mSocket.getInputStream(2)));
                        
                } catch (IOException e) {
                        failure("Initialisation",e);
                        return;
                }
  
                while (true) {
  
                        try {
                                code=in.read();
                        } catch (IOException e) {
                                failure("Command read",e);
                                e.printStackTrace();
                                return;
                        }
                
                        try {
  
                                
                                switch (code)
                                {
                                        case RECEIVE: 
                                                
receive((SpyDestination)in.readObject(),(SpyMessage)in.readObject());
                                                break;
                                        case RECEIVE_MULTIPLE: 
                                                SpyDestination 
dest=(SpyDestination)in.readObject();
                                                int nb=in.readInt();
                                                receiveMultiple(dest,nb,in);
                                                break;
                                        case DELETE_TEMPORARY_DESTINATION:
                                                
deleteTemporaryDestination((SpyDestination)in.readObject());
                                                break;
                                        case CLOSE: 
                                                 close();
                                                break;
                                        default:
                                                throw new RemoteException("Bad method 
code !");
                                }
                                
                                //Everthing was OK
                                
                                try {
                                        out.write(0);
                                        out.flush();
                                } catch (IOException e) {
                                        failure("Result write",e);
                                        return;                                 
                                }
                                
                                } catch (Exception e) {
  
                                try {
                                        if( e instanceof NoReceiverException ) {
                                                out.write(2);
                                                out.writeObject(e.getMessage());
                                        } else {
                                                out.write(1);
                                                out.writeObject(e);
                                        }
                                        out.flush();
                                } catch (IOException e2) {
                                        failure("Result write",e2);
                                        return;                                 
                                }
                                
                        }
  
                }
        }
        
        void failure(String st,Exception e)
        {
                Log.error("Closing socket: "+st);
                Log.error(e);
        }
        
        // Public --------------------------------------------------------      
  
        public void setConnection(SpyConnection connection)
        {
                boolean export = this.connection==null;
                this.connection=connection;
                if( export )
                        exportObject();
        }
        
        public ConnectionReceiver createClient() throws Exception
        {               
                return new ConnectionReceiverUILClient();
        }
        
        // ---
        
        //<DEBUG>
        
        /*public void receive(SpyDestination dest,SpyMessage mes) throws JMSException
        {
                connection.rec++;
        }
        
        public void receiveMultiple(SpyDestination dest,SpyMessage mes[]) throws 
JMSException
        {
                connection.rec++;
        }*/
        
        //</DEBUG>
        
        
        //A message has arrived for this Connection, We have to dispatch it to the 
sessions
        public void receive(SpyDestination dest,SpyMessage mes) throws JMSException
        {               
                if (closed) throw new IllegalStateException("The connection is 
closed");
                
                Log.log("ConnectionReceiver: 
Receive(Destination="+dest.toString()+",Mes="+mes.toString()+")");
                
                if (connection instanceof SpyTopicConnection) {
                
                        //Get the set of subscribers for this Topic
                
                        ConnectionQueue 
connectionQueue=(ConnectionQueue)connection.destinations.get(dest);             
                        if (connectionQueue==null) return;
        
                        Iterator i=connectionQueue.subscribers.iterator();
                                        
                        while (i.hasNext()) {                                          
                 
                                        
                                SpySession session=(SpySession)i.next();
                                        
                                //add the new message to the session's queue
                                session.dispatchMessage(dest,mes);
                                        
                                //There is work to do... 
                                session.mutex.notifyLock();
                        }
                } else {
                        
                        while (true) {
                                
                                SessionQueue sq=null;
  
                                try {
                        
                                        //Find one session waiting for this Queue
                                        if (connection.modeStop) throw new 
Exception("This connection is stopped !");
                                        ConnectionQueue 
connectionQueue=(ConnectionQueue)connection.destinations.get(dest);
                                        if (connectionQueue==null) throw new 
Exception("There is no connectionQueue for this destination !");
                                        
                                        synchronized (connectionQueue) {
                                                
                                                //Find a SessionQueue
                                                if 
(connectionQueue.NumListeningSessions==0) throw new NoReceiverException("There are no 
listening sessions for this destination !");
                        
                                                Iterator 
i=connectionQueue.subscribers.iterator();
                                                while (i.hasNext()) {
                                                        SpySession 
session=(SpySession)i.next();
                                                        
sq=(SessionQueue)session.destinations.get(dest);
                                                        if 
(sq.NumListeningSubscribers!=0) break;
                                                }
                                                if 
(sq==null||sq.NumListeningSubscribers==0) {
                                                        Log.error("FIXME: The 
listeners count was invalid !");
                                                        throw new 
NoReceiverException("There are no listening sessions for this destination !");
                                                }
                                        
                                                //Try with this sessionQueue
                                                Log.log("Dispatching to SessionQueue: 
"+mes);
                                                sq.dispatchMessage(dest,mes);
                                
                                                //Our work is done here
                                                break;
                                        }
  
                                } catch (NoReceiverException e) {
                                        //This SessionQueue should not have been 
registered !
                                        throw e;
                                } catch (Exception e) {
                                        //This error is non-recoverable : we must 
unregister from this queue
                                        //Let the JMSServerQueue do its work
                                        Log.log(e);
                                        throw new JMSException("There are no listening 
sessions in this connection");
                                }
                        }
                        
                }
                        
        } 
  
        public void receiveMultiple(SpyDestination dest,int nb,ObjectInputStream in) 
throws Exception
        {               
                if (closed) throw new IllegalStateException("The connection is 
closed");
                
                Log.log("ConnectionReceiver: ReceiveMultiple()");
                
                if (connection instanceof SpyTopicConnection) {
                
                        //Get the set of subscribers for this Topic
                
                        ConnectionQueue 
connectionQueue=(ConnectionQueue)connection.destinations.get(dest);             
                        if (connectionQueue==null) return;
        
                        for(int val=0;val<nb;val++) {
                        
                                SpyMessage mes=(SpyMessage)in.readObject();
                                
                                //NL: i is a short-lived object. Try to "group" 
messages in an pre-allocated/peristant
                                //array and apply the same iterator on this array
                                Iterator i=connectionQueue.subscribers.iterator();
                                        
                                while (i.hasNext()) {                                  
                         
                                
                                        SpySession session=(SpySession)i.next();
                                        
                                        //add the new message to the session's queue
                                        session.dispatchMessage(dest,mes);
                                
                                        //There is work to do... 
                                        session.mutex.notifyLock();
                                }
                        }
                        
                } else {
                        throw new Exception("Multiple dispatch for a Queue");          
         
                }
        } 
        
        
        public void close() throws Exception
        {
                closed=true;            
        }
  
        //One TemporaryDestination has been deleted
        public void deleteTemporaryDestination(SpyDestination dest) throws JMSException
        {
                if (closed) throw new IllegalStateException("The connection is 
closed");        
  
                connection.deleteTemporaryDestination(dest);
        }
  
  }
  
  
  
  1.1                  
spyderMQ/src/java/org/spydermq/distributed/server/ConnectionReceiverUILClient.java
  
  Index: ConnectionReceiverUILClient.java
  ===================================================================
  /*
   * spyderMQ, the OpenSource JMS implementation
   *
   * Distributable under GPL license.
   * See terms of license at gnu.org.
   */
  package org.spydermq.distributed.server;
  
  import org.spydermq.distributed.interfaces.ConnectionReceiver;
  import org.spydermq.SpyDestination;
  import org.spydermq.SpyMessage;
  import org.spydermq.Log;
  import org.spydermq.SpyConnection;
  import java.rmi.RemoteException;
  import java.io.ObjectOutputStream;
  import java.io.ObjectInputStream;
  import java.io.InputStream;
  import java.io.BufferedInputStream;
  import java.io.OutputStream;
  import java.io.BufferedOutputStream;
  import java.io.IOException;
  import java.io.Serializable;
  import java.net.Socket;
  import java.net.InetAddress;
  import java.net.SocketException;
  
  /**
   *    The OIL implementation of the ConnectionReceiver object
   *      
   *    @author Norbert Lataille ([EMAIL PROTECTED])
   *    @author Hiram Chirino ([EMAIL PROTECTED])
   * 
   *    @version $Revision: 1.1 $
   */
  import org.spydermq.multiplexor.SocketMultiplexor;public class 
ConnectionReceiverUILClient
        implements ConnectionReceiver, Serializable
  {
        static final int RECEIVE = 1;
        static final int RECEIVE_MULTIPLE = 2;
        static final int DELETE_TEMPORARY_DESTINATION = 3;
        static final int CLOSE = 4;             
        
  
  
  
        private transient ObjectOutputStream out;
        private transient ObjectInputStream in;
        
  
  
        
  
        
        void createConnection() throws RemoteException
        {
                try {
                        in=new ObjectInputStream(new 
BufferedInputStream(mSocket.getInputStream(2)));
                        out=new ObjectOutputStream(new 
BufferedOutputStream(mSocket.getOutputStream(2)));
                        out.flush();
                } catch (Exception e) {                 
                        Log.error(e);
                        throw new RemoteException("Cannot connect to the 
ConnectionReceiver/Server");
                }
        }
        
        public void waitAnswer() throws Exception
        {
                Exception throwException=null;
                try {
                        out.flush();
                        int val=in.read();
                        switch(val) {
                        case 1:                         
                                Exception e=(Exception)in.readObject();
                                throwException = new RemoteException("", e);
                                break;
                        case 2:
                                String st=(String)in.readObject();
                                throwException = new 
org.spydermq.NoReceiverException(st);
                        }
                } catch (IOException e) {            
                        Log.notice("IOException while reading the answer");
                        Log.notice(e);
                        throw new RemoteException("Cannot contact the remote object");
                }
                
                if( throwException != null )
                        throw throwException;
        }
  
        public void receive(SpyDestination dest,SpyMessage mes) throws Exception
        {               
                if (out==null) createConnection();
                out.write(RECEIVE);
                out.writeObject(dest);
                out.writeObject(mes);
                waitAnswer();
        }
                
        public void receiveMultiple(SpyDestination dest,SpyMessage mes[]) throws 
Exception      
        {
                if (out==null) createConnection();
                out.write(RECEIVE_MULTIPLE);
                out.writeObject(dest);
                out.writeInt(mes.length);
                for(int i=0;i<mes.length;i++)
                        out.writeObject(mes[i]);
                waitAnswer();
        }       
        
        public void deleteTemporaryDestination(SpyDestination dest) throws Exception
        {
                if (out==null) createConnection();
                out.write(DELETE_TEMPORARY_DESTINATION);
                out.writeObject(dest);
                waitAnswer();
        }       
        
        public void close() throws Exception
        {
                if (out==null) createConnection();
                out.write(CLOSE);
                waitAnswer();
        }
        
        transient SocketMultiplexor mSocket;    public ConnectionReceiverUILClient()
        {
        }}
  
  
  
  1.1                  
spyderMQ/src/java/org/spydermq/distributed/server/DistributedJMSServerUIL.java
  
  Index: DistributedJMSServerUIL.java
  ===================================================================
  /*
   * spyderMQ, the OpenSource JMS implementation
   *
   * Distributable under GPL license.
   * See terms of license at gnu.org.
   */
  package org.spydermq.distributed.server;
  
  import javax.jms.JMSException;
  import javax.jms.Destination;
  import javax.jms.Topic;
  import javax.jms.Queue;
  import javax.jms.TemporaryTopic;
  import javax.jms.TemporaryQueue;
  import org.spydermq.SpyMessage;
  import org.spydermq.JMSServerQueue;
  import org.spydermq.SpyDestination;
  import org.spydermq.JMSServer;
  import org.spydermq.SpyDistributedConnection;
  import org.spydermq.Log;
  import org.spydermq.distributed.interfaces.DistributedJMSServer;
  import org.spydermq.distributed.interfaces.DistributedJMSServerSetup;
  import java.rmi.RemoteException; 
  import java.net.ServerSocket;
  import java.net.Socket;
  import java.net.InetAddress;
  import java.io.ObjectOutputStream;
  import java.io.BufferedOutputStream;
  import java.io.ObjectInputStream;
  import java.io.BufferedInputStream;
  import java.io.IOException;
  
  /**
   *    The OIL implementation of the DistributedJMSServer object
   *      
   *    @author Norbert Lataille ([EMAIL PROTECTED])
   *    @author Hiram Chirino ([EMAIL PROTECTED])
   * 
   *    @version $Revision: 1.1 $
   */
  import org.spydermq.multiplexor.SocketMultiplexor;public class 
DistributedJMSServerUIL
        implements Runnable, DistributedJMSServerSetup, DistributedJMSServerUILMBean
  {
  
        // Attributes ----------------------------------------------------
  
        //The server implementation
        private static JMSServer server;
        
        // Constructor ---------------------------------------------------
        
        public DistributedJMSServerUIL() 
        {
                exportObject();
        }
  
        // Internals -----------------------------------------------------
        
        static final int GetID = 1;
        static final int NewMessage = 2;
        static final int Subscribe = 3;
        static final int Unsubscribe = 4;
        static final int CreateTopic = 5;
        static final int CreateQueue = 6;
        static final int GetTemporaryTopic = 7;
        static final int GetTemporaryQueue = 8;
        static final int ConnectionClosing = 9;
        static final int DeleteTemporaryDestination = 10;
        static final int CheckID = 11;
        static final int QueueReceiveNoWait = 12;
        static final int ConnectionListening = 13;
        
        private ServerSocket serverSocket;
  
        void exportObject()     
        {
                try {
                         serverSocket = new ServerSocket(0);
                         new Thread(this).start();
                } catch (IOException e) {
                        failure("Initialization",e);
                }
        }
        
        public void run()
        {
                Socket socket = null;
                SocketMultiplexor mSocket = null;
                int code = 0;
                ObjectOutputStream out=null;
                ObjectInputStream in=null;
                      
                try {
                        socket = serverSocket.accept();
                        new Thread(this).start();
  
                        Log.log("SeverUIL initializing");
  
                mSocket = new SocketMultiplexor(socket);                
  
                        out = new ObjectOutputStream(new 
BufferedOutputStream(mSocket.getOutputStream(1)));
                        out.flush();
                        
                        in = new ObjectInputStream(new 
BufferedInputStream(mSocket.getInputStream(1)));
  
                        Log.log("SeverUIL initialized");
  
                } catch (IOException e) {
                        failure("Initialisation",e);
                        return;
                }
  
                
                while (true) {
  
                        try {
                                code=in.read();         
                        } catch (IOException e) {
                                Log.notice("Command read");
                                Log.notice(e);
                                return;
                        }
                
                        try {
                                
                                Object result=null;                                    
 
                                
                                switch (code)
                                {
                                        case GetID: 
                                                result=server.getID();
                                                break;
                                        case NewMessage:                               
                 
                                                
newMessage((String)in.readObject(),in.readInt(),in);
                                                break;
                                        case Subscribe:
                                                Destination d = 
(Destination)in.readObject();
                                                SpyDistributedConnection c = 
(SpyDistributedConnection)in.readObject();
                                                if( c.cr instanceof 
ConnectionReceiverUILClient ) 
                                                        
((ConnectionReceiverUILClient)c.cr).mSocket = mSocket;
                                                server.subscribe(d,c);
                                                break;
                                        case Unsubscribe: 
                                                
server.unsubscribe((Destination)in.readObject(),(SpyDistributedConnection)in.readObject());
                                                break;
                                        case CreateTopic: 
                                                
result=(Topic)server.createTopic((String)in.readObject());
                                                break;
                                        case CreateQueue: 
                                                
result=(Queue)server.createQueue((String)in.readObject());
                                                break;
                                        case GetTemporaryTopic:
                                                
result=(TemporaryTopic)server.getTemporaryTopic((SpyDistributedConnection)in.readObject());
                                                break;
                                        case GetTemporaryQueue: 
                                                
result=(TemporaryQueue)server.getTemporaryQueue((SpyDistributedConnection)in.readObject());
                                                break;
                                        case ConnectionClosing: 
                                                
server.connectionClosing((SpyDistributedConnection)in.readObject(),null);
                                                break;
                                        case DeleteTemporaryDestination: 
                                                
server.deleteTemporaryDestination((SpyDestination)in.readObject());
                                                break;
                                        case CheckID: 
                                                
server.checkID((String)in.readObject());
                                                break;
                                        case QueueReceiveNoWait:
                                                
result=server.queueReceiveNoWait((Queue)in.readObject());
                                                break;
                                        case ConnectionListening: 
                                                
server.connectionListening(((in.read())==1),(Destination)in.readObject(),(SpyDistributedConnection)in.readObject());
                                                break;
                                        default:
                                                throw new RemoteException("Bad method 
code !");
                                }
                                
                                //Everthing was OK
                                
                                try {
                                        if (result==null) out.write(0);
                                        else {
                                                out.write(1);
                                                out.writeObject(result);
                                        }
                                        out.flush();
                                } catch (IOException e) {
                                        failure("Result write",e);
                                        return;                                 
                                }
                                
                        } catch (Exception e) {
  
                                try {
                                        out.write(2);
                                        out.writeObject(e);
                                        out.flush();
                                } catch (IOException e2) {
                                        failure("Result write",e2);
                                        return;                                 
                                }                               
                        }
                }
        }
        
        void failure(String st,Exception e)
        {
                Log.error("Closing socket: "+st);
                Log.error(e);
        }
        
        void newMessage(String id,int nb,ObjectInputStream in) throws Exception
        {
                Log.notice("INCOMING: "+nb+" messages from "+id);
                
                SpyDestination dest=null;
                JMSServerQueue queue=null;
                
                for(int i=0;i<nb;i++) { 
                        
                        SpyMessage mes=(SpyMessage)in.readObject();
                        
                        if (dest==null||!dest.equals(mes.jmsDestination)) {
                                
queue=(JMSServerQueue)server.messageQueue.get(mes.jmsDestination);
                                if (queue==null) throw new JMSException("This 
destination does not exist !"); //hum...
                        }
                
                        //Add the message to the queue          
                        queue.addMessage(mes);
                }
        }
        
        // --
        
        public DistributedJMSServer createClient() throws Exception
        {               
                return new 
DistributedJMSServerUILClient(InetAddress.getLocalHost(),serverSocket.getLocalPort());
        }
        
        public void setServer(JMSServer s)
        {
                server=s;
        }
        
  }
  
  
  
  1.1                  
spyderMQ/src/java/org/spydermq/distributed/server/DistributedJMSServerUILClient.java
  
  Index: DistributedJMSServerUILClient.java
  ===================================================================
  /*
   * spyderMQ, the OpenSource JMS implementation
   *
   * Distributable under GPL license.
   * See terms of license at gnu.org.
   */
  package org.spydermq.distributed.server;
  
  import javax.jms.JMSException;
  import javax.jms.Destination;
  import javax.jms.Topic;
  import javax.jms.Queue;
  import javax.jms.TemporaryTopic;
  import javax.jms.TemporaryQueue;
  import org.spydermq.SpyMessage;
  import org.spydermq.SpyDestination;
  import org.spydermq.JMSServer;
  import org.spydermq.Log;
  import org.spydermq.SpyDistributedConnection;
  import java.rmi.RemoteException;
  import java.io.ObjectOutputStream;
  import java.io.ObjectInputStream;
  import java.io.BufferedInputStream;
  import java.io.BufferedOutputStream;
  import java.io.IOException;
  import java.io.Serializable;
  import java.net.Socket;
  import java.net.InetAddress;
  import org.spydermq.distributed.interfaces.DistributedJMSServer;
  
  /**
   *    The OIL implementation of the DistributedJMSServer object
   *      
   *    @author Norbert Lataille ([EMAIL PROTECTED])
   *    @author Hiram Chirino ([EMAIL PROTECTED])
   * 
   *    @version $Revision: 1.1 $
   */
  import org.spydermq.multiplexor.SocketMultiplexor;public class 
DistributedJMSServerUILClient
        implements DistributedJMSServer, Serializable
  {
        
        static final int GetID = 1;
        static final int NewMessage = 2;
        static final int Subscribe = 3;
        static final int Unsubscribe = 4;
        static final int CreateTopic = 5;
        static final int CreateQueue = 6;
        static final int GetTemporaryTopic = 7;
        static final int GetTemporaryQueue = 8;
        static final int ConnectionClouting = 9;
        static final int DeleteTemporaryDestination = 10;
        static final int CheckID = 11;
        static final int QueueReceiveNoWait = 12;
        static final int ConnectionListening = 13;
        
        //Remote stuff
        
        private transient Socket socket;
  
  
        private transient ObjectOutputStream out;
        private transient ObjectInputStream in;
        
        private int port;
        private InetAddress addr;
        
        public DistributedJMSServerUILClient(InetAddress addr,int port)
        {
                socket=null;
                this.port=port;
                this.addr=addr;
        }
        
        void createConnection() throws RemoteException
        {
                try {
                        
                        System.out.println("ClientUIL initializing");
                        socket=new Socket(addr,port);
                        mSocket = new SocketMultiplexor( socket );
  
                        out=new ObjectOutputStream(new 
BufferedOutputStream(mSocket.getOutputStream(1)));
                        out.flush();
                        
                        in=new ObjectInputStream(new 
BufferedInputStream(mSocket.getInputStream(1)));
                        System.out.println("ClientUIL initialized");
                        
                } catch (Exception e) {
                        failure(e);
                }
        }
        
        public Object waitAnswer() throws RemoteException
        {
                try {
                        out.flush();
                        int val=in.read();
                        if (val==0) return null;
                        if (val==1) {
                                return in.readObject();
                        } else {
                                Exception e=(Exception)in.readObject();
                                throw new RemoteException("",e);        
                        }
                } catch (RemoteException e) {
                        Log.log(e);
                        throw e;
                } catch (Exception e) {
                        failure(e);
                        return null;
                }
                
        }       
        
        void failure(Exception e) throws RemoteException
        {
                Log.error(e);
                throw new RemoteException("Cannot contact the remote object");
        }       
        
        //--- Remote Calls
        
        public void newMessage(SpyMessage val[],String id) throws JMSException, 
RemoteException
        {
                if (socket==null) createConnection();
                
                try {
                        out.write(NewMessage);
                        out.writeObject(id);
                        out.writeInt(val.length);
                        for(int i=0;i<val.length;i++)
                                out.writeObject(val[i]);
                } catch (IOException e) {
                        failure(e);
                }
                
                waitAnswer();
        }
  
        public String getID() throws Exception
        {
                if (socket==null) createConnection();
                
                try {
                        out.write(GetID);
                } catch (IOException e) {
                        failure(e);
                }
                
                return (String)waitAnswer();
        }
                
        public void subscribe(Destination dest,SpyDistributedConnection who) throws 
JMSException, RemoteException
        {
                if (socket==null) createConnection();
                
                try {
                        out.write(Subscribe);
                        out.writeObject(dest);
                        out.writeObject(who);
                } catch (IOException e) {
                        failure(e);
                }
                
                waitAnswer();
        }
        
        public void unsubscribe(Destination dest,SpyDistributedConnection who) throws 
JMSException, RemoteException
        {
                if (socket==null) createConnection();
                
                try {
                        out.write(Unsubscribe);
                        out.writeObject(dest);
                        out.writeObject(who);
                } catch (IOException e) {
                        failure(e);
                }
                
                waitAnswer();
        }
        
        public Topic createTopic(String dest) throws JMSException, RemoteException
        {
                if (socket==null) createConnection();
                
                try {
                        out.write(CreateTopic);
                        out.writeObject(dest);
                } catch (IOException e) {
                        failure(e);
                }
                
                return (Topic)waitAnswer();
        }
        
        public Queue createQueue(String dest) throws JMSException, RemoteException
        {
                if (socket==null) createConnection();
                
                try {
                        out.write(CreateQueue);
                        out.writeObject(dest);
                } catch (IOException e) {
                        failure(e);
                }
                
                return (Queue)waitAnswer();
        }
        
        public TemporaryTopic getTemporaryTopic(SpyDistributedConnection dc) throws 
JMSException, RemoteException
        {
                if (socket==null) createConnection();
                
                try {
                        out.write(GetTemporaryTopic);
                        out.writeObject(dc);
                } catch (IOException e) {
                        failure(e);
                }
                
                return (TemporaryTopic)waitAnswer();            
        }
        
        public TemporaryQueue getTemporaryQueue(SpyDistributedConnection dc) throws 
JMSException, RemoteException
        {
                if (socket==null) createConnection();
                
                try {
                        out.write(GetTemporaryQueue);
                        out.writeObject(dc);
                } catch (IOException e) {
                        failure(e);
                }
                
                return (TemporaryQueue)waitAnswer();            
        }
        
  
        
        public void deleteTemporaryDestination(SpyDestination dest) throws 
JMSException, RemoteException
        {
                if (socket==null) createConnection();
                
                try {
                        out.write(DeleteTemporaryDestination);
                        out.writeObject(dest);
                } catch (IOException e) {
                        failure(e);
                }
                
                waitAnswer();
        }
        
        public void checkID(String ID) throws JMSException, RemoteException
        {
                if (socket==null) createConnection();
                
                try {
                        out.write(CheckID);
                        out.writeObject(ID);
                } catch (IOException e) {
                        failure(e);
                }
                
                waitAnswer();
        }
        
        public SpyMessage queueReceiveNoWait(Queue queue) throws Exception, 
RemoteException
        {
                if (socket==null) createConnection();
                
                try {
                        out.write(QueueReceiveNoWait);
                        out.writeObject(queue);
                } catch (IOException e) {
                        failure(e);
                }
                
                return (SpyMessage)waitAnswer();
        }
        
        public void connectionListening(boolean mode,Destination 
dest,SpyDistributedConnection dc) throws Exception, RemoteException
        {
                if (socket==null) createConnection();
                
                try {
                        out.write(ConnectionListening);
                        if (mode) out.write(1);
                        else out.write(0);                                             
  
                        out.writeObject(dest);
                        out.writeObject(dc);
                } catch (IOException e) {
                        failure(e);
                }
                
                waitAnswer();
        }
        
        static final int ConnectionOneTimeListener = 14;                transient 
SocketMultiplexor mSocket;    public void connectionClosing(SpyDistributedConnection 
dc) throws JMSException, RemoteException
        {
                if (socket==null) createConnection();
                
                try {
                        out.write(ConnectionClouting);
                        out.writeObject(dc);
                } catch (IOException e) {
                        failure(e);
                }
                waitAnswer();
        }}
  
  
  
  1.1                  
spyderMQ/src/java/org/spydermq/distributed/server/DistributedJMSServerUILMBean.java
  
  Index: DistributedJMSServerUILMBean.java
  ===================================================================
  /*
   * spyderMQ, the OpenSource JMS implementation
   *
   * Distributable under GPL license.
   * See terms of license at gnu.org.
   */
  package org.spydermq.distributed.server;
  
  import java.util.Vector;
  
  /**
   *    The OIL implementation of the DistributedJMSServer object
   *      
   *    @author Norbert Lataille ([EMAIL PROTECTED])
   *    @author Hiram Chirino ([EMAIL PROTECTED])
   * 
   *    @version $Revision: 1.1 $
   */
  public interface DistributedJMSServerUILMBean
  {
  }
  
  
  

Reply via email to