KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mortbay > stop > Main


1 // ========================================================================
2
// $Id: Main.java,v 1.4 2004/05/09 20:32:48 gregwilkins Exp $
3
// Copyright 2002-2004 Mort Bay Consulting Pty. Ltd.
4
// ------------------------------------------------------------------------
5
// Licensed under the Apache License, Version 2.0 (the "License");
6
// you may not use this file except in compliance with the License.
7
// You may obtain a copy of the License at
8
// http://www.apache.org/licenses/LICENSE-2.0
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14
// ========================================================================
15

16 package org.mortbay.stop;
17
18 import java.io.OutputStream JavaDoc;
19 import java.net.InetAddress JavaDoc;
20 import java.net.Socket JavaDoc;
21
22
23
24 /*-------------------------------------------*/
25 /** Main stop class.
26  * This class is intended to be the main class listed in the MANIFEST.MF of
27  * the stop.jar archive. It allows an application started with the
28  * command "java -jar start.jar" to be stopped.
29  *
30  * Programs started with start.jar may be stopped with the stop.jar, which connects
31  * via a local port to stop the server. The default port can be set with the
32  * STOP.PORT system property (a port of < 0 disables the stop mechanism). If the STOP.KEY
33  * system property is set, then a random key is generated and written to stdout. This key
34  * must be passed to the stop.jar.
35  *
36  * @author Greg Wilkins
37  * @version $Revision: 1.4 $
38  */

39  
40 public class Main
41 {
42     private boolean _debug = System.getProperty("DEBUG",null)!=null;
43     private String JavaDoc _config = System.getProperty("START","org/mortbay/start/start.config");
44     private int _port = Integer.getInteger("STOP.PORT",8079).intValue();
45     private String JavaDoc _key = System.getProperty("STOP.KEY","mortbay");
46        
47     public static void main(String JavaDoc[] args)
48     {
49         new Main().stop();
50     }
51
52     void stop()
53     {
54         try
55         {
56             if (_port<=0)
57                 System.err.println("START.PORT system property must be specified");
58             if (_key==null)
59             {
60                 _key="";
61                 System.err.println("Using empty key");
62             }
63
64             Socket JavaDoc s=new Socket JavaDoc(InetAddress.getByName("127.0.0.1"),_port);
65             OutputStream JavaDoc out=s.getOutputStream();
66             out.write((_key+"\r\nstop\r\n").getBytes());
67             out.flush();
68             s.shutdownOutput();
69             s.close();
70         }
71         catch (Exception JavaDoc e)
72         {
73             e.printStackTrace();
74         }
75     }
76 }
77
Popular Tags