1 45 package org.openejb.server.admin; 46 47 import java.io.InputStream ; 48 import java.io.OutputStream ; 49 import java.net.ConnectException ; 50 import java.net.Socket ; 51 import java.net.URL ; 52 import java.util.Properties ; 53 54 import org.openejb.util.JarUtils; 55 56 59 public class Stop implements org.openejb.client.RequestMethods { 60 private static final String helpBase = "META-INF/org.openejb.cli/"; 61 62 67 public static void stop(String host, int port) { 68 try{ 69 70 Socket socket = new Socket (host, port); 71 OutputStream out = socket.getOutputStream(); 72 73 out.write( STOP_REQUEST_Stop ); 74 75 } catch (ConnectException e){ 76 System.out.println(":: server not running ::"); 77 } catch (Exception e){ 78 e.printStackTrace(); 79 } 80 } 81 82 public void stop() { 83 stop("localhost",4200); 84 } 85 86 public static void main(String [] args) { 87 try { 88 89 String host = "localhost"; 91 92 int port = 4200; 94 95 for (int i=0; i < args.length; i++){ 96 if (args[i].equals("-h")){ 97 if (args.length > i+1 ) { 98 host = args[++i]; 99 } 100 } else if (args[i].equals("-p")){ 101 if (args.length > i+1 ) { 102 port = Integer.parseInt( args[++i] ); 103 } 104 } else if (args[i].equals("--help")){ 105 printHelp(); 106 return; 107 } else if (args[i].equals("-examples")){ 108 printExamples(); 109 return; 110 } 111 } 112 113 stop( host, port ); 114 } catch ( Exception re ) { 115 System.err.println("[EJB Server] FATAL ERROR: "+ re.getMessage()); 116 re.printStackTrace(); 117 } 118 } 119 120 private static void printHelp() { 121 String header = "OpenEJB Remote Server "; 122 try { 123 JarUtils.setHandlerSystemProperty(); 124 Properties versionInfo = new Properties (); 125 versionInfo.load( new URL ( "resource:/openejb-version.properties" ).openConnection().getInputStream() ); 126 header += versionInfo.get( "version" ); 127 } catch (java.io.IOException e) { 128 } 129 130 System.out.println( header ); 131 132 try { 134 InputStream in = Thread.currentThread().getContextClassLoader().getResource(helpBase + "stop.help").openConnection().getInputStream(); 135 136 int b = in.read(); 137 while (b != -1) { 138 System.out.write( b ); 139 b = in.read(); 140 } 141 } catch (java.io.IOException e) { 142 } 143 } 144 145 private static void printExamples() { 146 String header = "OpenEJB Remote Server "; 147 try { 148 JarUtils.setHandlerSystemProperty(); 149 Properties versionInfo = new Properties (); 150 versionInfo.load( new URL ( "resource:/openejb-version.properties" ).openConnection().getInputStream() ); 151 header += versionInfo.get( "version" ); 152 } catch (java.io.IOException e) { 153 } 154 155 System.out.println( header ); 156 157 try { 159 InputStream in = Thread.currentThread().getContextClassLoader().getResource(helpBase + "stop.examples").openConnection().getInputStream(); 160 161 int b = in.read(); 162 while (b != -1) { 163 System.out.write( b ); 164 b = in.read(); 165 } 166 } catch (java.io.IOException e) { 167 } 168 } 169 } 170 | Popular Tags |