use of sun.rmi.transport.tcp.TCPEndpoint in project jdk8u_jdk by JetBrains.
the class TestLibrary method getRegistryPort.
/**
* Returns the port number the RMI {@link Registry} is running on.
*
* @param registry the registry to find the port of.
* @return the port number the registry is using.
* @throws RuntimeException if there was a problem getting the port number.
*/
public static int getRegistryPort(Registry registry) {
int port = -1;
try {
RemoteRef remoteRef = ((RegistryImpl) registry).getRef();
LiveRef liveRef = ((UnicastServerRef) remoteRef).getLiveRef();
Endpoint endpoint = liveRef.getChannel().getEndpoint();
TCPEndpoint tcpEndpoint = (TCPEndpoint) endpoint;
port = tcpEndpoint.getPort();
} catch (Exception ex) {
throw new RuntimeException("Error getting registry port.", ex);
}
return port;
}
use of sun.rmi.transport.tcp.TCPEndpoint in project jdk8u_jdk by JetBrains.
the class StreamRemoteCall method exceptionReceivedFromServer.
/**
* Routine that causes the stack traces of remote exceptions to be
* filled in with the current stack trace on the client. Detail
* exceptions are filled in iteratively.
*/
protected void exceptionReceivedFromServer(Exception ex) throws Exception {
serverException = ex;
StackTraceElement[] serverTrace = ex.getStackTrace();
StackTraceElement[] clientTrace = (new Throwable()).getStackTrace();
StackTraceElement[] combinedTrace = new StackTraceElement[serverTrace.length + clientTrace.length];
System.arraycopy(serverTrace, 0, combinedTrace, 0, serverTrace.length);
System.arraycopy(clientTrace, 0, combinedTrace, serverTrace.length, clientTrace.length);
ex.setStackTrace(combinedTrace);
/*
* Log the details of a server exception thrown as a result of a
* remote method invocation.
*/
if (UnicastRef.clientCallLog.isLoggable(Log.BRIEF)) {
/* log call exception returned from server before it is rethrown */
TCPEndpoint ep = (TCPEndpoint) conn.getChannel().getEndpoint();
UnicastRef.clientCallLog.log(Log.BRIEF, "outbound call " + "received exception: [" + ep.getHost() + ":" + ep.getPort() + "] exception: ", ex);
}
throw ex;
}
use of sun.rmi.transport.tcp.TCPEndpoint in project jdk8u_jdk by JetBrains.
the class LiveRef method write.
public void write(ObjectOutput out, boolean useNewFormat) throws IOException {
boolean isResultStream = false;
if (out instanceof ConnectionOutputStream) {
ConnectionOutputStream stream = (ConnectionOutputStream) out;
isResultStream = stream.isResultStream();
/*
* Ensure that referential integrity is not broken while
* this LiveRef is in transit. If it is being marshalled
* as part of a result, it may not otherwise be strongly
* reachable after the remote call has completed; even if
* it is being marshalled as part of an argument, the VM
* may determine that the reference on the stack is no
* longer reachable after marshalling (see 6181943)--
* therefore, tell the stream to save a reference until a
* timeout expires or, for results, a DGCAck message has
* been received from the caller, or for arguments, the
* remote call has completed. For a "local" LiveRef, save
* a reference to the impl directly, because the impl is
* not reachable from the LiveRef (see 4114579);
* otherwise, save a reference to the LiveRef, for the
* client-side DGC to watch over. (Also see 4017232.)
*/
if (isLocal) {
ObjectEndpoint oe = new ObjectEndpoint(id, ep.getInboundTransport());
Target target = ObjectTable.getTarget(oe);
if (target != null) {
Remote impl = target.getImpl();
if (impl != null) {
stream.saveObject(impl);
}
}
} else {
stream.saveObject(this);
}
}
// (need to choose whether or not to use old JDK1.1 endpoint format)
if (useNewFormat) {
((TCPEndpoint) ep).write(out);
} else {
((TCPEndpoint) ep).writeHostPortFormat(out);
}
id.write(out);
out.writeBoolean(isResultStream);
}
use of sun.rmi.transport.tcp.TCPEndpoint in project jdk8u_jdk by JetBrains.
the class LocateRegistry method getRegistry.
/**
* Returns a locally created remote reference to the remote object
* <code>Registry</code> on the specified <code>host</code> and
* <code>port</code>. Communication with this remote registry will
* use the supplied <code>RMIClientSocketFactory</code> <code>csf</code>
* to create <code>Socket</code> connections to the registry on the
* remote <code>host</code> and <code>port</code>.
*
* @param host host for the remote registry
* @param port port on which the registry accepts requests
* @param csf client-side <code>Socket</code> factory used to
* make connections to the registry. If <code>csf</code>
* is null, then the default client-side <code>Socket</code>
* factory will be used in the registry stub.
* @return reference (a stub) to the remote registry
* @exception RemoteException if the reference could not be created
* @since 1.2
*/
public static Registry getRegistry(String host, int port, RMIClientSocketFactory csf) throws RemoteException {
Registry registry = null;
if (port <= 0)
port = Registry.REGISTRY_PORT;
if (host == null || host.length() == 0) {
// that the RegistryImpl's checkAccess will not fail.
try {
host = java.net.InetAddress.getLocalHost().getHostAddress();
} catch (Exception e) {
// If that failed, at least try "" (localhost) anyway...
host = "";
}
}
/*
* Create a proxy for the registry with the given host, port, and
* client socket factory. If the supplied client socket factory is
* null, then the ref type is a UnicastRef, otherwise the ref type
* is a UnicastRef2. If the property
* java.rmi.server.ignoreStubClasses is true, then the proxy
* returned is an instance of a dynamic proxy class that implements
* the Registry interface; otherwise the proxy returned is an
* instance of the pregenerated stub class for RegistryImpl.
**/
LiveRef liveRef = new LiveRef(new ObjID(ObjID.REGISTRY_ID), new TCPEndpoint(host, port, csf, null), false);
RemoteRef ref = (csf == null) ? new UnicastRef(liveRef) : new UnicastRef2(liveRef);
return (Registry) Util.createProxy(RegistryImpl.class, ref, false);
}
use of sun.rmi.transport.tcp.TCPEndpoint in project jdk8u_jdk by JetBrains.
the class InterfaceHash method main.
public static void main(String[] args) throws Exception {
System.err.println("\nRegression test for bug 4472769");
System.err.println("\n=== verifying that J2SE registry's skeleton uses" + "\ncorrect interface hash and operation numbers:");
Registry testImpl = LocateRegistry.createRegistry(PORT);
System.err.println("created test registry on port " + PORT);
RemoteRef ref = new UnicastRef(new LiveRef(new ObjID(ObjID.REGISTRY_ID), new TCPEndpoint("", PORT), false));
Registry referenceStub = new ReferenceRegistryStub(ref);
System.err.println("created reference registry stub: " + referenceStub);
referenceStub.bind(NAME, referenceStub);
System.err.println("bound name \"" + NAME + "\" in registry");
String[] list = referenceStub.list();
System.err.println("list of registry contents: " + Arrays.asList(list));
if (list.length != 1 || !list[0].equals(NAME)) {
throw new RuntimeException("TEST FAILED: unexpected list contents");
}
Registry result = (Registry) referenceStub.lookup(NAME);
System.err.println("lookup of name \"" + NAME + "\" returned: " + result);
if (!result.equals(referenceStub)) {
throw new RuntimeException("TEST FAILED: unexpected lookup result");
}
referenceStub.rebind(NAME, referenceStub);
referenceStub.unbind(NAME);
System.err.println("unbound name \"" + NAME + "\"");
list = referenceStub.list();
System.err.println("list of registry contents: " + Arrays.asList(list));
if (list.length != 0) {
throw new RuntimeException("TEST FAILED: list not empty");
}
System.err.println("\n=== verifying that J2SE registry's stub uses" + "correct interface hash:");
class FakeRemoteRef implements RemoteRef {
long hash;
int opnum;
public RemoteCall newCall(RemoteObject obj, Operation[] op, int opnum, long hash) {
this.hash = hash;
this.opnum = opnum;
throw new UnsupportedOperationException();
}
public void invoke(RemoteCall call) {
}
public void done(RemoteCall call) {
}
public Object invoke(Remote obj, Method method, Object[] args, long hash) {
throw new UnsupportedOperationException();
}
public String getRefClass(java.io.ObjectOutput out) {
return "FakeRemoteRef";
}
public int remoteHashCode() {
return 1013;
}
public boolean remoteEquals(RemoteRef obj) {
return false;
}
public String remoteToString() {
return "FakeRemoteRef";
}
public void writeExternal(java.io.ObjectOutput out) {
}
public void readExternal(java.io.ObjectInput in) {
}
}
FakeRemoteRef f = new FakeRemoteRef();
Registry testRegistry = LocateRegistry.getRegistry(PORT);
System.err.println("created original test registry stub: " + testRegistry);
Class stubClass = testRegistry.getClass();
System.err.println("test registry stub class: " + stubClass);
Constructor cons = stubClass.getConstructor(new Class[] { RemoteRef.class });
Registry testStub = (Registry) cons.newInstance(new Object[] { f });
System.err.println("created new instrumented test registry stub: " + testStub);
System.err.println("invoking bind:");
try {
testStub.bind(NAME, referenceStub);
} catch (UnsupportedOperationException e) {
}
System.err.println("hash == " + f.hash + ", opnum == " + f.opnum);
if (f.hash != 4905912898345647071L) {
throw new RuntimeException("TEST FAILED: wrong interface hash");
} else if (f.opnum != 0) {
throw new RuntimeException("TEST FAILED: wrong operation number");
}
System.err.println("invoking list:");
try {
testStub.list();
} catch (UnsupportedOperationException e) {
}
System.err.println("hash == " + f.hash + ", opnum == " + f.opnum);
if (f.hash != 4905912898345647071L) {
throw new RuntimeException("TEST FAILED: wrong interface hash");
} else if (f.opnum != 1) {
throw new RuntimeException("TEST FAILED: wrong operation number");
}
System.err.println("invoking lookup:");
try {
testStub.lookup(NAME);
} catch (UnsupportedOperationException e) {
}
System.err.println("hash == " + f.hash + ", opnum == " + f.opnum);
if (f.hash != 4905912898345647071L) {
throw new RuntimeException("TEST FAILED: wrong interface hash");
} else if (f.opnum != 2) {
throw new RuntimeException("TEST FAILED: wrong operation number");
}
System.err.println("invoking rebind:");
try {
testStub.rebind(NAME, referenceStub);
} catch (UnsupportedOperationException e) {
}
System.err.println("hash == " + f.hash + ", opnum == " + f.opnum);
if (f.hash != 4905912898345647071L) {
throw new RuntimeException("TEST FAILED: wrong interface hash");
} else if (f.opnum != 3) {
throw new RuntimeException("TEST FAILED: wrong operation number");
}
System.err.println("invoking unbind:");
try {
testStub.unbind(NAME);
} catch (UnsupportedOperationException e) {
}
System.err.println("hash == " + f.hash + ", opnum == " + f.opnum);
if (f.hash != 4905912898345647071L) {
throw new RuntimeException("TEST FAILED: wrong interface hash");
} else if (f.opnum != 4) {
throw new RuntimeException("TEST FAILED: wrong operation number");
}
System.err.println("TEST PASSED");
}
Aggregations