User: user57  
  Date: 02/02/12 23:51:54

  Modified:    src/main/org/jboss/mq/server QueueManager.java
                        TopicManager.java
  Log:
   o Implemented JNDI unbind during stop(), still needs more work to finish
     the stop impls
  
  Revision  Changes    Path
  1.13      +70 -62    jbossmq/src/main/org/jboss/mq/server/QueueManager.java
  
  Index: QueueManager.java
  ===================================================================
  RCS file: /cvsroot/jboss/jbossmq/src/main/org/jboss/mq/server/QueueManager.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- QueueManager.java 13 Feb 2002 00:15:01 -0000      1.12
  +++ QueueManager.java 13 Feb 2002 07:51:54 -0000      1.13
  @@ -4,6 +4,7 @@
    * Distributable under LGPL license.
    * See terms of license at gnu.org.
    */
  +
   package org.jboss.mq.server;
   
   import java.util.HashMap;
  @@ -28,12 +29,12 @@
   import org.jboss.logging.Logger;
   
   /**
  - *  This class is a message queue which is stored (hashed by Destination)
  - *  on the JMS provider
  + * This class is a message queue which is stored (hashed by Destination)
  + * on the JMS provider
    *
    * @author     Norbert Lataille ([EMAIL PROTECTED])
    * @author     <a href="[EMAIL PROTECTED]">Hiram Chirino</a>
  - * @version    $Revision: 1.12 $
  + * @version    $Revision: 1.13 $
    */
   public class QueueManager
      extends ServiceMBeanSupport
  @@ -43,33 +44,17 @@
      SpyQueue queue;
      String queueName;
      String jndiName;
  -   boolean jndiBound = false;
  +   boolean jndiBound;
      
      private ObjectName jbossMQService;
   
  -   /**
  -    *  Gets the Name attribute of the QueueManager object
  -    *
  -    * @return    The Name value
  -    */
  -   public String getName()
  -   {
  -      return "JBossMQQueue";
  -   }
  -
  -   /**
  -    *  Insert the method's description here. Creation date: (7/1/2001 11:30:33
  -    *  AM)
  -    *
  -    * @return    java.lang.String
  -    */
      public String getQueueName()
      {
         return queueName;
      }
   
      /**
  -    *  Gets the QueueDepth attribute of the QueueManager object
  +    * Gets the QueueDepth attribute of the QueueManager object
       *
       * @return                The QueueDepth value
       * @exception  Exception  Description of Exception
  @@ -81,6 +66,7 @@
      
      /**
       * Get the value of JBossMQService.
  +    * 
       * @return value of JBossMQService.
       */
      public ObjectName getJBossMQService() 
  @@ -90,6 +76,7 @@
      
      /**
       * Set the value of JBossMQService.
  +    * 
       * @param v  Value to assign to JBossMQService.
       */
      public void setJBossMQService(ObjectName  jbossMQService) 
  @@ -97,48 +84,56 @@
         this.jbossMQService = jbossMQService;
      }
   
  -   /**
  -    *  #Description of the Method
  -    *
  -    * @exception  Exception  Description of Exception
  -    */
  -   public void startService() throws Exception
  +   protected void startService() throws Exception
      {
         if (queueName == null || queueName.length() == 0)
         {
  -         throw new Exception("QueueName was not set");
  +         throw new IllegalStateException("QueueName was not set");
         }
   
  -      JMSServer server = (JMSServer)getServer().invoke(jbossMQService, 
"getJMSServer", new Object[]{}, new String[]{});
  +      JMSServer jmsServer = (JMSServer)
  +         server.invoke(jbossMQService,
  +                       "getJMSServer",
  +                       new Object[0],
  +                       new String[0]);
   
         queue = new SpyQueue(queueName);
  -      destination = new JMSQueue(queue, null, server);
  -
  +      destination = new JMSQueue(queue, null, jmsServer);
   
  -//      server.addDestination(queue, destination);
  -
  -      try { 
  -         server.addDestination(queue, destination);
  +      jmsServer.addDestination(queue, destination);
  +      jmsServer.getPersistenceManager().restoreQueue(destination, queue);
         
  -      //server.getPersistenceManager().initQueue(destination);
  -      server.getPersistenceManager().restoreQueue(destination, queue);
  -      if (jndiName == null)
  -         setJNDIName("queue/"+queueName);
  -      else
  -         setJNDIName(jndiName); //in config phase, all we did was store the name, 
and not actually bind
  +      if (jndiName == null) {
  +         setJNDIName("queue/" + queueName);
         }
  -      catch (JMSException e) {
  -         log.warn("Couldn't add queue", e);
  +      else {
  +         // in config phase, all we did was store the name, and not actually bind
  +         setJNDIName(jndiName);
         }
  -      
      }
   
  -   protected void stopService()
  -   {
  -      log.warn("queue stop not yet implemented");
  +   protected void stopService() throws Exception
  +   {
  +      // unbind from JNDI
  +      if (jndiBound) {
  +         InitialContext ctx = new InitialContext();
  +         try {
  +            Util.unbind(ctx, jndiName);
  +         }
  +         finally {
  +            ctx.close();
  +         }
  +         jndiName = null;
  +         jndiBound = false;
  +      }
  +
  +      // TODO: need to remove from JMSServer
  +      
  +      log.warn("queue stop not yet fully implemented");
      }
   
  -   protected ObjectName getObjectName(MBeanServer server, ObjectName name) throws 
javax.management.MalformedObjectNameException
  +   protected ObjectName getObjectName(MBeanServer server, ObjectName name)
  +      throws MalformedObjectNameException
      {
         queueName = name.getKeyProperty("name");
         if (queueName == null || queueName.length() == 0)
  @@ -152,32 +147,45 @@
         return name;
      }
   
  -  /**
  +   /**
       * Sets the JNDI name for this queue
  +    * 
       * @param name Name to bind this queue to in the JNDI tree
       */
  -   public synchronized void setJNDIName(String name) throws Exception{
  -      if (queue == null){ //nothing to bind yet, startService will recall us
  +   public synchronized void setJNDIName(String name)
  +      throws Exception
  +   {
  +      if (queue == null){ // nothing to bind yet, startService will recall us
            jndiName = name;
            return;
         }
  -      if (name == null)
  -         throw new InvalidAttributeValueException("Queue JNDI names can't be null");
  -      InitialContext ic  = new InitialContext();
  -      if (jndiName != null && jndiBound){
  -         Util.unbind(ic,jndiName); //Remove old jndi name
  -         jndiName = null;
  -         jndiBound = false;
  +      
  +      if (name == null) {
  +         throw new InvalidAttributeValueException("Queue JNDI names can not be 
null");
         }
  -      Util.rebind(ic,name,queue);
  -      jndiName = name;
  -      jndiBound = true;
  -
  +      
  +      InitialContext ic = new InitialContext();
  +      try {
  +         if (jndiName != null && jndiBound){
  +            Util.unbind(ic,jndiName); // Remove old jndi name
  +            jndiName = null;
  +            jndiBound = false;
  +         }
  +         
  +         Util.rebind(ic,name, queue);
  +         jndiName = name;
  +         jndiBound = true;
  +      }
  +      finally {
  +         ic.close();
  +      }
  +      
         log.info("Bound to JNDI name: " + jndiName);
      }
   
      /**
       * Gets the JNDI name use by this queue
  +    * 
       * @return  The JNDI name currently in use
       */
      public String getJNDIName(){
  
  
  
  1.14      +96 -93    jbossmq/src/main/org/jboss/mq/server/TopicManager.java
  
  Index: TopicManager.java
  ===================================================================
  RCS file: /cvsroot/jboss/jbossmq/src/main/org/jboss/mq/server/TopicManager.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- TopicManager.java 13 Feb 2002 00:15:01 -0000      1.13
  +++ TopicManager.java 13 Feb 2002 07:51:54 -0000      1.14
  @@ -1,9 +1,10 @@
   /*
  -* JBoss, the OpenSource J2EE webOS
  -*
  -* Distributable under LGPL license.
  -* See terms of license at gnu.org.
  -*/
  + * JBoss, the OpenSource J2EE webOS
  + *
  + * Distributable under LGPL license.
  + * See terms of license at gnu.org.
  + */
  +
   package org.jboss.mq.server;
   
   import java.util.Collection;
  @@ -31,119 +32,110 @@
   import org.jboss.logging.Logger;
   
   /**
  -*  This class is a message queue which is stored (hashed by Destination) on the
  -*  JMS provider
  -*
  -* @author     Norbert Lataille ([EMAIL PROTECTED])
  -* @author     <a href="[EMAIL PROTECTED]">Hiram Chirino</a>
  -* @version    $Revision: 1.13 $
  -*/
  + * This class is a message queue which is stored (hashed by Destination) on the
  + * JMS provider
  + *
  + * @author     Norbert Lataille ([EMAIL PROTECTED])
  + * @author     <a href="[EMAIL PROTECTED]">Hiram Chirino</a>
  + * @version    $Revision: 1.14 $
  + */
   public class TopicManager
  -extends ServiceMBeanSupport
  -implements TopicManagerMBean, MBeanRegistration
  +   extends ServiceMBeanSupport
  +   implements TopicManagerMBean, MBeanRegistration
   {
  -   
      JMSTopic destination;
      SpyTopic topic;
      String topicName;
      String jndiName;
  -   boolean jndiBound = false;
  -   private ObjectName jbossMQService;
  +   boolean jndiBound;
      
  -   /**
  -   *  Gets the Name attribute of the TopicManager object
  -   *
  -   * @return    The Name value
  -   */
  -   public String getName()
  -   {
  -      return "JBossMQTopic";
  -   }
  +   private ObjectName jbossMQService;
      
  -   /**
  -   *  Insert the method's description here. Creation date: (7/1/2001 11:27:22
  -   *  AM)
  -   *
  -   * @return    java.lang.String
  -   */
      public String getTopicName()
      {
         return topicName;
      }
      
      /**
  -   * Get the value of JBossMQService.
  -   * @return value of JBossMQService.
  -   */
  +    * Get the value of JBossMQService.
  +    * 
  +    * @return value of JBossMQService.
  +    */
      public ObjectName getJBossMQService() 
      {
         return jbossMQService;
      }
      
      /**
  -   * Set the value of JBossMQService.
  -   * @param v  Value to assign to JBossMQService.
  -   */
  +    * Set the value of JBossMQService.
  +    * 
  +    * @param v  Value to assign to JBossMQService.
  +    */
      public void setJBossMQService(ObjectName  jbossMQService) 
      {
         this.jbossMQService = jbossMQService;
      }
      
  -   /**
  -   *  #Description of the Method
  -   *
  -   * @exception  Exception  Description of Exception
  -   */
      public void startService() throws Exception
      {
         if (topicName == null || topicName.length() == 0)
         {
  -         throw new Exception("TopicName was not set");
  +         throw new IllegalStateException("TopicName was not set");
         }
         
  -      JMSServer server = (JMSServer)getServer().invoke(jbossMQService, 
"getJMSServer", new Object[]{
  -         }, new String[]{
  -         });
  +      JMSServer jmsServer = (JMSServer)
  +         server.invoke(jbossMQService,
  +                       "getJMSServer",
  +                       new Object[0],
  +                       new String[0]);
         
         topic = new SpyTopic(topicName);
  -      destination = new JMSTopic(topic, null, server);
  +      destination = new JMSTopic(topic, null, jmsServer);
         
  -      //      server.addDestination(topic, destination);
  -      try { 
  -         
  -         server.addDestination(topic, destination) ;
  +      jmsServer.addDestination(topic, destination);
            
  -         //Is this right? 
  -         StateManager sm = server.getStateManager();
  -         Collection durableSubs = sm.getDurableSubscriptionIdsForTopic(topic);
  -         for (Iterator i = durableSubs.iterator(); i.hasNext();) 
  -         {
  -            destination.createDurableSubscription((DurableSubscriptionID)i.next()); 
        
  -         } // end of for ()
  +      // Is this right? 
  +      StateManager sm = jmsServer.getStateManager();
  +      Collection durableSubs = sm.getDurableSubscriptionIdsForTopic(topic);
  +      for (Iterator i = durableSubs.iterator(); i.hasNext();) 
  +      {
  +         destination.createDurableSubscription((DurableSubscriptionID)i.next());    
     
  +      }
            
  -         //server.getPersistenceManager().restoreQueue(destination, topic);
  -         //server.getPersistenceManager().initQueue(destination);
  +      // jmsServer.getPersistenceManager().restoreQueue(destination, topic);
  +      // jmsServer.getPersistenceManager().initQueue(destination);
            
  -         if (jndiName == null)
  -            setJNDIName("topic/"+topicName);
  -         else
  -            setJNDIName(jndiName); //In config phase, we only stored the name, and 
didn't actually bind it
  +      if (jndiName == null) {
  +            setJNDIName("topic/" + topicName);
         }
  -      catch (JMSException e) {
  -         log.warn("Couldn't add topic", e);
  +      else {
  +         // in config phase, we only stored the name, and didn't actually bind it
  +         setJNDIName(jndiName);
         }
  -   
      }
      
  -   protected void stopService()
  -   {
  -      // FIXME marcf: implement the removal of the service 
  -      // The behavior to be fixed is a "rebuild the server, it hot deploys, 
destination exists"
  -      log.warn("queue stop not yet implemented");
  +   protected void stopService() throws Exception
  +   {
  +      // unbind from JNDI
  +      if (jndiBound) {
  +         InitialContext ctx = new InitialContext();
  +         try {
  +            Util.unbind(ctx, jndiName);
  +         }
  +         finally {
  +            ctx.close();
  +         }
  +         jndiName = null;
  +         jndiBound = false;
  +      }
  +
  +      // TODO: need to remove from JMSServer
  +
  +      log.warn("topic stop not yet fully implemented");
      }
      
      protected ObjectName getObjectName(MBeanServer server, ObjectName name)
  -      throws javax.management.MalformedObjectNameException
  +      throws MalformedObjectNameException
      {
         topicName = name.getKeyProperty("name");
         if (topicName == null || topicName.length() == 0)
  @@ -158,34 +150,45 @@
      }
      
      /**
  -   * Sets the JNDI name for this topic
  -   * @param name Name to bind this topic to in the JNDI tree
  -   */
  -   public synchronized void setJNDIName(String name) throws Exception{
  -      if (topic == null){ //nothing to bind yet, startService will recall us
  +    * Sets the JNDI name for this topic
  +    * 
  +    * @param name Name to bind this topic to in the JNDI tree
  +    */
  +   public synchronized void setJNDIName(String name) throws Exception {
  +      if (topic == null) { // nothing to bind yet, startService will recall us
            jndiName = name;
            return;
         }
  -      if (name == null)
  -         throw new InvalidAttributeValueException("Topic JNDI names can't be null");
  -      InitialContext ic  = new InitialContext();
  -      if (jndiName != null && jndiBound){
  -         Util.unbind(ic,jndiName); //Remove old jndi name
  -         jndiName = null;
  -         jndiBound = false;
  +      
  +      if (name == null) {
  +         throw new InvalidAttributeValueException("Topic JNDI names can not be 
null");
         }
  -      Util.rebind(ic,name,topic);
  -      jndiName = name;
  -      jndiBound = true;
  +      
  +      InitialContext ic = new InitialContext();
  +      try {
  +         if (jndiName != null && jndiBound){
  +            Util.unbind(ic,jndiName); //Remove old jndi name
  +            jndiName = null;
  +            jndiBound = false;
  +         }
  +         
  +         Util.rebind(ic,name,topic);
  +         jndiName = name;
  +         jndiBound = true;
  +      }
  +      finally {
  +         ic.close();
  +      }
  +      
         log.info("Bound to JNDI name: " + jndiName);
      }
      
      /**
  -   * Gets the JNDI name use by this topic
  -   * @return  The JNDI name currently in use
  -   */
  +    * Gets the JNDI name use by this topic
  +    * 
  +    * @return  The JNDI name currently in use
  +    */
      public String getJNDIName(){
         return jndiName;
      }
  -
   }
  
  
  

_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development

Reply via email to