Don't you have to call process.destroy() when you shutdown.
On Wed, Mar 23, 2011 at 5:30 PM, Chamara Silva <[email protected]> wrote: > I have wrote java class to start Axis2Server programatically. It started > properly and issue is it didn't stop either i destroy relevant process. > please help. > > Thank you, > Chamara Silva > > /* > *Copyright (c) 2005-2010, WSO2 Inc. (http://www.wso2.org) All Rights > Reserved. > * > *WSO2 Inc. licenses this file to you under the Apache License, > *Version 2.0 (the "License"); you may not use this file except > *in compliance with the License. > *You may obtain a copy of the License at > * > *http://www.apache.org/licenses/LICENSE-2.0 > * > *Unless required by applicable law or agreed to in writing, > *software distributed under the License is distributed on an > *"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY > *KIND, either express or implied. See the License for the > *specific language governing permissions and limitations > *under the License. > */ > package org.wso2.carbon.integration.core; > > import org.wso2.carbon.base.ServerConfigurationException; > import org.wso2.carbon.utils.ServerConstants; > > import java.io.BufferedReader; > import java.io.File; > import java.io.IOException; > import java.io.InputStreamReader; > > /** > * > */ > public class SimpleAxis2ServerManager { > public static Process processAxisServer; > private static Thread runnable; > private static String originalUserDir = null; > > private final static String SERVER_STARTUP_MESSAGE = "HTTP Listener > started"; > private final static String SERVER_SHUTDOWN_MESSAGE = "HTTP Sender > Shutdown"; > private final static long DEFAULT_START_STOP_WAIT_MS = 1000 * 60 * 4; > > > public synchronized static void startServer(String carbonHome) > throws ServerConfigurationException, InterruptedException { > if (processAxisServer != null) { // An instance of the server is > running > return; > } > Process tempProcess; > try { > System.setProperty(ServerConstants.CARBON_HOME, carbonHome); > originalUserDir = System.getProperty("user.dir"); > System.setProperty("user.dir", carbonHome); > System.out.println("Importing Code Coverage Details..."); > String temp; > if > (System.getProperty("os.name").toLowerCase().contains("windows")) > { > tempProcess = Runtime.getRuntime().exec(new String[]{"bat", > "samples/axis2Server/axis2server.bat"}, > null, new > File(carbonHome)); > } else { > tempProcess = Runtime.getRuntime().exec(new String[]{"sh", > "samples/axis2Server/axis2server.sh"}, > null, new > File(carbonHome)); > } > Runtime.getRuntime().addShutdownHook(new Thread() { > public void run() { > try { > shutdown(); > } catch (Exception ignored) { > > } > } > }); > final BufferedReader reader = new BufferedReader( > new InputStreamReader(tempProcess.getInputStream())); > long time = System.currentTimeMillis() + > DEFAULT_START_STOP_WAIT_MS; > while ((temp = reader.readLine()) != null && > System.currentTimeMillis() < time) { > System.out.println(temp); > if (temp.contains(SERVER_STARTUP_MESSAGE)) { > runnable = new Thread() { > public void run() { > try { > String temp; > while ((temp = reader.readLine()) != null) > { > System.out.println(temp); > } > } catch (Exception ignore) { > > } > } > }; > runnable.start(); > break; > } > } > } catch (IOException e) { > throw new RuntimeException("Unable to start server", e); > } > processAxisServer = tempProcess; > System.out.println("Successfully started axis2 server. > Returning..."); > } > > public synchronized static void shutdown() throws Exception { > if (processAxisServer != null) { > // try { > String temp; > processAxisServer.destroy(); > // BufferedReader reader = new BufferedReader( > // new > InputStreamReader(processAxisServer.getInputStream())); > // long time = System.currentTimeMillis() + > DEFAULT_START_STOP_WAIT_MS; > // while ((temp = reader.readLine()) != null && > System.currentTimeMillis() < time) { > // if (temp.contains(SERVER_SHUTDOWN_MESSAGE)) { > // break; > // } > // } > > // } catch (IOException ignored) { > // } > try { > runnable.interrupt(); > } catch (Exception ignored) { > } > runnable = null; > processAxisServer = null; > System.out.println("Saving Code Coverage Details..."); > try { > Thread.sleep(1000); > } catch (InterruptedException ignored) { > } > System.out.println("Completed Saving Code Coverage Details."); > System.clearProperty(ServerConstants.CARBON_HOME); > System.setProperty("user.dir", originalUserDir); > } > } > > public static void main(String[] args) throws Exception { > System.out.println("Hello i am starting"); > > > startServer("/home/chamara/wso2/framework-migration/temp/wso2esb-4.0.0-SNAPSHOT"); > System.out.println("Hello chamara"); > shutdown(); > > } > public void AAAtest() throws Exception { > System.out.println("Hello i am starting"); > > > startServer("/home/chamara/wso2/framework-migration/temp/wso2esb-4.0.0-SNAPSHOT"); > System.out.println("Hello chamara"); > shutdown(); > } > } > > > > > -- > Suminda Chamara Silva > WSO2 Inc. > Mobile: +94 718 302858 > blog: http://chamaras.blogspot.com > > _______________________________________________ > Carbon-dev mailing list > [email protected] > http://mail.wso2.org/cgi-bin/mailman/listinfo/carbon-dev > > -- *Afkham Azeez* Senior Software Architect & Senior Manager; WSO2, Inc.; http://wso2.com, * * *Member; Apache Software Foundation; **http://www.apache.org/*<http://www.apache.org/> * email: **[email protected]* <[email protected]>* cell: +94 77 3320919 blog: **http://blog.afkham.org* <http://blog.afkham.org>* twitter: **http://twitter.com/afkham_azeez*<http://twitter.com/afkham_azeez> * linked-in: **http://lk.linkedin.com/in/afkhamazeez* * * *Lean . Enterprise . Middleware*
_______________________________________________ Carbon-dev mailing list [email protected] http://mail.wso2.org/cgi-bin/mailman/listinfo/carbon-dev
