1 28 29 package org.objectweb.carol.jtests.conform.util; 30 31 import java.io.BufferedWriter ; 32 import java.io.IOException ; 33 import java.io.OutputStreamWriter ; 34 import java.io.UnsupportedEncodingException ; 35 import java.net.Socket ; 36 import java.net.UnknownHostException ; 37 import java.util.Arrays ; 38 39 44 public class ProcessStopper { 45 46 49 private ProcessStopper() { 50 51 } 52 53 58 public static void main(String [] args) { 59 if (args.length != 1) { 60 throw new IllegalArgumentException ("expected the port number, but got: " + Arrays.asList(args)); 61 } 62 final int port = Integer.parseInt(args[0]); 63 final String host = "localhost"; 64 65 final Socket socket; 66 try { 67 socket = new Socket (host, port); 68 } catch (UnknownHostException ex) { 69 throw new RuntimeException ("no such host: " + host, ex); 70 } catch (IOException ex) { 71 System.err.println("ProcessStopper: couldn't connect to " + host + ":" + port); 72 return; 73 } 74 75 final BufferedWriter writer; 76 77 try { 78 writer = new BufferedWriter (new OutputStreamWriter (socket.getOutputStream(), ProcessRunner.STREAM_ENCODING)); 79 } catch (UnsupportedEncodingException ex) { 80 throw new RuntimeException ("can't happen", ex); 81 } catch (IOException ex) { 82 throw new RuntimeException (ex); 83 } 84 85 try { 86 writer.write(ProcessRunner.SHUTDOWN_COMMAND); 87 writer.newLine(); 88 writer.flush(); 89 socket.close(); 90 } catch (IOException ex) { 91 throw new RuntimeException ("Error sending a shutdown command", ex); 92 } 93 } 94 } | Popular Tags |