User: joel
Date: 01/03/14 13:36:54
Modified: src/main/org/jbossmq/server JMSServer.java
JMSServerMBean.java
Log:
Added ability to dynamically add/remove queues/topics to the server.
When adding new queue/topic the server will add it to the internal message queue
structure,
as well as the JNDI topic/queue subcontext. It will also add an entry to the server's
config file, so the server will remember the topic/queue between bounces. When
removing
a queue/topic it will remove it from the internal message structure, the JNDI tree,
and
the config file.
Revision Changes Path
1.5 +256 -7 jbossmq/src/main/org/jbossmq/server/JMSServer.java
Index: JMSServer.java
===================================================================
RCS file: /products/cvs/ejboss/jbossmq/src/main/org/jbossmq/server/JMSServer.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- JMSServer.java 2001/03/02 01:13:02 1.4
+++ JMSServer.java 2001/03/14 21:36:54 1.5
@@ -16,11 +16,13 @@
import java.util.LinkedList;
import java.util.HashMap;
import java.util.Iterator;
+import java.util.Enumeration;
+import java.io.IOException;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
-
-
-
import org.jbossmq.*;
import org.jbossmq.xml.XElement;
@@ -30,7 +32,7 @@
* @author Norbert Lataille ([EMAIL PROTECTED])
* @author Hiram Chirino ([EMAIL PROTECTED])
*
- * @version $Revision: 1.4 $
+ * @version $Revision: 1.5 $
*/
public class JMSServer
implements Runnable, JMSServerMBean
@@ -181,11 +183,133 @@
newMap.put(newTopic,queue);
messageQueue=newMap;
}
-
+
+ InitialContext ctx = null;
+ Context subcontext = null;
+
+ try{
+ //Get an InitialContext
+ ctx = new InitialContext();
+
+ //get the topics subcontext
+ subcontext = (Context)ctx.lookup("topic");
+
+ //add this topic to the jndi topic context
+ subcontext.rebind(name,newTopic);
+
+ }
+ catch(Exception e){
+ //remove the topic from the messageQueue
+ messageQueue.remove(newTopic);
+ throw new JMSException("Exception binding Topic to the JNDI topic
context: "+e);
+ }
+
+ //check to see if this topic already exists in the config structure
+ boolean topicExists = false;
+ XElement element = null;
+
+ try{
+ Enumeration enum = serverConfig.getElementsNamed("Topic");
+
+ while( enum.hasMoreElements() ) {
+ element = (XElement)enum.nextElement();
+ if(name.equals(element.getField("Name"))){
+ topicExists = true;
+ break;
+ }
+
+ }
+
+ //if it doesn't exist, add it
+ if(!topicExists){
+ XElement newTopicEl = new XElement("Topic");
+ newTopicEl.addField("Name", name);
+ serverConfig.addElement(newTopicEl);
+
+ //save the new state in the config file
+ saveConfig();
+ }
+
+ }
+ catch(Exception ioe){
+ //remove the topic from the messageQueue
+ messageQueue.remove(newTopic);
+ //remove the topic from the jndi topic context
+ try{
+ subcontext.unbind(name);
+ }
+ catch(Exception e){ /*Do we need to do anything else here? For now
we'll just eat this exception */ }
+
+ throw new JMSException("Exception saving updated configuration
state: "+ioe);
+ }
+
return newTopic;
}
+ public void destroyTopic(String name) throws JMSException
+ {
+ Log.notice("destroy topic : "+name);
+
+ SpyTopic destroyTopic=new SpyTopic(name);
+ if (!messageQueue.containsKey(destroyTopic)) throw new
JMSException("This topic doesn't exist!");
+
+ JMSDestination queue=new JMSDestination(destroyTopic,null,this);
+
+ //remove this new JMSServerQueue from the list
+ synchronized (messageQueue) {
+ HashMap newMap=(HashMap)messageQueue.clone();
+ newMap.remove(destroyTopic);
+ messageQueue=newMap;
+ }
+
+ InitialContext ctx = null;
+ Context subcontext = null;
+
+ try{
+ //Get an InitialContext
+ ctx = new InitialContext();
+
+ //get the topics subcontext
+ subcontext = (Context)ctx.lookup("topic");
+
+ //remove this topic to the jndi topic context
+ subcontext.unbind(name);
+
+ }
+ catch(Exception e){
+ throw new JMSException("Exception unbinding Topic from the JNDI
topic context: "+e);
+ }
+
+ //check to see if this topic already exists in the config structure
+ //and remove it if it does
+ XElement element = null;
+
+ try{
+ Enumeration enum = serverConfig.getElementsNamed("Topic");
+
+ while( enum.hasMoreElements() ) {
+ element = (XElement)enum.nextElement();
+ if(name.equals(element.getField("Name"))){
+ //remove this topic element from the config structure
+ element.removeFromParent();
+ break;
+ }
+
+ }
+
+ //save the new state in the config file
+ saveConfig();
+
+
+ }
+ catch(Exception ioe){
+ throw new JMSException("Exception saving updated configuration
state: "+ioe);
+ }
+
+ }
+
+
public SpyQueue newQueue(String name) throws JMSException
{
Log.notice("new queue : "+name);
@@ -201,10 +325,135 @@
newMap.put(newQueue,queue);
messageQueue=newMap;
}
-
+
+ InitialContext ctx = null;
+ Context subcontext = null;
+
+ try{
+ //Get an InitialContext
+ ctx = new InitialContext();
+
+ //get the queues subcontext
+ subcontext = (Context)ctx.lookup("queue");
+
+ //add this queue to the jndi queue context
+ subcontext.rebind(name,newQueue);
+
+ }
+ catch(Exception e){
+ //remove the queue from the messageQueue
+ messageQueue.remove(newQueue);
+ throw new JMSException("Exception binding Queue to the JNDI queue
context: "+e);
+ }
+
+ //check to see if this queue already exists in the config structure
+ boolean queueExists = false;
+ XElement element = null;
+ try{
+
+ Enumeration enum = serverConfig.getElementsNamed("Queue");
+
+ while( enum.hasMoreElements() ) {
+ element = (XElement)enum.nextElement();
+ if(name.equals(element.getField("Name"))){
+ queueExists = true;
+ break;
+ }
+
+ }
+
+ if(!queueExists){
+ //add this queue to the config structure
+ XElement newQueueEl = new XElement("Queue");
+ newQueueEl.addField("Name", name);
+ serverConfig.addElement(newQueueEl);
+
+ //save the new state in the config file
+ saveConfig();
+
+ }
+
+ }
+ catch(Exception ioe){
+ //remove the queue from the messageQueue
+ messageQueue.remove(newQueue);
+ //remove the queue from the jndi queue context
+ try{
+ subcontext.unbind(name);
+ }
+ catch(Exception e){ /*Do we need to do anything else here? For now
we'll just eat this exception */ }
+
+ throw new JMSException("Exception saving updated configuration
state: "+ioe);
+ }
+
return newQueue;
}
+
+
+ public void destroyQueue(String name) throws JMSException
+ {
+ Log.notice("destroy queue : "+name);
+ SpyQueue destroyQueue=new SpyQueue(name);
+ if (!messageQueue.containsKey(destroyQueue)) throw new
JMSException("This queue doesn't exist!");
+
+ JMSDestination queue=new JMSDestination(destroyQueue,null,this);
+
+ //remove this new JMSServerQueue from the list
+ synchronized (messageQueue) {
+ HashMap newMap=(HashMap)messageQueue.clone();
+ newMap.remove(destroyQueue);
+ messageQueue=newMap;
+ }
+
+ InitialContext ctx = null;
+ Context subcontext = null;
+
+ try{
+ //Get an InitialContext
+ ctx = new InitialContext();
+
+ //get the queues subcontext
+ subcontext = (Context)ctx.lookup("queue");
+
+ //remove this queue to the jndi queue context
+ subcontext.unbind(name);
+
+ }
+ catch(Exception e){
+ throw new JMSException("Exception unbinding Queue from the JNDI
queue context: "+e);
+ }
+
+ //check to see if this queue already exists in the config structure
+ //and remove it if it does
+ XElement element = null;
+
+ try{
+ Enumeration enum = serverConfig.getElementsNamed("Queue");
+
+ while( enum.hasMoreElements() ) {
+ element = (XElement)enum.nextElement();
+ if(name.equals(element.getField("Name"))){
+ //remove this queue element from the config structure
+ element.removeFromParent();
+ break;
+ }
+
+ }
+
+ //save the new state in the config file
+ saveConfig();
+
+
+ }
+ catch(Exception ioe){
+ throw new JMSException("Exception saving updated configuration
state: "+ioe);
+ }
+
+
+ }
+
+
//Get a new ClientID for a connection
public String getID()
{
@@ -524,4 +773,4 @@
return userManager.checkUser(userName, password);
}
-}
\ No newline at end of file
+}
1.3 +7 -4 jbossmq/src/main/org/jbossmq/server/JMSServerMBean.java
Index: JMSServerMBean.java
===================================================================
RCS file:
/products/cvs/ejboss/jbossmq/src/main/org/jbossmq/server/JMSServerMBean.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- JMSServerMBean.java 2001/03/02 01:13:02 1.2
+++ JMSServerMBean.java 2001/03/14 21:36:54 1.3
@@ -16,10 +16,13 @@
* @author Norbert Lataille ([EMAIL PROTECTED])
* @author Hiram Chirino ([EMAIL PROTECTED])
*
- * @version $Revision: 1.2 $
+ * @version $Revision: 1.3 $
*/
public interface JMSServerMBean
{
- public SpyTopic newTopic(String name) throws JMSException;
- public SpyQueue newQueue(String name) throws JMSException;
-}
\ No newline at end of file
+ public SpyTopic newTopic(String name) throws JMSException;
+ public void destroyTopic(String name) throws JMSException;
+
+ public SpyQueue newQueue(String name) throws JMSException;
+ public void destroyQueue(String name) throws JMSException;
+}