0N/A/*
0N/A * Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
553N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
0N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
0N/A * or visit www.oracle.com if you need additional information or have any
553N/A * questions.
553N/A */
553N/A
0N/A/**
0N/A *
0N/A *
0N/A * Client that will run in its own vm and tell the main CheckFQDN test
0N/A * program what its rmi host name is, name obtained from TCPEndpoint.
0N/A */
0N/A
0N/Aimport java.rmi.*;
0N/Aimport java.rmi.server.*;
0N/Aimport sun.rmi.transport.tcp.TCPEndpoint;
0N/A
0N/A/**
0N/A * Get the local endpoint: make sure that this process does
0N/A * not take too much time and that the resulting localhost
0N/A * string is correct for the property set on an execed vm process.
0N/A */
0N/Apublic class CheckFQDNClient implements Runnable {
0N/A
0N/A final static int NAME_SERVICE_TIME_OUT = 12000;
0N/A
0N/A static TCPEndpoint ep = null;
0N/A
0N/A /**
0N/A * main, lookup remote object and tell it the rmi
0N/A * hostname of this client vm.
0N/A */
1147N/A public static void main (String args[]) {
0N/A
0N/A // start a registry and register a copy of this in it.
0N/A TellServerName tell;
391N/A String hostname = null;
391N/A
391N/A try {
391N/A hostname = retrieveServerName();
0N/A System.err.println("Client host name: " +
0N/A hostname);
0N/A
0N/A int registryPort = Integer.parseInt(System.getProperty("rmi.registry.port"));
0N/A tell = (TellServerName) Naming.lookup("rmi://:" +
0N/A registryPort
0N/A + "/CheckFQDN");
0N/A tell.tellServerName(hostname);
0N/A System.err.println("client has exited");
0N/A
0N/A } catch (Exception e ) {
0N/A throw new RuntimeException(e.getMessage());
0N/A }
0N/A System.exit(0);
0N/A }
0N/A
391N/A /* what is the rmi hostname for this vm? */
0N/A public static String retrieveServerName () {
0N/A try {
0N/A
0N/A CheckFQDNClient chk = new CheckFQDNClient();
0N/A
0N/A synchronized(chk) {
(new Thread (chk)).start();
chk.wait(NAME_SERVICE_TIME_OUT);
}
if (ep == null) {
throw new RuntimeException
("Timeout getting the local endpoint.");
}
// this is the name used by rmi for the client hostname
return ep.getHost();
}catch (Exception e){
throw new RuntimeException (e.getMessage());
}
}
/* thread to geth the rmi hostname of this vm */
public void run () {
try {
synchronized(this) {
ep = TCPEndpoint.getLocalEndpoint(0);
}
} catch (Exception e) {
throw new RuntimeException();
} finally {
synchronized(this) {
this.notify();
}
}
}
}