use of java.rmi.server.RemoteRef in project jdk8u_jdk by JetBrains.
the class ActivationID method readObject.
/**
* <code>readObject</code> for custom serialization.
*
* <p>This method reads this object's serialized form for this
* class as follows:
*
* <p>The <code>readObject</code> method is invoked on
* <code>in</code> to read this object's unique identifier
* (a {@link java.rmi.server.UID UID} instance).
*
* <p>Next, the <code>readUTF</code> method is invoked on
* <code>in</code> to read the external ref type name of the
* <code>RemoteRef</code> instance for this object's
* activator. Next, the <code>RemoteRef</code>
* instance is created of an implementation-specific class
* corresponding to the external ref type name (returned by
* <code>readUTF</code>), and the <code>readExternal</code>
* method is invoked on that <code>RemoteRef</code> instance
* to read the external form corresponding to the external
* ref type name.
*
* <p>Note: If the external ref type name is
* <code>"UnicastRef"</code>, <code>"UnicastServerRef"</code>,
* <code>"UnicastRef2"</code>, <code>"UnicastServerRef2"</code>,
* or <code>"ActivatableRef"</code>, a corresponding
* implementation-specific class must be found, and its
* <code>readExternal</code> method must read the serial data
* for that external ref type name as specified to be written
* in the <b>serialData</b> documentation for this class.
* If the external ref type name is any other string (of non-zero
* length), a <code>ClassNotFoundException</code> will be thrown,
* unless the implementation provides an implementation-specific
* class corresponding to that external ref type name, in which
* case the <code>RemoteRef</code> will be an instance of
* that implementation-specific class.
*/
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
uid = (UID) in.readObject();
try {
Class<? extends RemoteRef> refClass = Class.forName(RemoteRef.packagePrefix + "." + in.readUTF()).asSubclass(RemoteRef.class);
RemoteRef ref = refClass.newInstance();
ref.readExternal(in);
activator = (Activator) Proxy.newProxyInstance(null, new Class<?>[] { Activator.class }, new RemoteObjectInvocationHandler(ref));
} catch (InstantiationException e) {
throw (IOException) new InvalidObjectException("Unable to create remote reference").initCause(e);
} catch (IllegalAccessException e) {
throw (IOException) new InvalidObjectException("Unable to create remote reference").initCause(e);
}
}
use of java.rmi.server.RemoteRef in project jdk8u_jdk by JetBrains.
the class ActivationID method writeObject.
/**
* <code>writeObject</code> for custom serialization.
*
* <p>This method writes this object's serialized form for
* this class as follows:
*
* <p>The <code>writeObject</code> method is invoked on
* <code>out</code> passing this object's unique identifier
* (a {@link java.rmi.server.UID UID} instance) as the argument.
*
* <p>Next, the {@link
* java.rmi.server.RemoteRef#getRefClass(java.io.ObjectOutput)
* getRefClass} method is invoked on the activator's
* <code>RemoteRef</code> instance to obtain its external ref
* type name. Next, the <code>writeUTF</code> method is
* invoked on <code>out</code> with the value returned by
* <code>getRefClass</code>, and then the
* <code>writeExternal</code> method is invoked on the
* <code>RemoteRef</code> instance passing <code>out</code>
* as the argument.
*
* @serialData The serialized data for this class comprises a
* <code>java.rmi.server.UID</code> (written with
* <code>ObjectOutput.writeObject</code>) followed by the
* external ref type name of the activator's
* <code>RemoteRef</code> instance (a string written with
* <code>ObjectOutput.writeUTF</code>), followed by the
* external form of the <code>RemoteRef</code> instance as
* written by its <code>writeExternal</code> method.
*
* <p>The external ref type name of the
* <code>RemoteRef</Code> instance is
* determined using the definitions of external ref type
* names specified in the {@link java.rmi.server.RemoteObject
* RemoteObject} <code>writeObject</code> method
* <b>serialData</b> specification. Similarly, the data
* written by the <code>writeExternal</code> method and read
* by the <code>readExternal</code> method of
* <code>RemoteRef</code> implementation classes
* corresponding to each of the defined external ref type
* names is specified in the {@link
* java.rmi.server.RemoteObject RemoteObject}
* <code>writeObject</code> method <b>serialData</b>
* specification.
**/
private void writeObject(ObjectOutputStream out) throws IOException, ClassNotFoundException {
out.writeObject(uid);
RemoteRef ref;
if (activator instanceof RemoteObject) {
ref = ((RemoteObject) activator).getRef();
} else if (Proxy.isProxyClass(activator.getClass())) {
InvocationHandler handler = Proxy.getInvocationHandler(activator);
if (!(handler instanceof RemoteObjectInvocationHandler)) {
throw new InvalidObjectException("unexpected invocation handler");
}
ref = ((RemoteObjectInvocationHandler) handler).getRef();
} else {
throw new InvalidObjectException("unexpected activator type");
}
out.writeUTF(ref.getRefClass(out));
ref.writeExternal(out);
}
use of java.rmi.server.RemoteRef in project jdk8u_jdk by JetBrains.
the class ActivatableRef method invoke.
/**
* Invoke method on remote object. This method delegates remote
* method invocation to the underlying ref type. If the
* underlying reference is not known (is null), then the object
* must be activated first. If an attempt at method invocation
* fails, the object should force reactivation. Method invocation
* must preserve "at most once" call semantics. In RMI, "at most
* once" applies to parameter deserialization at the remote site
* and the remote object's method execution. "At most once" does
* not apply to parameter serialization at the client so the
* parameters of a call don't need to be buffered in anticipation
* of call retry. Thus, a method call is only be retried if the
* initial method invocation does not execute at all at the server
* (including parameter deserialization).
*/
public Object invoke(Remote obj, java.lang.reflect.Method method, Object[] params, long opnum) throws Exception {
boolean force = false;
RemoteRef localRef;
Exception exception = null;
/*
* Attempt object activation if active ref is unknown.
* Throws a RemoteException if object can't be activated.
*/
synchronized (this) {
if (ref == null) {
localRef = activate(force);
force = true;
} else {
localRef = ref;
}
}
for (int retries = MAX_RETRIES; retries > 0; retries--) {
try {
return localRef.invoke(obj, method, params, opnum);
} catch (NoSuchObjectException e) {
/*
* Object is not active in VM; retry call
*/
exception = e;
} catch (ConnectException e) {
/*
* Failure during connection setup; retry call
*/
exception = e;
} catch (UnknownHostException e) {
/*
* Failure during connection setup; retry call.
*/
exception = e;
} catch (ConnectIOException e) {
/*
* Failure setting up multiplexed connection or reusing
* cached connection; retry call
*/
exception = e;
} catch (MarshalException e) {
/*
* Failure during parameter serialization; call may
* have reached server, so call retry not possible.
*/
throw e;
} catch (ServerError e) {
/*
* Call reached server; propagate remote exception.
*/
throw e;
} catch (ServerException e) {
/*
* Call reached server; propagate remote exception
*/
throw e;
} catch (RemoteException e) {
/*
* This is a catch-all for other RemoteExceptions.
* UnmarshalException being the only one relevant.
*
* StubNotFoundException should never show up because
* it is generally thrown when attempting to locate
* a stub.
*
* UnexpectedException should never show up because
* it is only thrown by a stub and would be wrapped
* in a ServerException if it was propagated by a
* remote call.
*/
synchronized (this) {
if (localRef == ref) {
// this may be overly conservative
ref = null;
}
}
throw e;
}
if (retries > 1) {
/*
* Activate object, since object could not be reached.
*/
synchronized (this) {
if (localRef.remoteEquals(ref) || ref == null) {
RemoteRef newRef = activate(force);
if (newRef.remoteEquals(localRef) && exception instanceof NoSuchObjectException && force == false) {
/*
* If last exception was NoSuchObjectException,
* then old value of ref is definitely wrong,
* so make sure that it is different.
*/
newRef = activate(true);
}
localRef = newRef;
force = true;
} else {
localRef = ref;
force = false;
}
}
}
}
/*
* Retries unsuccessful, so throw last exception
*/
throw exception;
}
use of java.rmi.server.RemoteRef in project jdk8u_jdk by JetBrains.
the class ActivatableRef method getStub.
/**
* Returns the stub for the remote object whose class is
* specified in the activation descriptor. The ActivatableRef
* in the resulting stub has its activation id set to the
* activation id supplied as the second argument.
*/
public static Remote getStub(ActivationDesc desc, ActivationID id) throws StubNotFoundException {
String className = desc.getClassName();
try {
Class<?> cl = RMIClassLoader.loadClass(desc.getLocation(), className);
RemoteRef clientRef = new ActivatableRef(id, null);
return Util.createProxy(cl, clientRef, false);
} catch (IllegalArgumentException e) {
throw new StubNotFoundException("class implements an illegal remote interface", e);
} catch (ClassNotFoundException e) {
throw new StubNotFoundException("unable to load class: " + className, e);
} catch (MalformedURLException e) {
throw new StubNotFoundException("malformed URL", e);
}
}
use of java.rmi.server.RemoteRef in project jdk8u_jdk by JetBrains.
the class RMIConnector method checkStub.
//--------------------------------------------------------------------
// Private stuff - Check if stub can be trusted.
//--------------------------------------------------------------------
private static void checkStub(Remote stub, Class<?> stubClass) {
//
if (stub.getClass() != stubClass) {
if (!Proxy.isProxyClass(stub.getClass())) {
throw new SecurityException("Expecting a " + stubClass.getName() + " stub!");
} else {
InvocationHandler handler = Proxy.getInvocationHandler(stub);
if (handler.getClass() != RemoteObjectInvocationHandler.class)
throw new SecurityException("Expecting a dynamic proxy instance with a " + RemoteObjectInvocationHandler.class.getName() + " invocation handler!");
else
stub = (Remote) handler;
}
}
// Check RemoteRef in stub is from the expected class
// "sun.rmi.server.UnicastRef2".
//
RemoteRef ref = ((RemoteObject) stub).getRef();
if (ref.getClass() != UnicastRef2.class)
throw new SecurityException("Expecting a " + UnicastRef2.class.getName() + " remote reference in stub!");
// Check RMIClientSocketFactory in stub is from the expected class
// "javax.rmi.ssl.SslRMIClientSocketFactory".
//
LiveRef liveRef = ((UnicastRef2) ref).getLiveRef();
RMIClientSocketFactory csf = liveRef.getClientSocketFactory();
if (csf == null || csf.getClass() != SslRMIClientSocketFactory.class)
throw new SecurityException("Expecting a " + SslRMIClientSocketFactory.class.getName() + " RMI client socket factory in stub!");
}
Aggregations