Search in sources :

Example 1 with RemoteStub

use of java.rmi.server.RemoteStub in project jdk8u_jdk by JetBrains.

the class ActivatableRef method activate.

/**
     * private method to activate the remote object.
     *
     * NOTE: the caller must be synchronized on "this" before
     * calling this method.
     */
private RemoteRef activate(boolean force) throws RemoteException {
    assert Thread.holdsLock(this);
    ref = null;
    try {
        /*
             * Activate the object and retrieve the remote reference
             * from inside the stub returned as the result. Then
             * set this activatable ref's internal ref to be the
             * ref inside the ref of the stub. In more clear terms,
             * the stub returned from the activate call contains an
             * ActivatableRef. We need to set the ref in *this*
             * ActivatableRef to the ref inside the ActivatableRef
             * retrieved from the stub. The ref type embedded in the
             * ActivatableRef is typically a UnicastRef.
             */
        Remote proxy = id.activate(force);
        ActivatableRef newRef = null;
        if (proxy instanceof RemoteStub) {
            newRef = (ActivatableRef) ((RemoteStub) proxy).getRef();
        } else {
            /*
                 * Assume that proxy is an instance of a dynamic proxy
                 * class.  If that assumption is not correct, or either of
                 * the casts below fails, the resulting exception will be
                 * wrapped in an ActivateFailedException below.
                 */
            RemoteObjectInvocationHandler handler = (RemoteObjectInvocationHandler) Proxy.getInvocationHandler(proxy);
            newRef = (ActivatableRef) handler.getRef();
        }
        ref = newRef.ref;
        return ref;
    } catch (ConnectException e) {
        throw new ConnectException("activation failed", e);
    } catch (RemoteException e) {
        throw new ConnectIOException("activation failed", e);
    } catch (UnknownObjectException e) {
        throw new NoSuchObjectException("object not registered");
    } catch (ActivationException e) {
        throw new ActivateFailedException("activation failed", e);
    }
}
Also used : RemoteStub(java.rmi.server.RemoteStub) RemoteObjectInvocationHandler(java.rmi.server.RemoteObjectInvocationHandler)

Example 2 with RemoteStub

use of java.rmi.server.RemoteStub 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);
    }
}
Also used : RemoteStub(java.rmi.server.RemoteStub) InvocationTargetException(java.lang.reflect.InvocationTargetException) StubNotFoundException(java.rmi.StubNotFoundException)

Example 3 with RemoteStub

use of java.rmi.server.RemoteStub in project jdk8u_jdk by JetBrains.

the class UnicastServerRef method exportObject.

/**
     * Export this object, create the skeleton and stubs for this
     * dispatcher.  Create a stub based on the type of the impl,
     * initialize it with the appropriate remote reference. Create the
     * target defined by the impl, dispatcher (this) and stub.
     * Export that target via the Ref.
     */
public Remote exportObject(Remote impl, Object data, boolean permanent) throws RemoteException {
    Class<?> implClass = impl.getClass();
    Remote stub;
    try {
        stub = Util.createProxy(implClass, getClientRef(), forceStubUse);
    } catch (IllegalArgumentException e) {
        throw new ExportException("remote object implements illegal remote interface", e);
    }
    if (stub instanceof RemoteStub) {
        setSkeleton(impl);
    }
    Target target = new Target(impl, this, stub, ref.getObjID(), permanent);
    ref.exportObject(target);
    hashToMethod_Map = hashToMethod_Maps.get(implClass);
    return stub;
}
Also used : Target(sun.rmi.transport.Target) RemoteStub(java.rmi.server.RemoteStub) Remote(java.rmi.Remote) ExportException(java.rmi.server.ExportException)

Example 4 with RemoteStub

use of java.rmi.server.RemoteStub in project jdk8u_jdk by JetBrains.

the class RemoteInterface method main.

public static void main(String[] args) throws Exception {
    RemoteInterface server = null;
    RemoteInterface proxy = null;
    try {
        System.setProperty("java.rmi.server.ignoreStubClasses", args[0]);
        boolean ignoreStubClasses = Boolean.parseBoolean(args[0]);
        if (System.getSecurityManager() == null) {
            System.setSecurityManager(new SecurityManager());
        }
        System.err.println("export object");
        server = new UseDynamicProxies();
        proxy = (RemoteInterface) UnicastRemoteObject.exportObject(server, 0);
        System.err.println("proxy = " + proxy);
        if (ignoreStubClasses) {
            if (!Proxy.isProxyClass(proxy.getClass())) {
                throw new RuntimeException("server proxy is not a dynamic proxy");
            }
            if (!(Proxy.getInvocationHandler(proxy) instanceof RemoteObjectInvocationHandler)) {
                throw new RuntimeException("invalid invocation handler");
            }
        } else if (!(proxy instanceof RemoteStub)) {
            throw new RuntimeException("server proxy is not a RemoteStub");
        }
        System.err.println("invoke methods");
        Object obj = proxy.passObject(proxy);
        if (!proxy.equals(obj)) {
            throw new RuntimeException("returned proxy not equal");
        }
        int x = proxy.passInt(53);
        if (x != 53) {
            throw new RuntimeException("returned int not equal");
        }
        String string = proxy.passString("test");
        if (!string.equals("test")) {
            throw new RuntimeException("returned string not equal");
        }
        System.err.println("TEST PASSED");
    } finally {
        if (proxy != null) {
            UnicastRemoteObject.unexportObject(server, true);
        }
    }
}
Also used : RemoteObjectInvocationHandler(java.rmi.server.RemoteObjectInvocationHandler) RemoteStub(java.rmi.server.RemoteStub) UnicastRemoteObject(java.rmi.server.UnicastRemoteObject)

Aggregations

RemoteStub (java.rmi.server.RemoteStub)4 RemoteObjectInvocationHandler (java.rmi.server.RemoteObjectInvocationHandler)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Remote (java.rmi.Remote)1 StubNotFoundException (java.rmi.StubNotFoundException)1 ExportException (java.rmi.server.ExportException)1 UnicastRemoteObject (java.rmi.server.UnicastRemoteObject)1 Target (sun.rmi.transport.Target)1