|
|||||||||||||||||||
| 30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover | |||||||||||||||||||
| Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
| ResinRun.java | 0% | 0% | 0% | 0% |
|
||||||||||||||
| 1 |
/*
|
|
| 2 |
* ========================================================================
|
|
| 3 |
*
|
|
| 4 |
* Copyright 2001-2004 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.resin;
|
|
| 21 |
|
|
| 22 |
import java.lang.reflect.Constructor;
|
|
| 23 |
import java.lang.reflect.Field;
|
|
| 24 |
import java.lang.reflect.Method;
|
|
| 25 |
import java.util.ArrayList;
|
|
| 26 |
|
|
| 27 |
import org.apache.cactus.integration.ant.container.AbstractServerRun;
|
|
| 28 |
|
|
| 29 |
/**
|
|
| 30 |
* Starts/stop Resin by setting up a listener socket. Supports Resin 2.0.x,
|
|
| 31 |
* 2.1.x and 3.x.
|
|
| 32 |
*
|
|
| 33 |
* @version $Id: ResinRun.java 238918 2004-04-18 12:21:50Z vmassol $
|
|
| 34 |
*/
|
|
| 35 |
public class ResinRun extends AbstractServerRun |
|
| 36 |
{
|
|
| 37 |
/**
|
|
| 38 |
* The started Resin server class. We use <code>Object</code> instead of
|
|
| 39 |
* the Resin class so that we don't need the Resin jars in the classpath
|
|
| 40 |
* to compile this class.
|
|
| 41 |
*/
|
|
| 42 |
private Object resinServer;
|
|
| 43 |
|
|
| 44 |
/**
|
|
| 45 |
* @param theArgs the command line arguments
|
|
| 46 |
*/
|
|
| 47 | 0 |
public ResinRun(String[] theArgs)
|
| 48 |
{
|
|
| 49 | 0 |
super(theArgs);
|
| 50 |
} |
|
| 51 |
|
|
| 52 |
/**
|
|
| 53 |
* Entry point to start/stop the Resin server.
|
|
| 54 |
*
|
|
| 55 |
* @param theArgs the command line arguments
|
|
| 56 |
*/
|
|
| 57 | 0 |
public static void main(String[] theArgs) |
| 58 |
{
|
|
| 59 | 0 |
ResinRun resin = new ResinRun(theArgs);
|
| 60 |
|
|
| 61 | 0 |
resin.doRun(); |
| 62 |
} |
|
| 63 |
|
|
| 64 |
/**
|
|
| 65 |
* Start the Resin server. We use reflection so that the Resin jars do not
|
|
| 66 |
* need to be in the classpath to compile this class.
|
|
| 67 |
*
|
|
| 68 |
* @see AbstractServerRun#doStartServer
|
|
| 69 |
*/
|
|
| 70 | 0 |
protected final Thread doStartServer(String[] theArgs)
|
| 71 |
{
|
|
| 72 | 0 |
Thread runningThread = this;
|
| 73 |
|
|
| 74 | 0 |
try
|
| 75 |
{
|
|
| 76 | 0 |
if (isResinVersion("2.0")) |
| 77 |
{
|
|
| 78 | 0 |
startResin20x(theArgs); |
| 79 |
} |
|
| 80 | 0 |
else if (isResinVersion("2.1")) |
| 81 |
{
|
|
| 82 | 0 |
startResin21x(theArgs); |
| 83 |
} |
|
| 84 | 0 |
else if (isResinVersion("3")) |
| 85 |
{
|
|
| 86 | 0 |
runningThread = startResin3x(theArgs); |
| 87 |
} |
|
| 88 |
else
|
|
| 89 |
{
|
|
| 90 | 0 |
throw new RuntimeException("Unsupported Resin version [" |
| 91 |
+ getResinVersion() + "]");
|
|
| 92 |
} |
|
| 93 |
} |
|
| 94 |
catch (Exception e)
|
|
| 95 |
{
|
|
| 96 | 0 |
e.printStackTrace(); |
| 97 | 0 |
throw new RuntimeException("Failed to start Resin server"); |
| 98 |
} |
|
| 99 |
|
|
| 100 | 0 |
return runningThread;
|
| 101 |
} |
|
| 102 |
|
|
| 103 |
/**
|
|
| 104 |
* Starts Resin 2.0.x
|
|
| 105 |
*
|
|
| 106 |
* @param theArgs the command line arguments for starting the server
|
|
| 107 |
* @throws Exception if an error happens when starting the server
|
|
| 108 |
*/
|
|
| 109 | 0 |
private void startResin20x(String[] theArgs) throws Exception |
| 110 |
{
|
|
| 111 | 0 |
Class resinClass = |
| 112 |
Class.forName("com.caucho.server.http.ResinServer");
|
|
| 113 | 0 |
Constructor constructor = resinClass.getConstructor( |
| 114 |
new Class[] {theArgs.getClass(), boolean.class}); |
|
| 115 |
|
|
| 116 | 0 |
this.resinServer = constructor.newInstance(
|
| 117 |
new Object[] {theArgs, Boolean.TRUE});
|
|
| 118 |
|
|
| 119 | 0 |
Method initMethod = this.resinServer.getClass().getMethod("init", |
| 120 |
new Class[] {boolean.class}); |
|
| 121 |
|
|
| 122 | 0 |
initMethod.invoke(this.resinServer, new Object[] {Boolean.TRUE}); |
| 123 |
} |
|
| 124 |
|
|
| 125 |
/**
|
|
| 126 |
* Starts Resin 2.1.x
|
|
| 127 |
*
|
|
| 128 |
* @param theArgs the command line arguments for starting the server
|
|
| 129 |
* @throws Exception if an error happens when starting the server
|
|
| 130 |
*/
|
|
| 131 | 0 |
private void startResin21x(String[] theArgs) throws Exception |
| 132 |
{
|
|
| 133 | 0 |
Class resinClass = |
| 134 |
Class.forName("com.caucho.server.http.ResinServer");
|
|
| 135 | 0 |
Constructor constructor = resinClass.getConstructor( |
| 136 |
new Class[] {theArgs.getClass(), boolean.class}); |
|
| 137 |
|
|
| 138 | 0 |
this.resinServer = constructor.newInstance(
|
| 139 |
new Object[] {theArgs, Boolean.TRUE});
|
|
| 140 |
|
|
| 141 | 0 |
Method initMethod = this.resinServer.getClass().getMethod("init", |
| 142 |
new Class[] {ArrayList.class}); |
|
| 143 |
|
|
| 144 | 0 |
initMethod.invoke(this.resinServer, new Object[] {null}); |
| 145 |
} |
|
| 146 |
|
|
| 147 |
/**
|
|
| 148 |
* Starts Resin 3.x
|
|
| 149 |
*
|
|
| 150 |
* @return the thread in which the server has been started
|
|
| 151 |
* @param theArgs the command line arguments for starting the server
|
|
| 152 |
* @throws Exception if an error happens when starting the server
|
|
| 153 |
*/
|
|
| 154 | 0 |
private Thread startResin3x(final String[] theArgs) throws Exception |
| 155 |
{
|
|
| 156 |
// Start the server in another thread so that it doesn't block
|
|
| 157 |
// the current thread. It seems that Resin 3.x is acting differently
|
|
| 158 |
// than Resin 2.x which was not blocking and thus which did not need
|
|
| 159 |
// to be started in a separate thread.
|
|
| 160 | 0 |
Thread startThread = new Thread()
|
| 161 |
{
|
|
| 162 | 0 |
public void run() |
| 163 |
{
|
|
| 164 | 0 |
try
|
| 165 |
{
|
|
| 166 | 0 |
Class resinClass = |
| 167 |
Class.forName("com.caucho.server.http.ResinServer");
|
|
| 168 |
|
|
| 169 | 0 |
Method mainMethod = resinClass.getMethod("main",
|
| 170 |
new Class[] {String[].class}); |
|
| 171 |
|
|
| 172 | 0 |
mainMethod.invoke(null, new Object[] {theArgs}); |
| 173 |
} |
|
| 174 |
catch (Exception e)
|
|
| 175 |
{
|
|
| 176 | 0 |
e.printStackTrace(); |
| 177 | 0 |
throw new RuntimeException( |
| 178 |
"Failed to start Resin 3.x. Error = ["
|
|
| 179 |
+ e.getMessage() + "]");
|
|
| 180 |
} |
|
| 181 |
} |
|
| 182 |
}; |
|
| 183 | 0 |
startThread.start(); |
| 184 |
|
|
| 185 | 0 |
return startThread;
|
| 186 |
} |
|
| 187 |
|
|
| 188 |
/**
|
|
| 189 |
* Stops the Resin server. We use reflection so that the Resin jars do not
|
|
| 190 |
* need to be in the classpath to compile this class.
|
|
| 191 |
*
|
|
| 192 |
* @see AbstractServerRun#doStopServer
|
|
| 193 |
*/
|
|
| 194 | 0 |
protected final void doStopServer(String[] theArgs, |
| 195 |
Thread theRunningServerThread) |
|
| 196 |
{
|
|
| 197 | 0 |
try
|
| 198 |
{
|
|
| 199 | 0 |
if (isResinVersion("2.0")) |
| 200 |
{
|
|
| 201 | 0 |
stopResin20x(theArgs); |
| 202 |
} |
|
| 203 | 0 |
else if (isResinVersion("2.1")) |
| 204 |
{
|
|
| 205 | 0 |
stopResin20x(theArgs); |
| 206 |
} |
|
| 207 | 0 |
else if (isResinVersion("3")) |
| 208 |
{
|
|
| 209 | 0 |
stopResin3x(theArgs, theRunningServerThread); |
| 210 |
} |
|
| 211 |
else
|
|
| 212 |
{
|
|
| 213 | 0 |
throw new RuntimeException("Unsupported Resin version [" |
| 214 |
+ getResinVersion() + "]");
|
|
| 215 |
} |
|
| 216 |
} |
|
| 217 |
catch (Exception e)
|
|
| 218 |
{
|
|
| 219 | 0 |
e.printStackTrace(); |
| 220 | 0 |
throw new RuntimeException( |
| 221 |
"Failed to stop the running Resin server");
|
|
| 222 |
} |
|
| 223 |
} |
|
| 224 |
|
|
| 225 |
/**
|
|
| 226 |
* Stops Resin 2.0.x and 2.1.x versions.
|
|
| 227 |
*
|
|
| 228 |
* @param theArgs the command line arguments for starting the server
|
|
| 229 |
* @throws Exception if an error happens when starting the server
|
|
| 230 |
*/
|
|
| 231 | 0 |
private void stopResin20x(String[] theArgs) throws Exception |
| 232 |
{
|
|
| 233 | 0 |
Method closeMethod = this.resinServer.getClass().getMethod(
|
| 234 |
"close", null); |
|
| 235 |
|
|
| 236 | 0 |
closeMethod.invoke(this.resinServer, null); |
| 237 |
} |
|
| 238 |
|
|
| 239 |
/**
|
|
| 240 |
* Stops Resin 3.x.
|
|
| 241 |
*
|
|
| 242 |
* @param theArgs the command line arguments for starting the server
|
|
| 243 |
* @param theRunningServerThread the thread in which the server is running
|
|
| 244 |
* @throws Exception if an error happens when starting the server
|
|
| 245 |
*/
|
|
| 246 | 0 |
private void stopResin3x(String[] theArgs, |
| 247 |
Thread theRunningServerThread) throws Exception
|
|
| 248 |
{
|
|
| 249 |
// As we don't know how to properly stop a running Resin server,
|
|
| 250 |
// we simply try to kill the thread in which it is running.
|
|
| 251 |
// Not clean...
|
|
| 252 | 0 |
theRunningServerThread.stop(); |
| 253 |
} |
|
| 254 |
|
|
| 255 |
/**
|
|
| 256 |
* @return the Resin version
|
|
| 257 |
*/
|
|
| 258 | 0 |
private String getResinVersion()
|
| 259 |
{
|
|
| 260 | 0 |
String version; |
| 261 |
|
|
| 262 | 0 |
try
|
| 263 |
{
|
|
| 264 | 0 |
Class versionClass = Class.forName("com.caucho.Version");
|
| 265 | 0 |
Field versionField = versionClass.getField("VERSION");
|
| 266 | 0 |
version = (String) versionField.get(null);
|
| 267 |
} |
|
| 268 |
catch (Exception e)
|
|
| 269 |
{
|
|
| 270 | 0 |
throw new RuntimeException("Cannot get Resin version. Error = [" |
| 271 |
+ e.getMessage() + "]");
|
|
| 272 |
} |
|
| 273 |
|
|
| 274 | 0 |
return version;
|
| 275 |
} |
|
| 276 |
|
|
| 277 |
/**
|
|
| 278 |
* @param theVersionPrefix the version prefix to test for
|
|
| 279 |
* @return true if the Resin version starts with versionPrefix
|
|
| 280 |
*/
|
|
| 281 | 0 |
private boolean isResinVersion(String theVersionPrefix) |
| 282 |
{
|
|
| 283 | 0 |
return getResinVersion().startsWith(theVersionPrefix);
|
| 284 |
} |
|
| 285 |
} |
|
| 286 |
|
|
||||||||||