Home » openejb-3.1.2-src » org.apache » openejb » server » activemq » [javadoc | source]

    1   /**
    2    * Licensed to the Apache Software Foundation (ASF) under one or more
    3    * contributor license agreements.  See the NOTICE file distributed with
    4    * this work for additional information regarding copyright ownership.
    5    * The ASF licenses this file to You under the Apache License, Version 2.0
    6    * (the "License"); you may not use this file except in compliance with
    7    * the License.  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   package org.apache.openejb.server.activemq;
   18   
   19   import org.apache.activemq.broker.BrokerService;
   20   import org.apache.openejb.server.SelfManaging;
   21   import org.apache.openejb.server.ServerService;
   22   import org.apache.openejb.server.ServiceException;
   23   
   24   import java.io.IOException;
   25   import java.io.InputStream;
   26   import java.io.OutputStream;
   27   import java.net.InetAddress;
   28   import java.net.Socket;
   29   import java.net.URI;
   30   import java.util.Properties;
   31   
   32   /**
   33    * @version $Rev: 607077 $ $Date: 2007-12-27 06:55:23 -0800 (Thu, 27 Dec 2007) $
   34    */
   35   public class BrokerServer implements ServerService, SelfManaging {
   36       private BrokerService broker;
   37   
   38       private int port = 1527;
   39       private boolean disabled;
   40       private InetAddress host;
   41   
   42       public void init(Properties properties) throws Exception {
   43           String port = properties.getProperty("port", "1527");
   44           String bind = properties.getProperty("bind");
   45           String disabled = properties.getProperty("disabled");
   46           this.port = Integer.parseInt(port);
   47           this.disabled = Boolean.parseBoolean(disabled);
   48           host = InetAddress.getByName(bind);
   49   
   50           if (this.disabled) {
   51               return;
   52           }
   53           URI uri = new URI("tcp", null, bind, this.port, null, null, null);
   54   
   55           broker = new BrokerService();
   56           broker.setPersistent(false);
   57           broker.addConnector(uri);
   58       }
   59   
   60       public void start() throws ServiceException {
   61           if (disabled) return;
   62           try {
   63               broker.start();
   64           } catch (Exception e) {
   65               throw new ServiceException(e);
   66           }
   67       }
   68   
   69       public void stop() throws ServiceException {
   70           if (broker == null) {
   71               return;
   72           }
   73           try {
   74               broker.stop();
   75           } catch (Exception e) {
   76               throw new ServiceException(e);
   77           } finally {
   78               broker = null;
   79           }
   80       }
   81   
   82       public void service(InputStream inputStream, OutputStream outputStream) throws ServiceException, IOException {
   83       }
   84   
   85       public void service(Socket socket) throws ServiceException, IOException {
   86       }
   87   
   88       public String getName() {
   89           return "activemq";
   90       }
   91   
   92       public String getIP() {
   93           return host.getHostAddress();
   94       }
   95   
   96       public int getPort() {
   97           return port;
   98       }
   99   
  100   }

Home » openejb-3.1.2-src » org.apache » openejb » server » activemq » [javadoc | source]