java.rmi.server.RemoteRef Java Examples

The following examples show how to use java.rmi.server.RemoteRef. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestLibrary.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example #2
Source File: TestLibrary.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example #3
Source File: TestLibrary.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example #4
Source File: ActivatableRef.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Write out external representation for remote ref.
 */
public void writeExternal(ObjectOutput out) throws IOException
{
    RemoteRef localRef = ref;

    out.writeObject(id);
    if (localRef == null) {
        out.writeUTF("");
    } else {
        out.writeUTF(localRef.getRefClass(out));
        localRef.writeExternal(out);
    }
}
 
Example #5
Source File: ActivatableRef.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * private method to obtain the ref for a call.
 */
private synchronized RemoteRef getRef()
    throws RemoteException
{
    if (ref == null) {
        ref = activate(false);
    }

    return ref;
}
 
Example #6
Source File: Test.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    System.err.println("\nRegression test for RFE 5096178\n");
    Class<? extends P> cl =
        Class.forName(PImpl.class.getName() + "_Stub").asSubclass(P.class);
    Constructor<? extends P> cons = cl.getConstructor(RemoteRef.class);
    cons.newInstance(new ArgCheckingRemoteRef(Boolean.FALSE)).m(false);
    cons.newInstance(new ArgCheckingRemoteRef(Boolean.TRUE)).m(true);
    System.err.println("TEST PASSED");
}
 
Example #7
Source File: ActivatableRef.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * private method to obtain the ref for a call.
 */
private synchronized RemoteRef getRef()
    throws RemoteException
{
    if (ref == null) {
        ref = activate(false);
    }

    return ref;
}
 
Example #8
Source File: RMIConnector.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public Constructor<?> run() throws Exception {
    Class thisClass = RMIConnector.class;
    ClassLoader thisLoader = thisClass.getClassLoader();
    ProtectionDomain thisProtectionDomain =
            thisClass.getProtectionDomain();
    String[] otherClassNames = {ProxyRef.class.getName()};
    ClassLoader cl =
            new NoCallStackClassLoader(pRefClassName,
            pRefByteCode,
            otherClassNames,
            thisLoader,
            thisProtectionDomain);
    Class<?> c = cl.loadClass(pRefClassName);
    return c.getConstructor(RemoteRef.class);
}
 
Example #9
Source File: RMIConnector.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
private static RMIConnection shadowJrmpStub(RemoteObject stub)
throws InstantiationException, IllegalAccessException,
        InvocationTargetException, ClassNotFoundException,
        NoSuchMethodException {
    RemoteRef ref = stub.getRef();
    RemoteRef proxyRef = (RemoteRef)
        proxyRefConstructor.newInstance(new Object[] {ref});
    final Constructor<?> rmiConnectionImplStubConstructor =
        rmiConnectionImplStubClass.getConstructor(RemoteRef.class);
    Object[] args = {proxyRef};
    RMIConnection proxyStub = (RMIConnection)
    rmiConnectionImplStubConstructor.newInstance(args);
    return proxyStub;
}
 
Example #10
Source File: RMIConnector.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public Constructor<?> run() throws Exception {
    Class thisClass = RMIConnector.class;
    ClassLoader thisLoader = thisClass.getClassLoader();
    ProtectionDomain thisProtectionDomain =
            thisClass.getProtectionDomain();
    String[] otherClassNames = {ProxyRef.class.getName()};
    ClassLoader cl =
            new NoCallStackClassLoader(pRefClassName,
            pRefByteCode,
            otherClassNames,
            thisLoader,
            thisProtectionDomain);
    Class<?> c = cl.loadClass(pRefClassName);
    return c.getConstructor(RemoteRef.class);
}
 
Example #11
Source File: Util.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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);

    /* REMIND: private remote interfaces? */

    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);
    }
}
 
Example #12
Source File: ActivatableRef.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Write out external representation for remote ref.
 */
public void writeExternal(ObjectOutput out) throws IOException
{
    RemoteRef localRef = ref;

    out.writeObject(id);
    if (localRef == null) {
        out.writeUTF("");
    } else {
        out.writeUTF(localRef.getRefClass(out));
        localRef.writeExternal(out);
    }
}
 
Example #13
Source File: Util.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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);

    /* REMIND: private remote interfaces? */

    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);
    }
}
 
Example #14
Source File: RMIConnector.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public Constructor<?> run() throws Exception {
    Class thisClass = RMIConnector.class;
    ClassLoader thisLoader = thisClass.getClassLoader();
    ProtectionDomain thisProtectionDomain =
            thisClass.getProtectionDomain();
    String[] otherClassNames = {ProxyRef.class.getName()};
    ClassLoader cl =
            new NoCallStackClassLoader(pRefClassName,
            pRefByteCode,
            otherClassNames,
            thisLoader,
            thisProtectionDomain);
    Class<?> c = cl.loadClass(pRefClassName);
    return c.getConstructor(RemoteRef.class);
}
 
Example #15
Source File: Util.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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);

    /* REMIND: private remote interfaces? */

    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);
    }
}
 
Example #16
Source File: RMIConnector.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
private static RMIConnection shadowJrmpStub(RemoteObject stub)
throws InstantiationException, IllegalAccessException,
        InvocationTargetException, ClassNotFoundException,
        NoSuchMethodException {
    RemoteRef ref = stub.getRef();
    RemoteRef proxyRef = (RemoteRef)
        proxyRefConstructor.newInstance(new Object[] {ref});
    final Constructor<?> rmiConnectionImplStubConstructor =
        rmiConnectionImplStubClass.getConstructor(RemoteRef.class);
    Object[] args = {proxyRef};
    RMIConnection proxyStub = (RMIConnection)
    rmiConnectionImplStubConstructor.newInstance(args);
    return proxyStub;
}
 
Example #17
Source File: Test.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    System.err.println("\nRegression test for RFE 5096178\n");
    Class<? extends P> cl =
        Class.forName(PImpl.class.getName() + "_Stub").asSubclass(P.class);
    Constructor<? extends P> cons = cl.getConstructor(RemoteRef.class);
    cons.newInstance(new ArgCheckingRemoteRef(Boolean.FALSE)).m(false);
    cons.newInstance(new ArgCheckingRemoteRef(Boolean.TRUE)).m(true);
    System.err.println("TEST PASSED");
}
 
Example #18
Source File: RMIConnector.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public Constructor<?> run() throws Exception {
    Class thisClass = RMIConnector.class;
    ClassLoader thisLoader = thisClass.getClassLoader();
    ProtectionDomain thisProtectionDomain =
            thisClass.getProtectionDomain();
    String[] otherClassNames = {ProxyRef.class.getName()};
    ClassLoader cl =
            new NoCallStackClassLoader(pRefClassName,
            pRefByteCode,
            otherClassNames,
            thisLoader,
            thisProtectionDomain);
    Class<?> c = cl.loadClass(pRefClassName);
    return c.getConstructor(RemoteRef.class);
}
 
Example #19
Source File: ActivatableRef.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Write out external representation for remote ref.
 */
public void writeExternal(ObjectOutput out) throws IOException
{
    RemoteRef localRef = ref;

    out.writeObject(id);
    if (localRef == null) {
        out.writeUTF("");
    } else {
        out.writeUTF(localRef.getRefClass(out));
        localRef.writeExternal(out);
    }
}
 
Example #20
Source File: ActivatableRef.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Write out external representation for remote ref.
 */
public void writeExternal(ObjectOutput out) throws IOException
{
    RemoteRef localRef = ref;

    out.writeObject(id);
    if (localRef == null) {
        out.writeUTF("");
    } else {
        out.writeUTF(localRef.getRefClass(out));
        localRef.writeExternal(out);
    }
}
 
Example #21
Source File: Util.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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);

    /* REMIND: private remote interfaces? */

    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);
    }
}
 
Example #22
Source File: RMIConnector.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private static RMIConnection shadowJrmpStub(RemoteObject stub)
throws InstantiationException, IllegalAccessException,
        InvocationTargetException, ClassNotFoundException,
        NoSuchMethodException {
    RemoteRef ref = stub.getRef();
    RemoteRef proxyRef = (RemoteRef)
        proxyRefConstructor.newInstance(new Object[] {ref});
    final Constructor<?> rmiConnectionImplStubConstructor =
        rmiConnectionImplStubClass.getConstructor(RemoteRef.class);
    Object[] args = {proxyRef};
    RMIConnection proxyStub = (RMIConnection)
    rmiConnectionImplStubConstructor.newInstance(args);
    return proxyStub;
}
 
Example #23
Source File: Test.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    System.err.println("\nRegression test for RFE 5096178\n");
    Class<? extends P> cl =
        Class.forName(PImpl.class.getName() + "_Stub").asSubclass(P.class);
    Constructor<? extends P> cons = cl.getConstructor(RemoteRef.class);
    cons.newInstance(new ArgCheckingRemoteRef(Boolean.FALSE)).m(false);
    cons.newInstance(new ArgCheckingRemoteRef(Boolean.TRUE)).m(true);
    System.err.println("TEST PASSED");
}
 
Example #24
Source File: RMIConnector.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public Constructor<?> run() throws Exception {
    Class thisClass = RMIConnector.class;
    ClassLoader thisLoader = thisClass.getClassLoader();
    ProtectionDomain thisProtectionDomain =
            thisClass.getProtectionDomain();
    String[] otherClassNames = {ProxyRef.class.getName()};
    ClassLoader cl =
            new NoCallStackClassLoader(pRefClassName,
            pRefByteCode,
            otherClassNames,
            thisLoader,
            thisProtectionDomain);
    Class<?> c = cl.loadClass(pRefClassName);
    return c.getConstructor(RemoteRef.class);
}
 
Example #25
Source File: Util.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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);

    /* REMIND: private remote interfaces? */

    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);
    }
}
 
Example #26
Source File: RMIConnector.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
private static RMIConnection shadowJrmpStub(RemoteObject stub)
throws InstantiationException, IllegalAccessException,
        InvocationTargetException, ClassNotFoundException,
        NoSuchMethodException {
    RemoteRef ref = stub.getRef();
    RemoteRef proxyRef = (RemoteRef)
        proxyRefConstructor.newInstance(new Object[] {ref});
    final Constructor<?> rmiConnectionImplStubConstructor =
        rmiConnectionImplStubClass.getConstructor(RemoteRef.class);
    Object[] args = {proxyRef};
    RMIConnection proxyStub = (RMIConnection)
    rmiConnectionImplStubConstructor.newInstance(args);
    return proxyStub;
}
 
Example #27
Source File: Util.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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);

    /* REMIND: private remote interfaces? */

    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);
    }
}
 
Example #28
Source File: ActivatableRef.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * private method to obtain the ref for a call.
 */
private synchronized RemoteRef getRef()
    throws RemoteException
{
    if (ref == null) {
        ref = activate(false);
    }

    return ref;
}
 
Example #29
Source File: RMIConnector.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
public Constructor<?> run() throws Exception {
    Class thisClass = RMIConnector.class;
    ClassLoader thisLoader = thisClass.getClassLoader();
    ProtectionDomain thisProtectionDomain =
            thisClass.getProtectionDomain();
    String[] otherClassNames = {ProxyRef.class.getName()};
    ClassLoader cl =
            new NoCallStackClassLoader(pRefClassName,
            pRefByteCode,
            otherClassNames,
            thisLoader,
            thisProtectionDomain);
    Class<?> c = cl.loadClass(pRefClassName);
    return c.getConstructor(RemoteRef.class);
}
 
Example #30
Source File: ActivatableRef.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Write out external representation for remote ref.
 */
public void writeExternal(ObjectOutput out) throws IOException
{
    RemoteRef localRef = ref;

    out.writeObject(id);
    if (localRef == null) {
        out.writeUTF("");
    } else {
        out.writeUTF(localRef.getRefClass(out));
        localRef.writeExternal(out);
    }
}