View Javadoc

    1   /***
    2    *
    3    * Copyright 2004 Hiram Chirino
    4    * Copyright 2004 Protique Ltd
    5    *
    6    * Licensed under the Apache License, Version 2.0 (the "License");
    7    * you may not use this file except in compliance with the License.
    8    * You may obtain a copy of the License at
    9    *
    10   * http://www.apache.org/licenses/LICENSE-2.0
    11   *
    12   * Unless required by applicable law or agreed to in writing, software
    13   * distributed under the License is distributed on an "AS IS" BASIS,
    14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    15   * See the License for the specific language governing permissions and
    16   * limitations under the License.
    17   *
    18   **/
    19  package org.codehaus.activemq.transport.gnet;
    20
    21  import org.apache.geronimo.network.SelectorManager;
    22  import org.apache.geronimo.pool.ClockPool;
    23  import org.apache.geronimo.pool.ThreadPool;
    24  import org.codehaus.activemq.message.WireFormat;
    25  import org.codehaus.activemq.transport.TransportServerChannel;
    26  import org.codehaus.activemq.transport.TransportServerChannelFactory;
    27
    28  import javax.jms.JMSException;
    29  import java.net.URI;
    30
    31  /***
    32   * An implementation of a TransportServerChannelFactory which uses
    33   * the Geronimo network layer for connectivity.
    34   *
    35   * @version $Revision: 1.7 $
    36   */
    37  public class GTransportServerChannelFactory implements TransportServerChannelFactory {
    38
    39      private static ThreadPool threadPool;
    40      private static ClockPool clockPool;
    41      private static SelectorManager selectorManager;
    42
    43      static public void init(SelectorManager sm, ThreadPool tp,
    44                              ClockPool cp) throws IllegalArgumentException {
    45
    46          if (sm == null || tp == null || cp == null) {
    47              throw new IllegalArgumentException();
    48          }
    49
    50          selectorManager = sm;
    51          threadPool = tp;
    52          clockPool = cp;
    53      }
    54
    55      static private void init() throws Exception {
    56
    57          // Don't init if allready done.
    58          if (threadPool != null) {
    59              return;
    60          }
    61
    62          threadPool = new ThreadPool();
    63          threadPool.setKeepAliveTime(1 * 1000);
    64          threadPool.setPoolSize(5);
    65          threadPool.setPoolName("S Pool");
    66
    67          clockPool = new ClockPool();
    68          clockPool.setPoolName("S Clock");
    69
    70          selectorManager = new SelectorManager();
    71          selectorManager.setThreadPool(threadPool);
    72          selectorManager.setThreadName("S Manager");
    73          selectorManager.setTimeout(1000);
    74
    75          threadPool.doStart();
    76          clockPool.doStart();
    77          selectorManager.doStart();
    78
    79      }
    80
    81      /***
    82       * Bind a ServerChannel to an address
    83       *
    84       * @param wireFormat
    85       * @param bindAddress
    86       * @return the TransportChannel bound to the remote node
    87       * @throws JMSException
    88       */
    89      public TransportServerChannel create(WireFormat wireFormat, URI bindAddress) throws JMSException {
    90          try {
    91              init();
    92              return new GTransportServerChannel(wireFormat, bindAddress, selectorManager, threadPool, clockPool);
    93          }
    94          catch (Exception e) {
    95              e.printStackTrace();
    96              JMSException ex = new JMSException(e.getMessage());
    97              ex.setLinkedException(e);
    98              throw ex;
    99          }
    100     }
    101
    102 }