Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/sun/tools/common/ShutdownSimpleApplication.java
38839 views
/*1* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* Used to shutdown SimpleApplication (or a subclass). The argument to25* this class is the name of a file that contains the TCP port number26* on which SimpleApplication (or a subclass) is listening.27*28* Note: When this program returns, the SimpleApplication (or a subclass)29* may still be running because the application has not yet reached the30* shutdown check.31*/32import java.net.Socket;33import java.net.InetSocketAddress;34import java.io.File;35import java.io.FileInputStream;3637public class ShutdownSimpleApplication {38public static void main(String args[]) throws Exception {3940if (args.length != 1) {41throw new RuntimeException("Usage: ShutdownSimpleApplication" +42" port-file");43}4445// read the (TCP) port number from the given file4647File f = new File(args[0]);48FileInputStream fis = new FileInputStream(f);49byte b[] = new byte[8];50int n = fis.read(b);51if (n < 1) {52throw new RuntimeException("Empty port-file");53}54fis.close();5556String str = new String(b, 0, n, "UTF-8");57System.out.println("INFO: Port number of SimpleApplication: " + str);58int port = Integer.parseInt(str);5960// Now connect to the port (which will shutdown application)6162System.out.println("INFO: Connecting to port " + port +63" to shutdown SimpleApplication ...");64System.out.flush();6566Socket s = new Socket();67s.connect( new InetSocketAddress(port) );68s.close();6970System.out.println("INFO: done connecting to SimpleApplication.");71System.out.flush();7273System.exit(0);74}75}767778