User: norbert
Date: 00/05/31 11:10:21
Added: src/java/org/spydermq/server Main.java
Log:
Change the directory name
Revision Changes Path
1.1 spyderMQ/src/java/org/spydermq/server/Main.java
Index: Main.java
===================================================================
package org.spydermq.server;
/*
* spyderMQ, the OpenSource JMS implementation
*
* Distributable under GPL license.
* See terms of license at gnu.org.
*/
import org.spydermq.JMSServer;
import org.spydermq.security.SecurityManager;
import org.spydermq.distributed.interfaces.DistributedJMSServer;
import org.spydermq.distributed.interfaces.DistributedTopicConnectionFactory;
import org.spydermq.distributed.interfaces.DistributedQueueConnectionFactory;
import org.spydermq.distributed.JMSServerFactory;
import org.spydermq.distributed.SpyTopicConnectionFactory;
import org.spydermq.distributed.SpyQueueConnectionFactory;
import javax.jms.TopicConnectionFactory;
import javax.jms.QueueConnectionFactory;
import javax.jms.JMSException;
import javax.jms.Topic;
import javax.jms.Queue;
import org.jnp.server.NamingServer;
import javax.naming.InitialContext;
import javax.naming.Context;
import java.util.Properties;
import java.io.FileInputStream;
import java.util.StringTokenizer;
/**
* A simple JMS server
* This class is meant to be extended by specific server wanting JMS services
*
* @author Norbert Lataille ([EMAIL PROTECTED])
* @author Rich Johns ([EMAIL PROTECTED])
*
* @version $Revision: 1.1 $
*/
public class Main implements Runnable
{
SpyTopicConnectionFactory topicConnectionFactory;
SpyQueueConnectionFactory queueConnectionFactory;
DistributedTopicConnectionFactory distributedTopicConnectionFactory;
DistributedQueueConnectionFactory distributedQueueConnectionFactory;
DistributedJMSServer theDistributedServer;
SecurityManager securityManager;
JMSServer theServer;
//We prevent garbage collection with a static variable
//MF FIXME: use JMX to admin and prevent garbage collectionf
private static Main thisServer;
//bind the TopicConnectionFactory object
public void startJMSServer()
{
System.out.println("SpyderMQ [v0.3]");
try {
//Load the property file
FileInputStream in = new
FileInputStream("spyderMQ.properties");
Properties cfg=new Properties();
cfg.load(in);
in.close();
// By default we will start a JNDI Server. We won't
// if user explicitly tells us not to.
String noStartJNDI = (String)cfg.get("DoNotStartJNDI" );
if( (noStartJNDI == null) || (noStartJNDI.length() == 0) )
{
//Start the JNDI server
System.out.println( "Starting JNDI Server (JNP)" );
new org.jnp.server.Main().start();
}
else
{
// Need to warn user because if they fail to start
// a JNDI server prior to starting spyder, they
// will be confused by the resulting error.
System.out.println("[Warning]: SpyderMQ.properties
specifys NOT to start a JNDI Server.");
System.out.println(" If a JNDI Server is not
running SpyderMQ will not start.");
}
//Get an InitialContext
InitialContext ctx=new InitialContext();
//Create a SecurityManager object
securityManager=new SecurityManager();
//Create the JMSServer object
theServer = new JMSServer(securityManager);
theDistributedServer =
JMSServerFactory.createJMSServer(theServer,cfg);
String
connectionReceiverCN=(String)cfg.get("ConnectionReceiverClassName");
//Get the Topic properties
String
topicConnectionFactoryCN=(String)cfg.get("DistributedTopicConnectionFactoryClassName");
if
(topicConnectionFactoryCN==null||connectionReceiverCN==null) throw new
RuntimeException("Missing configuration parameters");
//Create the distributedTopicConnectionFactory object
distributedTopicConnectionFactory =
(DistributedTopicConnectionFactory)Class.forName(topicConnectionFactoryCN).newInstance();
distributedTopicConnectionFactory.setServer(theDistributedServer);
distributedTopicConnectionFactory.setCRClassName(connectionReceiverCN);
distributedTopicConnectionFactory.setSecurityManager(securityManager);
//Create the topicConnectionFactory object
topicConnectionFactory = new
SpyTopicConnectionFactory(distributedTopicConnectionFactory);
//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);
}
} else System.out.println("Warning: no known Topics !");
//Get the queue properties
String
queueConnectionFactoryCN=(String)cfg.get("DistributedQueueConnectionFactoryClassName");
if (queueConnectionFactoryCN==null) throw new
RuntimeException("Missing configuration parameter");
//Create the distributedTopicConnectionFactory object
distributedQueueConnectionFactory =
(DistributedQueueConnectionFactory)Class.forName(queueConnectionFactoryCN).newInstance();
distributedQueueConnectionFactory.setServer(theDistributedServer);
distributedQueueConnectionFactory.setCRClassName(connectionReceiverCN);
distributedQueueConnectionFactory.setSecurityManager(securityManager);
//Create the topicConnectionFactory object
queueConnectionFactory = new
SpyQueueConnectionFactory(distributedQueueConnectionFactory);
//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);
}
} else System.out.println("Warning: no known Queues !");
//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);
}
}
} else System.out.println("Warning: no known Ids !");
//(re)bind the connection factories in the JNDI namespace
ctx.rebind("TopicConnectionFactory",topicConnectionFactory);
ctx.rebind("QueueConnectionFactory",queueConnectionFactory);
} catch (Exception e) {
System.out.println("Cannot start the JMS server !
"+e.getMessage());
e.printStackTrace();
}
}
public void run()
{
try {
startJMSServer();
} catch (Exception e) {
System.out.println("I cannot start the server");
e.printStackTrace(System.err);
}
}
public static void main(String[] args) throws Exception
{
thisServer = new Main();
thisServer.run();
}
}