User: hiram   
  Date: 00/12/12 16:34:06

  Modified:    src/java/org/spydermq/server StartServer.java
  Log:
  The spyderMQ server now loads it's configuration via an XML file.
  The XML file allows us to configure the server for  multiple Invocation layers.
  
  Revision  Changes    Path
  1.3       +65 -75    spyderMQ/src/java/org/spydermq/server/StartServer.java
  
  Index: StartServer.java
  ===================================================================
  RCS file: 
/products/cvs/ejboss/spyderMQ/src/java/org/spydermq/server/StartServer.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- StartServer.java  2000/12/12 05:58:44     1.2
  +++ StartServer.java  2000/12/13 00:34:06     1.3
  @@ -35,17 +35,18 @@
   import org.spydermq.server.JMSServer;
   import org.spydermq.distributed.interfaces.DistributedConnectionFactory;
   import org.spydermq.SpyTopicConnectionFactory;
  +import org.spydermq.xml.XElement;
   
   /**
    *   Class used to start a JMS service.  This can be called from inside another
  - *  application to start the JMS provider.
  + *   application to start the JMS provider.
    *
    *   @author Norbert Lataille ([EMAIL PROTECTED])
  - *  @author Rich Johns ([EMAIL PROTECTED])
  - *  @author Vincent Sheffer ([EMAIL PROTECTED])
  + *   @author Rich Johns ([EMAIL PROTECTED])
  + *   @author Vincent Sheffer ([EMAIL PROTECTED])
    *   @author Hiram Chirino ([EMAIL PROTECTED])
    *
  - *   @version $Revision: 1.2 $
  + *   @version $Revision: 1.3 $
    */
   public class StartServer implements Runnable
   {
  @@ -146,11 +147,15 @@
                try {
   
                        //Load the property file
  -                     InputStream in = 
getClass().getClassLoader().getResource("spyderMQ.properties").openStream();
  -                     Properties cfg=new Properties();
  -                     cfg.load(in);
  +                     InputStream in = 
getClass().getClassLoader().getResource("spyderMQ.xml").openStream();
  +                     XElement serverCfg = XElement.createFrom(in);                  
 
                        in.close();
   
  +                     // Make sure that we loaded the right type of xml file
  +                     if( !serverCfg.getName().equals("Server") ) {
  +                             throw new JMSException("The spyderMQ.xml file is 
invalid.");
  +                     }
  +
                        //Get an InitialContext
                        InitialContext ctx=new InitialContext();
   
  @@ -163,85 +168,70 @@
   
                        //create the known topics
                        Context subcontext=ctx.createSubcontext("topic");
  -                     String topics=(String)cfg.get("knownTopics");
  -
  -                     if (topics!=null) {
  -
  -                             StringTokenizer st = new StringTokenizer(topics,", ");
  -
  -                             while (st.hasMoreElements()) {
  -                                     String name=(String)st.nextElement();
  -                                     Topic t=theServer.newTopic(name);
  -                                     subcontext.rebind(name,t);
  -                             }
  +                     
  +                     Iterator iter = serverCfg.getElementsNamed("Topic");
  +                     while( iter.hasNext() ) {
  +                             XElement element = (XElement)iter.next();
  +                             String name = element.getField("Name");
   
  -                     } else System.out.println("Warning: no known Topics !");
  +                             Topic t=theServer.newTopic(name);
  +                             subcontext.rebind(name,t);                             
 
  +                     }
  +                     
   
                        //create the known queues
                        subcontext=ctx.createSubcontext("queue");
  -                     String queues=(String)cfg.get("knownQueues");
  -
  -                     if (queues!=null) {
  -
  -                             StringTokenizer st = new StringTokenizer(queues,", ");
  -
  -                             while (st.hasMoreElements()) {
  -                                     String name=(String)st.nextElement();
  -                                     Queue q=theServer.newQueue(name);
  -                                     subcontext.rebind(name,q);
  -                             }
  +                     
  +                     iter = serverCfg.getElementsNamed("Queue");
  +                     while( iter.hasNext() ) {
  +                             XElement element = (XElement)iter.next();
  +                             String name = element.getField("Name");
   
  -                     } else {
  -                             System.out.println("Warning: no known Queues !");
  +                             Queue q=theServer.newQueue(name);
  +                             subcontext.rebind(name,q);
                        }
   
  -                     //Set the known Ids
  -                     String ids=(String)cfg.get("knownIds");
  -
  -                     if (ids!=null) {
  -
  -                             StringTokenizer st = new StringTokenizer(ids,", ");
   
  -                             while (st.hasMoreElements()) {
  -                                     String read=(String)st.nextElement();
  -                                     int pos=read.indexOf(':');
  -                                     if (pos==-1) throw new JMSException("Bad 
configuration file (missing separator in knownIds)");
  -                                     String name=read.substring(0,pos);
  -                                     String passwd=read.substring(pos+1);
  -                                     pos=passwd.indexOf(':');
  -
  -                                     if (pos==-1) {
  -                                             //System.out.println("[JMSServer] new 
user : Login = "+name+", Id = [none]");
  -                                             
securityManager.addUser(name,passwd,null);
  -                                     } else {
  -                                             String ID=passwd.substring(pos+1);
  -                                             //System.out.println("[JMSServer] new 
user : Login = "+name+", Id = "+ID);
  -                                             
securityManager.addUser(name,passwd.substring(0,pos),ID);
  -                                     }
  -
  +                     //Set the known Ids
  +                     iter = serverCfg.getElementsNamed("User");
  +                     while( iter.hasNext() ) {
  +                             XElement element = (XElement)iter.next();
  +                             String name = element.getField("Name");
  +                             String passwd = element.getField("Password");
  +                             if( element.containsField("Id") ) {
  +                                     
securityManager.addUser(name,passwd,element.getField("Id"));
  +                             } else {
  +                                     securityManager.addUser(name,passwd,null);
                                }
  -
  -                     } else {
  -                             System.out.println("Warning: no known Ids !");
                        }
   
  -                     //Set up the transports for the server
  -                     InvocationLayerFactory invocationLayerFactory= new 
InvocationLayerFactory();
  -                     invocationLayerFactory.distributedJMSServerClassName = 
(String)cfg.get("DistributedJMSServerClassName");
  -                     invocationLayerFactory.connectionReceiverClassName = 
(String)cfg.get("ConnectionReceiverClassName");
  -                     invocationLayerFactory.distributedConnectionFactoryClassName = 
(String)cfg.get("DistributedConnectionFactoryClassName");
  -
  -                     invocationLayerFactory.createObjects(theServer);
  -
  -                     
registerService(invocationLayerFactory.distributedJMSServerSetup,
  -                     new ObjectName("JMS:service=DistributedJMSServerSetup"));
  -
  -                     
registerService(invocationLayerFactory.distributedConnectionFactory,
  -                     new ObjectName("JMS:service=DistributedConnectionFactory"));
  -
  -                     //(re)bind the connection factories in the JNDI namespace
  -                     
ctx.rebind("TopicConnectionFactory",invocationLayerFactory.spyTopicConnectionFactory);
  -                     
ctx.rebind("QueueConnectionFactory",invocationLayerFactory.spyQueueConnectionFactory);
  +                     iter = serverCfg.getElementsNamed("InvocationLayer");
  +                     while( iter.hasNext() ) {
  +                             
  +                             XElement element = (XElement)iter.next();
  +                             String name = element.getField("Name");
  +                             String topicConnectionFactoryJNDI = 
element.getField("TopicConnectionFactoryJNDI");
  +                             String queueConnectionFactoryJNDI = 
element.getField("QueueConnectionFactoryJNDI");
  +
  +                             //Set up the transports for the server
  +                             InvocationLayerFactory invocationLayerFactory= new 
InvocationLayerFactory();
  +                             invocationLayerFactory.distributedJMSServerClassName = 
element.getField("ServerClass");
  +                             invocationLayerFactory.connectionReceiverClassName = 
element.getField("ReceiverClass");
  +                             
invocationLayerFactory.distributedConnectionFactoryClassName = 
element.getField("ConnectionFactoryClass");
  +
  +                             invocationLayerFactory.createObjects(theServer);
  +
  +                             
registerService(invocationLayerFactory.distributedJMSServerSetup,
  +                             new 
ObjectName("JMS:service=DistributedJMSServerSetup,type="+name));
  +
  +                             
registerService(invocationLayerFactory.distributedConnectionFactory,
  +                             new 
ObjectName("JMS:service=DistributedConnectionFactory,type="+name));
  +
  +                             //(re)bind the connection factories in the JNDI 
namespace
  +                             
ctx.rebind(topicConnectionFactoryJNDI,invocationLayerFactory.spyTopicConnectionFactory);
  +                             
ctx.rebind(queueConnectionFactoryJNDI,invocationLayerFactory.spyQueueConnectionFactory);
  +                             
  +                     }
   
   
                } catch (Exception e) {
  
  
  

Reply via email to