View Javadoc

    1   /***
    2    *
    3    * Copyright 2004 Protique Ltd
    4    *
    5    * Licensed under the Apache License, Version 2.0 (the "License");
    6    * you may not use this file except in compliance with the License.
    7    * You may obtain a copy of the License at
    8    *
    9    * http://www.apache.org/licenses/LICENSE-2.0
    10   *
    11   * Unless required by applicable law or agreed to in writing, software
    12   * distributed under the License is distributed on an "AS IS" BASIS,
    13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14   * See the License for the specific language governing permissions and
    15   * limitations under the License.
    16   *
    17   **/
    18  package org.codehaus.activemq.service.impl;
    19
    20  import EDU.oswego.cs.dl.util.concurrent.ConcurrentHashMap;
    21  import org.codehaus.activemq.service.Dispatcher;
    22  import org.codehaus.activemq.service.MessageContainer;
    23  import org.codehaus.activemq.service.MessageContainerManager;
    24
    25  import javax.jms.JMSException;
    26  import java.util.Iterator;
    27  import java.util.Map;
    28
    29  /***
    30   * @version $Revision: 1.1 $
    31   */
    32  public abstract class MessageContainerManagerSupport implements MessageContainerManager {
    33      protected Dispatcher dispatcher;
    34      protected Map messageContainers = new ConcurrentHashMap();
    35
    36      public MessageContainerManagerSupport(Dispatcher dispatcher) {
    37          this.dispatcher = dispatcher;
    38          dispatcher.register(this);
    39      }
    40
    41      /***
    42       * start the broker
    43       *
    44       * @throws javax.jms.JMSException
    45       */
    46      public void start() throws JMSException {
    47          dispatcher.start();
    48      }
    49
    50      /***
    51       * stop the broker
    52       *
    53       * @throws javax.jms.JMSException
    54       */
    55      public void stop() throws JMSException {
    56          dispatcher.stop();
    57          JMSException firstException = null;
    58          try {
    59              dispatcher.stop();
    60          }
    61          catch (JMSException e) {
    62              firstException = e;
    63          }
    64
    65          // lets stop all the containers
    66          for (Iterator iter = messageContainers.values().iterator(); iter.hasNext();) {
    67              MessageContainer container = (MessageContainer) iter.next();
    68              try {
    69                  container.stop();
    70              }
    71              catch (JMSException e) {
    72                  if (firstException == null) {
    73                      firstException = e;
    74                  }
    75              }
    76          }
    77          if (firstException != null) {
    78              throw firstException;
    79          }
    80
    81      }
    82  }