KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cactus > integration > ant > container > enhydra > EnhydraRun


1 /*
2  * ========================================================================
3  *
4  * Copyright 2001-2003 The Apache Software Foundation.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
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 JavaDoc;
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,v 1.8 2004/04/18 12:21:50 vmassol Exp $
30  * @see AbstractServerRun
31  */

32 public class EnhydraRun extends AbstractServerRun
33 {
34     /**
35      * @param theArgs the command line arguments
36      */

37     public EnhydraRun(String JavaDoc[] theArgs)
38     {
39         super(theArgs);
40     }
41
42     /**
43      * Entry point to start/stop the Enhydra server.
44      *
45      * @param theArgs the command line arguments
46      */

47     public static void main(String JavaDoc[] theArgs)
48     {
49         EnhydraRun enhydra = new EnhydraRun(theArgs);
50
51         enhydra.doRun();
52     }
53
54     /**
55      * Start the Enhydra server. We use reflection so that the Enhydra jars do
56      * not need to be in the classpath to compile this class.
57      *
58      * @see AbstractServerRun#doStartServer
59      */

60     protected final Thread JavaDoc doStartServer(String JavaDoc[] theArgs)
61     {
62         try
63         {
64             Class JavaDoc enhydraClass =
65                 Class.forName("com.lutris.multiServer.MultiServer");
66             Method JavaDoc initMethod = enhydraClass.getMethod("main",
67                 new Class JavaDoc[] {theArgs.getClass()});
68
69             initMethod.invoke(null, new Object JavaDoc[] {theArgs});
70         }
71         catch (Exception JavaDoc e)
72         {
73             e.printStackTrace();
74             throw new RuntimeException JavaDoc("Cannot create instance of MultiServer");
75         }
76         
77         return this;
78     }
79
80     /**
81      * Stops the Enhydra server. We use reflection so that the Enhydra jars do
82      * not need to be in the classpath to compile this class.
83      *
84      * @see AbstractServerRun#doStopServer
85      */

86     protected final void doStopServer(String JavaDoc[] theArgs,
87         Thread JavaDoc theRunningServerThread) throws Exception JavaDoc
88     {
89         try
90         {
91             Class JavaDoc enhydraClass =
92                 Class.forName("com.lutris.multiServer.MultiServer");
93             Method JavaDoc shutDownMethod = enhydraClass.getMethod("shutdown", null);
94
95             shutDownMethod.invoke(null, null);
96         }
97         catch (Exception JavaDoc e)
98         {
99             e.printStackTrace();
100             throw new RuntimeException JavaDoc("Cannot stop running instance of "
101                 + "MultiServer");
102         }
103     }
104 }
105
Popular Tags