|
|||||||||||||||||||
| Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
| ResinRun.java | - | 0% | 0% | 0% |
|
||||||||||||||
| 1 |
/*
|
|
| 2 |
* ====================================================================
|
|
| 3 |
*
|
|
| 4 |
* The Apache Software License, Version 1.1
|
|
| 5 |
*
|
|
| 6 |
* Copyright (c) 2001-2003 The Apache Software Foundation. All rights
|
|
| 7 |
* reserved.
|
|
| 8 |
*
|
|
| 9 |
* Redistribution and use in source and binary forms, with or without
|
|
| 10 |
* modification, are permitted provided that the following conditions
|
|
| 11 |
* are met:
|
|
| 12 |
*
|
|
| 13 |
* 1. Redistributions of source code must retain the above copyright
|
|
| 14 |
* notice, this list of conditions and the following disclaimer.
|
|
| 15 |
*
|
|
| 16 |
* 2. Redistributions in binary form must reproduce the above copyright
|
|
| 17 |
* notice, this list of conditions and the following disclaimer in
|
|
| 18 |
* the documentation and/or other materials provided with the
|
|
| 19 |
* distribution.
|
|
| 20 |
*
|
|
| 21 |
* 3. The end-user documentation included with the redistribution, if
|
|
| 22 |
* any, must include the following acknowlegement:
|
|
| 23 |
* "This product includes software developed by the
|
|
| 24 |
* Apache Software Foundation (http://www.apache.org/)."
|
|
| 25 |
* Alternately, this acknowlegement may appear in the software itself,
|
|
| 26 |
* if and wherever such third-party acknowlegements normally appear.
|
|
| 27 |
*
|
|
| 28 |
* 4. The names "The Jakarta Project", "Cactus" and "Apache Software
|
|
| 29 |
* Foundation" must not be used to endorse or promote products
|
|
| 30 |
* derived from this software without prior written permission. For
|
|
| 31 |
* written permission, please contact apache@apache.org.
|
|
| 32 |
*
|
|
| 33 |
* 5. Products derived from this software may not be called "Apache"
|
|
| 34 |
* nor may "Apache" appear in their names without prior written
|
|
| 35 |
* permission of the Apache Group.
|
|
| 36 |
*
|
|
| 37 |
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
|
|
| 38 |
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
| 39 |
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
| 40 |
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
|
|
| 41 |
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
| 42 |
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
| 43 |
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
|
| 44 |
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
| 45 |
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
| 46 |
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
|
| 47 |
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
| 48 |
* SUCH DAMAGE.
|
|
| 49 |
* ====================================================================
|
|
| 50 |
*
|
|
| 51 |
* This software consists of voluntary contributions made by many
|
|
| 52 |
* individuals on behalf of the Apache Software Foundation. For more
|
|
| 53 |
* information on the Apache Software Foundation, please see
|
|
| 54 |
* <http://www.apache.org/>.
|
|
| 55 |
*
|
|
| 56 |
*/
|
|
| 57 |
package org.apache.cactus.integration.ant.container.resin;
|
|
| 58 |
|
|
| 59 |
import java.lang.reflect.Constructor;
|
|
| 60 |
import java.lang.reflect.Method;
|
|
| 61 |
import java.util.ArrayList;
|
|
| 62 |
|
|
| 63 |
import org.apache.cactus.integration.ant.container.AbstractServerRun;
|
|
| 64 |
|
|
| 65 |
/**
|
|
| 66 |
* Starts/stop Resin by setting up a listener socket.
|
|
| 67 |
*
|
|
| 68 |
* @author <a href="mailto:vmassol@apache.org">Vincent Massol</a>
|
|
| 69 |
* @author <a href="mailto:digital@ix.net.au">Robert Leftwich</a>
|
|
| 70 |
*
|
|
| 71 |
* @version $Id: ResinRun.java,v 1.4 2003/05/26 09:42:59 cmlenz Exp $
|
|
| 72 |
* @see AbstractServerRun
|
|
| 73 |
*/
|
|
| 74 |
public class ResinRun extends AbstractServerRun |
|
| 75 |
{
|
|
| 76 |
/**
|
|
| 77 |
* The started Resin server class. We use <code>Object</code> instead of
|
|
| 78 |
* the Resin class so that we don't need the Resin jars in the classpath
|
|
| 79 |
* to compile this class.
|
|
| 80 |
*/
|
|
| 81 |
private Object resinServer;
|
|
| 82 |
|
|
| 83 |
/**
|
|
| 84 |
* @param theArgs the command line arguments
|
|
| 85 |
*/
|
|
| 86 | 0 |
public ResinRun(String[] theArgs)
|
| 87 |
{
|
|
| 88 | 0 |
super(theArgs);
|
| 89 |
} |
|
| 90 |
|
|
| 91 |
/**
|
|
| 92 |
* Entry point to start/stop the Resin server.
|
|
| 93 |
*
|
|
| 94 |
* @param theArgs the command line arguments
|
|
| 95 |
*/
|
|
| 96 | 0 |
public static void main(String[] theArgs) |
| 97 |
{
|
|
| 98 | 0 |
ResinRun resin = new ResinRun(theArgs);
|
| 99 |
|
|
| 100 | 0 |
resin.doRun(); |
| 101 |
} |
|
| 102 |
|
|
| 103 |
/**
|
|
| 104 |
* Start the Resin server. We use reflection so that the Resin jars do not
|
|
| 105 |
* need to be in the classpath to compile this class.
|
|
| 106 |
*
|
|
| 107 |
* @see AbstractServerRun#doStartServer
|
|
| 108 |
*/
|
|
| 109 | 0 |
protected final void doStartServer(String[] theArgs) |
| 110 |
{
|
|
| 111 | 0 |
try
|
| 112 |
{
|
|
| 113 | 0 |
Class resinClass = |
| 114 |
Class.forName("com.caucho.server.http.ResinServer");
|
|
| 115 | 0 |
Constructor constructor = resinClass.getConstructor( |
| 116 |
new Class[] {theArgs.getClass(), boolean.class}); |
|
| 117 |
|
|
| 118 | 0 |
this.resinServer = constructor.newInstance(
|
| 119 |
new Object[] {theArgs, Boolean.TRUE});
|
|
| 120 |
|
|
| 121 |
// Try Resin 2.0 first
|
|
| 122 | 0 |
try
|
| 123 |
{
|
|
| 124 | 0 |
startResin20(this.resinServer);
|
| 125 |
} |
|
| 126 |
catch (NoSuchMethodException nsme)
|
|
| 127 |
{
|
|
| 128 |
// Try Resin 2.1
|
|
| 129 | 0 |
startResin21(this.resinServer);
|
| 130 |
} |
|
| 131 |
} |
|
| 132 |
catch (Exception e)
|
|
| 133 |
{
|
|
| 134 | 0 |
e.printStackTrace(); |
| 135 | 0 |
throw new RuntimeException("Cannot create instance of ResinServer"); |
| 136 |
} |
|
| 137 |
} |
|
| 138 |
|
|
| 139 |
/**
|
|
| 140 |
* Starts Resin 2.0.x
|
|
| 141 |
*
|
|
| 142 |
* @param theResinServer the <code>ResinServer</code> instance
|
|
| 143 |
* @throws Exception if an error happens when starting the server
|
|
| 144 |
*/
|
|
| 145 | 0 |
private void startResin20(Object theResinServer) throws Exception |
| 146 |
{
|
|
| 147 | 0 |
Method initMethod = theResinServer.getClass().getMethod("init",
|
| 148 |
new Class[] {boolean.class}); |
|
| 149 |
|
|
| 150 | 0 |
initMethod.invoke(theResinServer, new Object[] {Boolean.TRUE});
|
| 151 |
} |
|
| 152 |
|
|
| 153 |
/**
|
|
| 154 |
* Starts Resin 2.1.x
|
|
| 155 |
*
|
|
| 156 |
* @param theResinServer the <code>ResinServer</code> instance
|
|
| 157 |
* @throws Exception if an error happens when starting the server
|
|
| 158 |
*/
|
|
| 159 | 0 |
private void startResin21(Object theResinServer) throws Exception |
| 160 |
{
|
|
| 161 | 0 |
Method initMethod = theResinServer.getClass().getMethod("init",
|
| 162 |
new Class[] {ArrayList.class}); |
|
| 163 |
|
|
| 164 | 0 |
initMethod.invoke(theResinServer, new Object[] {null}); |
| 165 |
} |
|
| 166 |
|
|
| 167 |
/**
|
|
| 168 |
* Stops the Resin server. We use reflection so that the Resin jars do not
|
|
| 169 |
* need to be in the classpath to compile this class.
|
|
| 170 |
*
|
|
| 171 |
* @see AbstractServerRun#doStopServer
|
|
| 172 |
*/
|
|
| 173 | 0 |
protected final void doStopServer(String[] theArgs) |
| 174 |
{
|
|
| 175 | 0 |
try
|
| 176 |
{
|
|
| 177 | 0 |
Method closeMethod = this.resinServer.getClass().getMethod(
|
| 178 |
"close", null); |
|
| 179 |
|
|
| 180 | 0 |
closeMethod.invoke(this.resinServer, null); |
| 181 |
} |
|
| 182 |
catch (Exception e)
|
|
| 183 |
{
|
|
| 184 | 0 |
e.printStackTrace(); |
| 185 | 0 |
throw new RuntimeException("Cannot stop running instance of " |
| 186 |
+ "ResinServer");
|
|
| 187 |
} |
|
| 188 |
} |
|
| 189 |
} |
|
| 190 |
|
|
||||||||||