use of java.rmi.StubNotFoundException in project jdk8u_jdk by JetBrains.
the class Util method createProxy.
/**
* Returns a proxy for the specified implClass.
*
* If both of the following criteria is satisfied, a dynamic proxy for
* the specified implClass is returned (otherwise a RemoteStub instance
* for the specified implClass is returned):
*
* a) either the property java.rmi.server.ignoreStubClasses is true or
* a pregenerated stub class does not exist for the impl class, and
* b) forceStubUse is false.
*
* If the above criteria are satisfied, this method constructs a
* dynamic proxy instance (that implements the remote interfaces of
* implClass) constructed with a RemoteObjectInvocationHandler instance
* constructed with the clientRef.
*
* Otherwise, this method loads the pregenerated stub class (which
* extends RemoteStub and implements the remote interfaces of
* implClass) and constructs an instance of the pregenerated stub
* class with the clientRef.
*
* @param implClass the class to obtain remote interfaces from
* @param clientRef the remote ref to use in the invocation handler
* @param forceStubUse if true, forces creation of a RemoteStub
* @throws IllegalArgumentException if implClass implements illegal
* remote interfaces
* @throws StubNotFoundException if problem locating/creating stub or
* creating the dynamic proxy instance
**/
public static Remote createProxy(Class<?> implClass, RemoteRef clientRef, boolean forceStubUse) throws StubNotFoundException {
Class<?> remoteClass;
try {
remoteClass = getRemoteClass(implClass);
} catch (ClassNotFoundException ex) {
throw new StubNotFoundException("object does not implement a remote interface: " + implClass.getName());
}
if (forceStubUse || !(ignoreStubClasses || !stubClassExists(remoteClass))) {
return createStub(remoteClass, clientRef);
}
final ClassLoader loader = implClass.getClassLoader();
final Class<?>[] interfaces = getRemoteInterfaces(implClass);
final InvocationHandler handler = new RemoteObjectInvocationHandler(clientRef);
try {
return AccessController.doPrivileged(new PrivilegedAction<Remote>() {
public Remote run() {
return (Remote) Proxy.newProxyInstance(loader, interfaces, handler);
}
});
} catch (IllegalArgumentException e) {
throw new StubNotFoundException("unable to create proxy", e);
}
}
use of java.rmi.StubNotFoundException in project jdk8u_jdk by JetBrains.
the class Util method createStub.
/**
* Creates a RemoteStub instance for the specified class, constructed
* with the specified RemoteRef. The supplied class must be the most
* derived class in the remote object's superclass chain that
* implements a remote interface. The stub class name is the name of
* the specified remoteClass with the suffix "_Stub". The loading of
* the stub class is initiated from class loader of the specified class
* (which may be the bootstrap class loader).
**/
private static RemoteStub createStub(Class<?> remoteClass, RemoteRef ref) throws StubNotFoundException {
String stubname = remoteClass.getName() + "_Stub";
/* Make sure to use the local stub loader for the stub classes.
* When loaded by the local loader the load path can be
* propagated to remote clients, by the MarshalOutputStream/InStream
* pickle methods
*/
try {
Class<?> stubcl = Class.forName(stubname, false, remoteClass.getClassLoader());
Constructor<?> cons = stubcl.getConstructor(stubConsParamTypes);
return (RemoteStub) cons.newInstance(new Object[] { ref });
} catch (ClassNotFoundException e) {
throw new StubNotFoundException("Stub class not found: " + stubname, e);
} catch (NoSuchMethodException e) {
throw new StubNotFoundException("Stub class missing constructor: " + stubname, e);
} catch (InstantiationException e) {
throw new StubNotFoundException("Can't create instance of stub class: " + stubname, e);
} catch (IllegalAccessException e) {
throw new StubNotFoundException("Stub class constructor not public: " + stubname, e);
} catch (InvocationTargetException e) {
throw new StubNotFoundException("Exception creating instance of stub class: " + stubname, e);
} catch (ClassCastException e) {
throw new StubNotFoundException("Stub class not instance of RemoteStub: " + stubname, e);
}
}
Aggregations