Java Code Examples for java.rmi.server.RemoteRef

The following examples show how to use java.rmi.server.RemoteRef. These examples are extracted from open source projects. 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
/**
 * 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 Project: TencentKona-8   Source File: TestLibrary.java    License: 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 Project: openjdk-8   Source File: TestLibrary.java    License: 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
/**
 * private method to obtain the ref for a call.
 */
private synchronized RemoteRef getRef()
    throws RemoteException
{
    if (ref == null) {
        ref = activate(false);
    }

    return ref;
}
 
Example 5
Source Project: jdk8u_jdk   Source File: Test.java    License: 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 6
/**
 * private method to obtain the ref for a call.
 */
private synchronized RemoteRef getRef()
    throws RemoteException
{
    if (ref == null) {
        ref = activate(false);
    }

    return ref;
}
 
Example 7
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 8
Source Project: openjdk-8   Source File: Util.java    License: 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 9
Source Project: dragonwell8_jdk   Source File: Util.java    License: 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 10
Source Project: dragonwell8_jdk   Source File: RMIConnector.java    License: 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 Project: dragonwell8_jdk   Source File: RMIConnector.java    License: 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 12
Source Project: openjdk-8-source   Source File: Test.java    License: 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 13
Source Project: dragonwell8_jdk   Source File: Test.java    License: 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 14
Source Project: hottub   Source File: Util.java    License: 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 15
Source Project: jdk8u_jdk   Source File: ActivatableRef.java    License: 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 16
Source Project: TencentKona-8   Source File: Util.java    License: 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 17
Source Project: TencentKona-8   Source File: RMIConnector.java    License: 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 18
Source Project: jdk8u-jdk   Source File: Util.java    License: 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 19
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 20
Source Project: jdk8u-jdk   Source File: ActivatableRef.java    License: 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 Project: openjdk-jdk8u   Source File: RMIConnector.java    License: 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 22
Source Project: jdk8u60   Source File: ActivatableRef.java    License: 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 23
/**
 * 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 24
Source Project: jdk8u60   Source File: Util.java    License: 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 25
Source Project: openjdk-jdk8u   Source File: RMIConnector.java    License: 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 26
Source Project: jdk8u60   Source File: Test.java    License: 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 27
Source Project: hottub   Source File: RMIConnector.java    License: 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 28
Source Project: jdk8u_jdk   Source File: Util.java    License: 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 29
Source Project: JDKSourceCode1.8   Source File: RMIConnector.java    License: 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 30
Source Project: openjdk-jdk8u-backup   Source File: Util.java    License: 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);
    }
}