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.geronimo.openejb;
017:
018: import java.net.InetSocketAddress;
019: import java.util.Properties;
020:
021: import org.apache.geronimo.gbean.GBeanInfo;
022: import org.apache.geronimo.gbean.GBeanInfoBuilder;
023: import org.apache.geronimo.gbean.GBeanLifecycle;
024: import org.apache.geronimo.management.geronimo.NetworkConnector;
025: import org.apache.openejb.server.ServiceManager;
026: import org.apache.openejb.loader.SystemInstance;
027:
028: /**
029: * @version $Rev: 583409 $ $Date: 2007-10-10 02:38:51 -0700 (Wed, 10 Oct 2007) $
030: */
031: public class EjbDaemonGBean implements NetworkConnector, GBeanLifecycle {
032: private String host;
033: private int port;
034: private int threads;
035: private ServiceManager serviceManager;
036:
037: public EjbDaemonGBean() {
038: System.setProperty("openejb.nobanner", "true");
039: serviceManager = new ServiceManager();
040: }
041:
042: public String getProtocol() {
043: return "ejbd";
044: }
045:
046: public String getHost() {
047: return host;
048: }
049:
050: public void setHost(String host) {
051: this .host = host;
052: }
053:
054: public int getPort() {
055: return port;
056: }
057:
058: public void setPort(int port) {
059: this .port = port;
060: }
061:
062: public int getThreads() {
063: return threads;
064: }
065:
066: public void setThreads(int threads) {
067: this .threads = threads;
068: }
069:
070: public InetSocketAddress getListenAddress() {
071: return new InetSocketAddress(host, port);
072: }
073:
074: public void doStart() throws Exception {
075: Properties properties = SystemInstance.get().getProperties();
076: properties.setProperty("ejbd.bind", host);
077: properties.setProperty("ejbd.port", Integer.toString(port));
078: if (threads > 0) {
079: properties.setProperty("ejbd.threads", Integer
080: .toString(threads));
081: }
082:
083: serviceManager.init();
084: serviceManager.start(false);
085:
086: }
087:
088: public void doStop() throws Exception {
089: serviceManager.stop();
090: }
091:
092: public void doFail() {
093: }
094:
095: public static final GBeanInfo GBEAN_INFO;
096:
097: static {
098: GBeanInfoBuilder infoBuilder = GBeanInfoBuilder.createStatic(
099: "OpenEJB Daemon", EjbDaemonGBean.class);
100: infoBuilder.addAttribute("host", String.class, true);
101: infoBuilder.addAttribute("port", int.class, true);
102: infoBuilder.addAttribute("threads", int.class, true);
103:
104: GBEAN_INFO = infoBuilder.getBeanInfo();
105: }
106:
107: public static GBeanInfo getGBeanInfo() {
108: return GBEAN_INFO;
109: }
110: }
|