01: /*
02: * ========================================================================
03: *
04: * Copyright 2001-2003 The Apache Software Foundation.
05: *
06: * Licensed under the Apache License, Version 2.0 (the "License");
07: * you may not use this file except in compliance with the License.
08: * You may obtain a copy of the License at
09: *
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: */
20: package org.apache.cactus.integration.ant.container.enhydra;
21:
22: import java.lang.reflect.Method;
23:
24: import org.apache.cactus.integration.ant.container.AbstractServerRun;
25:
26: /**
27: * Starts/stop Enhydra by setting up a listener socket.
28: *
29: * @version $Id: EnhydraRun.java 238918 2004-04-18 12:21:50Z vmassol $
30: * @see AbstractServerRun
31: */
32: public class EnhydraRun extends AbstractServerRun {
33: /**
34: * @param theArgs the command line arguments
35: */
36: public EnhydraRun(String[] theArgs) {
37: super (theArgs);
38: }
39:
40: /**
41: * Entry point to start/stop the Enhydra server.
42: *
43: * @param theArgs the command line arguments
44: */
45: public static void main(String[] theArgs) {
46: EnhydraRun enhydra = new EnhydraRun(theArgs);
47:
48: enhydra.doRun();
49: }
50:
51: /**
52: * Start the Enhydra server. We use reflection so that the Enhydra jars do
53: * not need to be in the classpath to compile this class.
54: *
55: * @see AbstractServerRun#doStartServer
56: */
57: protected final Thread doStartServer(String[] theArgs) {
58: try {
59: Class enhydraClass = Class
60: .forName("com.lutris.multiServer.MultiServer");
61: Method initMethod = enhydraClass.getMethod("main",
62: new Class[] { theArgs.getClass() });
63:
64: initMethod.invoke(null, new Object[] { theArgs });
65: } catch (Exception e) {
66: e.printStackTrace();
67: throw new RuntimeException(
68: "Cannot create instance of MultiServer");
69: }
70:
71: return this ;
72: }
73:
74: /**
75: * Stops the Enhydra server. We use reflection so that the Enhydra jars do
76: * not need to be in the classpath to compile this class.
77: *
78: * @see AbstractServerRun#doStopServer
79: */
80: protected final void doStopServer(String[] theArgs,
81: Thread theRunningServerThread) throws Exception {
82: try {
83: Class enhydraClass = Class
84: .forName("com.lutris.multiServer.MultiServer");
85: Method shutDownMethod = enhydraClass.getMethod("shutdown",
86: null);
87:
88: shutDownMethod.invoke(null, null);
89: } catch (Exception e) {
90: e.printStackTrace();
91: throw new RuntimeException(
92: "Cannot stop running instance of " + "MultiServer");
93: }
94: }
95: }
|