Path: blob/master/test/jdk/java/rmi/transport/checkFQDN/CheckFQDNClient.java
41155 views
/*1* Copyright (c) 1998, 2012, 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*25*26* Client that will run in its own vm and tell the main CheckFQDN test27* program what its rmi host name is, name obtained from TCPEndpoint.28*/2930import java.rmi.*;31import java.rmi.server.*;32import sun.rmi.transport.tcp.TCPEndpoint;3334/**35* Get the local endpoint: make sure that this process does36* not take too much time and that the resulting localhost37* string is correct for the property set on an execed vm process.38*/39public class CheckFQDNClient implements Runnable {4041final static int NAME_SERVICE_TIME_OUT = 12000;4243static TCPEndpoint ep = null;4445/**46* main, lookup remote object and tell it the rmi47* hostname of this client vm.48*/49public static void main (String args[]) {5051// start a registry and register a copy of this in it.52TellServerName tell;53String hostname = null;5455try {56hostname = retrieveServerName();57System.err.println("Client host name: " +58hostname);5960int registryPort = Integer.parseInt(System.getProperty("rmi.registry.port"));61tell = (TellServerName) Naming.lookup("rmi://:" +62registryPort63+ "/CheckFQDN");64tell.tellServerName(hostname);65System.err.println("client has exited");6667} catch (Exception e ) {68throw new RuntimeException(e.getMessage());69}70System.exit(0);71}7273/* what is the rmi hostname for this vm? */74public static String retrieveServerName () {75try {7677CheckFQDNClient chk = new CheckFQDNClient();7879synchronized(chk) {80(new Thread (chk)).start();81chk.wait(NAME_SERVICE_TIME_OUT);82}8384if (ep == null) {85throw new RuntimeException86("Timeout getting the local endpoint.");87}8889// this is the name used by rmi for the client hostname90return ep.getHost();9192}catch (Exception e){93throw new RuntimeException (e.getMessage());94}95}9697/* thread to geth the rmi hostname of this vm */98public void run () {99try {100synchronized(this) {101ep = TCPEndpoint.getLocalEndpoint(0);102}103} catch (Exception e) {104throw new RuntimeException();105} finally {106synchronized(this) {107this.notify();108}109}110}111}112113114