001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */package org.apache.openejb.server.activemq;
017:
018: import org.apache.activemq.broker.BrokerService;
019: import org.apache.openejb.server.SelfManaging;
020: import org.apache.openejb.server.ServerService;
021: import org.apache.openejb.server.ServiceException;
022:
023: import java.io.IOException;
024: import java.io.InputStream;
025: import java.io.OutputStream;
026: import java.net.InetAddress;
027: import java.net.Socket;
028: import java.net.URI;
029: import java.util.Properties;
030:
031: /**
032: * @version $Rev: 607077 $ $Date: 2007-12-27 06:55:23 -0800 $
033: */
034: public class BrokerServer implements ServerService, SelfManaging {
035: private BrokerService broker;
036:
037: private int port = 1527;
038: private boolean disabled;
039: private InetAddress host;
040:
041: public void init(Properties properties) throws Exception {
042: String port = properties.getProperty("port", "1527");
043: String bind = properties.getProperty("bind");
044: String disabled = properties.getProperty("disabled");
045: this .port = Integer.parseInt(port);
046: this .disabled = Boolean.parseBoolean(disabled);
047: host = InetAddress.getByName(bind);
048:
049: if (this .disabled) {
050: return;
051: }
052: URI uri = new URI("tcp", null, bind, this .port, null, null,
053: null);
054:
055: broker = new BrokerService();
056: broker.setPersistent(false);
057: broker.addConnector(uri);
058: }
059:
060: public void start() throws ServiceException {
061: if (disabled)
062: return;
063: try {
064: broker.start();
065: } catch (Exception e) {
066: throw new ServiceException(e);
067: }
068: }
069:
070: public void stop() throws ServiceException {
071: if (broker == null) {
072: return;
073: }
074: try {
075: broker.stop();
076: } catch (Exception e) {
077: throw new ServiceException(e);
078: } finally {
079: broker = null;
080: }
081: }
082:
083: public void service(InputStream inputStream,
084: OutputStream outputStream) throws ServiceException,
085: IOException {
086: }
087:
088: public void service(Socket socket) throws ServiceException,
089: IOException {
090: }
091:
092: public String getName() {
093: return "activemq";
094: }
095:
096: public String getIP() {
097: return host.getHostAddress();
098: }
099:
100: public int getPort() {
101: return port;
102: }
103:
104: }
|