2007-12-01 00:00:00 +00:00
|
|
|
/*
|
2010-05-25 22:58:33 +00:00
|
|
|
* Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
|
2007-12-01 00:00:00 +00:00
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
|
|
*
|
|
|
|
* This code is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License version 2 only, as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* version 2 for more details (a copy is included in the LICENSE file that
|
|
|
|
* accompanied this code).
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License version
|
|
|
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*
|
2010-05-25 22:58:33 +00:00
|
|
|
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
|
|
* or visit www.oracle.com if you need additional information or have any
|
|
|
|
* questions.
|
2007-12-01 00:00:00 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* A simple "Application" used by the Attach API unit tests. This application is
|
|
|
|
* launched by the test. It binds to a random port and shuts down when somebody
|
|
|
|
* connects to that port.
|
2013-12-03 16:06:23 +00:00
|
|
|
* Used port and pid are written both to stdout and to a specified file.
|
2007-12-01 00:00:00 +00:00
|
|
|
*/
|
|
|
|
import java.net.Socket;
|
|
|
|
import java.net.ServerSocket;
|
2013-12-03 16:06:23 +00:00
|
|
|
import java.io.PrintWriter;
|
|
|
|
import jdk.testlibrary.ProcessTools;
|
2007-12-01 00:00:00 +00:00
|
|
|
|
|
|
|
public class Application {
|
|
|
|
public static void main(String args[]) throws Exception {
|
|
|
|
// bind to a random port
|
2013-12-03 16:06:23 +00:00
|
|
|
if (args.length < 1) {
|
|
|
|
System.err.println("First argument should be path to output file.");
|
|
|
|
}
|
|
|
|
String outFileName = args[0];
|
|
|
|
|
2007-12-01 00:00:00 +00:00
|
|
|
ServerSocket ss = new ServerSocket(0);
|
|
|
|
int port = ss.getLocalPort();
|
2013-12-03 16:06:23 +00:00
|
|
|
int pid = ProcessTools.getProcessId();
|
2007-12-01 00:00:00 +00:00
|
|
|
|
2013-12-03 16:06:23 +00:00
|
|
|
System.out.println("shutdownPort=" + port);
|
|
|
|
System.out.println("pid=" + pid);
|
2007-12-01 00:00:00 +00:00
|
|
|
System.out.flush();
|
|
|
|
|
2013-12-03 16:06:23 +00:00
|
|
|
try (PrintWriter writer = new PrintWriter(outFileName)) {
|
|
|
|
writer.println("shutdownPort=" + port);
|
|
|
|
writer.println("pid=" + pid);
|
|
|
|
writer.println("done");
|
|
|
|
writer.flush();
|
|
|
|
}
|
|
|
|
|
2007-12-01 00:00:00 +00:00
|
|
|
// wait for test harness to connect
|
|
|
|
Socket s = ss.accept();
|
|
|
|
s.close();
|
|
|
|
ss.close();
|
|
|
|
}
|
|
|
|
}
|