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.derbynet;
017:
018: import org.apache.derby.drda.NetworkServerControl;
019: import org.apache.log4j.Priority;
020: import org.apache.openejb.server.SelfManaging;
021: import org.apache.openejb.server.ServerService;
022: import org.apache.openejb.server.ServiceException;
023: import org.apache.openejb.util.Log4jPrintWriter;
024: import org.apache.openejb.loader.SystemInstance;
025:
026: import java.io.IOException;
027: import java.io.InputStream;
028: import java.io.OutputStream;
029: import java.io.PrintWriter;
030: import java.net.InetAddress;
031: import java.net.Socket;
032: import java.util.Properties;
033:
034: /**
035: * @version $Rev: 605052 $ $Date: 2007-12-17 16:24:24 -0800 $
036: */
037: public class DerbyNetworkService implements ServerService, SelfManaging {
038:
039: private NetworkServerControl serverControl;
040: private int port = 1527;
041: private int threads;
042: private boolean disabled;
043: private InetAddress host;
044:
045: public String getIP() {
046: return host.getHostAddress();
047: }
048:
049: public String getName() {
050: return "derbynet";
051: }
052:
053: public int getPort() {
054: return port;
055: }
056:
057: public void init(Properties properties) throws Exception {
058: String threads = properties.getProperty("threads", "20");
059: String port = properties.getProperty("port", "1527");
060: String bind = properties.getProperty("bind");
061: String disabled = properties.getProperty("disabled");
062: this .threads = Integer.parseInt(threads);
063: this .port = Integer.parseInt(port);
064: this .disabled = Boolean.parseBoolean(disabled);
065: host = InetAddress.getByName("0.0.0.0");
066: System.setProperty("derby.system.home", SystemInstance.get()
067: .getBase().getDirectory().getAbsolutePath());
068: }
069:
070: public void service(InputStream inputStream,
071: OutputStream outputStream) throws ServiceException,
072: IOException {
073: }
074:
075: public void service(Socket socket) throws ServiceException,
076: IOException {
077: }
078:
079: public void start() throws ServiceException {
080: if (disabled)
081: return;
082: try {
083: serverControl = new NetworkServerControl(host, port);
084: //serverControl.setMaxThreads(threads);
085:
086: serverControl.start(new Log4jPrintWriter("Derby",
087: Priority.INFO));
088: } catch (Exception e) {
089: throw new ServiceException(e);
090: }
091: }
092:
093: public void stop() throws ServiceException {
094: if (serverControl == null) {
095: return;
096: }
097: try {
098: serverControl.shutdown();
099: } catch (Exception e) {
100: throw new ServiceException(e);
101: } finally {
102: serverControl = null;
103: }
104: }
105:
106: }
|