User: vincent 
  Date: 00/08/24 19:30:24

  Modified:    src/java/org/spydermq JMSServer.java
  Log:
  Factored out starting up the SpyderMQ server so that it can be started
  both standalone and inside another application (e.g. JBoss).
  
  Revision  Changes    Path
  1.8       +76 -45    spyderMQ/src/java/org/spydermq/JMSServer.java
  
  Index: JMSServer.java
  ===================================================================
  RCS file: /products/cvs/ejboss/spyderMQ/src/java/org/spydermq/JMSServer.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- JMSServer.java    2000/06/20 02:19:10     1.7
  +++ JMSServer.java    2000/08/25 02:30:23     1.8
  @@ -22,7 +22,7 @@
    *      
    *   @author Norbert Lataille ([EMAIL PROTECTED])
    * 
  - *   @version $Revision: 1.7 $
  + *   @version $Revision: 1.8 $
    */
   public class JMSServer 
                implements Runnable, JMSServerMBean
  @@ -49,6 +49,19 @@
        //The security manager
        SecurityManager securityManager;
   
  +    /**
  +     * <code>true</code> when the server is running.  <code>false</code> when the 
  +     * server should stop running.
  +     */
  +    private boolean alive = true;
  +
  +    /**
  +     * Because there can be a delay between killing the JMS service and the 
  +     * service actually dying, this field is used to tell external classes
  +     * that that server has actually stopped.
  +     */
  +    private boolean stopped = true;
  +
        // Constructor ---------------------------------------------------
      
        public JMSServer(SecurityManager securityManager)
  @@ -71,57 +84,75 @@
                
       }
   
  +    /**
  +     * Returns <code>false</code> if the JMS server is currently
  +     * running and handling requests, <code>true</code> otherwise.
  +     *
  +     * @return <code>false</code> if the JMS server is currently
  +     *         running and handling requests, <code>true</code> 
  +     *         otherwise.
  +     */
  +    public boolean isStopped() {
  +        return this.stopped;
  +    }
  +
        // Public --------------------------------------------------------
   
        //This is a correct threading system, but this is not ideal... 
        //We should let threads cycle through the JMSServerQueue list, and 
synchronized on the queue they are working on.
  -     
  -     public void run()
  -     {
  -             while (true)
  -             {
        
  -                     JMSServerQueue queue=null;                      
  +     public void run() {
  +            while (alive) {
  +                JMSServerQueue queue = null;                 
                
  -                     //Wait (and sleep) until it can find something to do
  -                     synchronized (taskQueue)
  -                     {
  -                             while (queue==null) {                                  
 
  -                                     
  -                                     // size() is O(1) in LinkedList... 
  -                                     int size=taskQueue.size(); 
  -                                     if (size!=0) { 
  -                                             
  -                                             //<DEBUG>
  -                                             
queue=(JMSServerQueue)taskQueue.removeFirst();
  -                                             
//queue=(JMSServerQueue)taskQueue.getFirst();
  -                                             //</DEBUG>
  -                                             
  -                                             //One other thread can start working 
on the task queue...
  -                                             if (size>1) taskQueue.notify();
  -                                     } else {        
  -                                             try {
  -                                                     Log.log("I'm going to bed...");
  -                                                     taskQueue.wait();
  -                                                     Log.log("I wake up");
  -                                             } catch (InterruptedException e) {
  -                                             }
  -                                     }
  -                                     
  -                             }
  -                     }
  -
  -                     //Ask the queue to do its job
  -                     try {
  -                             queue.doMyJob();
  -                     } catch (JMSException e) {
  -                             Log.error(e);
  -                     }
  -                     
  -             }
  -                     
  +                this.stopped = false;
  +
  +                //Wait (and sleep) until it can find something to do
  +                synchronized (taskQueue) {
  +                    while (queue == null && alive) {                                
 
  +                        
  +                        // size() is O(1) in LinkedList... 
  +                        int size=taskQueue.size(); 
  +                        if (size!=0) { 
  +                            
  +                            //<DEBUG>
  +                            queue = (JMSServerQueue)taskQueue.removeFirst();
  +                            //queue=(JMSServerQueue)taskQueue.getFirst();
  +                            //</DEBUG>
  +                            
  +                            //One other thread can start working on the task 
queue...
  +                            if (size > 1) {
  +                                taskQueue.notify();
  +                            }
  +                        } else {     
  +                            try {
  +                                Log.log("I'm going to bed...");
  +                                taskQueue.wait(5000);
  +                                Log.log("I wake up");
  +                            } catch (InterruptedException e) {
  +                            }
  +                        }
  +                        
  +                    }
  +                }
  +                
  +                if (alive) {
  +                    //Ask the queue to do its job
  +                    try {
  +                        queue.doMyJob();
  +                    } catch (JMSException e) {
  +                        Log.error(e);
  +                    }
  +                }
  +            }
  +            Log.log("JMS service stopped.");
  +            this.stopped = true;
        }
  -     
  +
  +    public void stopServer() {
  +        this.alive = false;
  +    }
  +
        // Administration calls
        
        public SpyTopic newTopic(String name) throws JMSException
  
  
  

Reply via email to