Java Code Examples for java.rmi.server.UnicastRemoteObject#exportObject()

The following examples show how to use java.rmi.server.UnicastRemoteObject#exportObject() . 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: ExportObjs.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Export remote objects.
 * Arguments: <# objects>
 */
public long run(String[] args) throws Exception {
    int size = Integer.parseInt(args[0]);
    Remote[] objs = new Remote[size];
    for (int i = 0; i < size; i++)
        objs[i] = new RemoteObj();

    long start = System.currentTimeMillis();
    for (int i = 0; i < size; i++)
        UnicastRemoteObject.exportObject(objs[i],0);
    long time = System.currentTimeMillis() - start;

    for (int i = 0; i < size; i++)
        UnicastRemoteObject.unexportObject(objs[i], true);
    return time;
}
 
Example 2
Source File: StandardRemoteDispatcherService.java    From openAGV with Apache License 2.0 6 votes vote down vote up
@Override
public void initialize() {
  if (isInitialized()) {
    return;
  }

  rmiRegistry = registryProvider.get();

  // Export this instance via RMI.
  try {
    LOG.debug("Exporting proxy...");
    UnicastRemoteObject.exportObject(this,
                                     configuration.remoteDispatcherServicePort(),
                                     socketFactoryProvider.getClientSocketFactory(),
                                     socketFactoryProvider.getServerSocketFactory());
    LOG.debug("Binding instance with RMI registry...");
    rmiRegistry.rebind(RegistrationName.REMOTE_DISPATCHER_SERVICE, this);
  }
  catch (RemoteException exc) {
    LOG.error("Could not export or bind with RMI registry", exc);
    return;
  }

  initialized = true;
}
 
Example 3
Source File: ShutdownImpl.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) {
    try {
        int registryPort = Integer.parseInt(System.getProperty("rmi.registry.port"));
        Registry registry =
            LocateRegistry.getRegistry("", registryPort);
        ShutdownMonitor monitor = (ShutdownMonitor)
            registry.lookup(KeepAliveDuringCall.BINDING);
        System.err.println("(ShutdownImpl) retrieved shutdown monitor");

        impl = new ShutdownImpl(monitor);
        Shutdown stub = (Shutdown) UnicastRemoteObject.exportObject(impl);
        System.err.println("(ShutdownImpl) exported shutdown object");

        monitor.submitShutdown(stub);
        System.err.println("(ShutdownImpl) submitted shutdown object");

    } catch (Exception e) {
        System.err.println("(ShutdownImpl) TEST SUBPROCESS FAILURE:");
        e.printStackTrace();
    }
}
 
Example 4
Source File: StandardRemoteKernel.java    From openAGV with Apache License 2.0 6 votes vote down vote up
@Override
public void initialize() {
  if (isInitialized()) {
    return;
  }
  registryProvider.initialize();
  userManager.initialize();

  rmiRegistry = registryProvider.get();
  // Export this instance via RMI.
  try {
    LOG.debug("Exporting proxy...");
    UnicastRemoteObject.exportObject(this,
                                     configuration.remoteKernelPort(),
                                     socketFactoryProvider.getClientSocketFactory(),
                                     socketFactoryProvider.getServerSocketFactory());
    LOG.debug("Binding instance with RMI registry...");
    rmiRegistry.rebind(org.opentcs.access.rmi.RemoteKernel.REGISTRATION_NAME, this);
    LOG.debug("Bound instance {} with registry {}.", rmiRegistry.list(), rmiRegistry);
  }
  catch (RemoteException exc) {
    LOG.error("Could not export or bind with RMI registry", exc);
  }
  enabled = true;
}
 
Example 5
Source File: ExportObjs.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Export remote objects.
 * Arguments: <# objects>
 */
public long run(String[] args) throws Exception {
    int size = Integer.parseInt(args[0]);
    Remote[] objs = new Remote[size];
    for (int i = 0; i < size; i++)
        objs[i] = new RemoteObj();

    long start = System.currentTimeMillis();
    for (int i = 0; i < size; i++)
        UnicastRemoteObject.exportObject(objs[i],0);
    long time = System.currentTimeMillis() - start;

    for (int i = 0; i < size; i++)
        UnicastRemoteObject.unexportObject(objs[i], true);
    return time;
}
 
Example 6
Source File: RMIJRMPServerImpl.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private void export(Remote obj) throws RemoteException {
    final RMIExporter exporter =
        (RMIExporter) env.get(RMIExporter.EXPORTER_ATTRIBUTE);
    final boolean daemon = EnvHelp.isServerDaemon(env);

    if (daemon && exporter != null) {
        throw new IllegalArgumentException("If "+EnvHelp.JMX_SERVER_DAEMON+
                " is specified as true, "+RMIExporter.EXPORTER_ATTRIBUTE+
                " cannot be used to specify an exporter!");
    }

    if (daemon) {
        if (csf == null && ssf == null) {
            new UnicastServerRef(port).exportObject(obj, null, true);
        } else {
            new UnicastServerRef2(port, csf, ssf).exportObject(obj, null, true);
        }
    } else if (exporter != null) {
        exporter.exportObject(obj, port, csf, ssf);
    } else {
        UnicastRemoteObject.exportObject(obj, port, csf, ssf);
    }
}
 
Example 7
Source File: StandardRemoteNotificationService.java    From openAGV with Apache License 2.0 6 votes vote down vote up
@Override
public void initialize() {
  if (isInitialized()) {
    return;
  }

  rmiRegistry = registryProvider.get();

  // Export this instance via RMI.
  try {
    LOG.debug("Exporting proxy...");
    UnicastRemoteObject.exportObject(this,
                                     configuration.remoteNotificationServicePort(),
                                     socketFactoryProvider.getClientSocketFactory(),
                                     socketFactoryProvider.getServerSocketFactory());
    LOG.debug("Binding instance with RMI registry...");
    rmiRegistry.rebind(RegistrationName.REMOTE_NOTIFICATION_SERVICE, this);
  }
  catch (RemoteException exc) {
    LOG.error("Could not export or bind with RMI registry", exc);
    return;
  }

  initialized = true;
}
 
Example 8
Source File: RapidExportUnexport.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    System.err.println("\nRegression test for bug 6275081\n");

    Remote impl = new Remote() { };
    long start = System.currentTimeMillis();
    for (int i = 0; i < REPS; i++) {
        System.err.println(i);
        UnicastRemoteObject.exportObject(impl, PORT);
        UnicastRemoteObject.unexportObject(impl, true);
        Thread.sleep(1);    // work around BindException (bug?)
    }
    long delta = System.currentTimeMillis() - start;
    System.err.println(REPS + " export/unexport operations took " +
                       delta + "ms");
    if (delta > TIMEOUT) {
        throw new Error("TEST FAILED: took over " + TIMEOUT + "ms");
    }
    System.err.println("TEST PASSED");
}
 
Example 9
Source File: RMIJRMPServerImpl.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
private void export(Remote obj) throws RemoteException {
    final RMIExporter exporter =
        (RMIExporter) env.get(RMIExporter.EXPORTER_ATTRIBUTE);
    final boolean daemon = EnvHelp.isServerDaemon(env);

    if (daemon && exporter != null) {
        throw new IllegalArgumentException("If "+EnvHelp.JMX_SERVER_DAEMON+
                " is specified as true, "+RMIExporter.EXPORTER_ATTRIBUTE+
                " cannot be used to specify an exporter!");
    }

    if (daemon) {
        if (csf == null && ssf == null) {
            new UnicastServerRef(port).exportObject(obj, null, true);
        } else {
            new UnicastServerRef2(port, csf, ssf).exportObject(obj, null, true);
        }
    } else if (exporter != null) {
        exporter.exportObject(obj, port, csf, ssf);
    } else {
        UnicastRemoteObject.exportObject(obj, port, csf, ssf);
    }
}
 
Example 10
Source File: ActivationGroupImpl.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates a default activation group implementation.
 *
 * @param id the group's identifier
 * @param data ignored
 */
public ActivationGroupImpl(ActivationGroupID id, MarshalledObject<?> data)
    throws RemoteException
{
    super(id);
    groupID = id;

    /*
     * Unexport activation group impl and attempt to export it on
     * an unshared anonymous port.  See 4692286.
     */
    unexportObject(this, true);
    RMIServerSocketFactory ssf = new ServerSocketFactoryImpl();
    UnicastRemoteObject.exportObject(this, 0, null, ssf);

    if (System.getSecurityManager() == null) {
        try {
            // Provide a default security manager.
            System.setSecurityManager(new SecurityManager());

        } catch (Exception e) {
            throw new RemoteException("unable to set security manager", e);
        }
    }
}
 
Example 11
Source File: PinLastArguments.java    From dragonwell8_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 bug 6332349\n");

    Ping impl = new PingImpl();
    Reference<?> ref = new WeakReference<Ping>(impl);
    try {
        Ping stub = (Ping) UnicastRemoteObject.exportObject(impl, 0);
        Object notSerializable = new Object();
        stub.ping(impl, null);
        try {
            stub.ping(impl, notSerializable);
        } catch (MarshalException e) {
            if (e.getCause() instanceof NotSerializableException) {
                System.err.println("ping invocation failed as expected");
            } else {
                throw e;
            }
        }
    } finally {
        UnicastRemoteObject.unexportObject(impl, true);
    }
    impl = null;

    // Might require multiple calls to System.gc() for weak-references
    // processing to be complete. If the weak-reference is not cleared as
    // expected we will hang here until timed out by the test harness.
    while (true) {
        System.gc();
        Thread.sleep(20);
        if (ref.get() == null) {
            break;
        }
    }

    System.err.println("TEST PASSED");
}
 
Example 12
Source File: ReuseDefaultPort.java    From dragonwell8_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 bug 6269166\n");
    RMISocketFactory.setSocketFactory(new SF());
    Remote impl = new ReuseDefaultPort();
    Remote stub = UnicastRemoteObject.exportObject(impl, 0);
    System.err.println("- exported object: " + stub);
    try {
        Registry registry = LocateRegistry.createRegistry(PORT);
        System.err.println("- exported registry: " + registry);
        System.err.println("TEST PASSED");
    } finally {
        UnicastRemoteObject.unexportObject(impl, true);
    }
}
 
Example 13
Source File: PinLastArguments.java    From TencentKona-8 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 bug 6332349\n");

    Ping impl = new PingImpl();
    Reference<?> ref = new WeakReference<Ping>(impl);
    try {
        Ping stub = (Ping) UnicastRemoteObject.exportObject(impl, 0);
        Object notSerializable = new Object();
        stub.ping(impl, null);
        try {
            stub.ping(impl, notSerializable);
        } catch (MarshalException e) {
            if (e.getCause() instanceof NotSerializableException) {
                System.err.println("ping invocation failed as expected");
            } else {
                throw e;
            }
        }
    } finally {
        UnicastRemoteObject.unexportObject(impl, true);
    }
    impl = null;

    // Might require multiple calls to System.gc() for weak-references
    // processing to be complete. If the weak-reference is not cleared as
    // expected we will hang here until timed out by the test harness.
    while (true) {
        System.gc();
        Thread.sleep(20);
        if (ref.get() == null) {
            break;
        }
    }

    System.err.println("TEST PASSED");
}
 
Example 14
Source File: NoConsoleOutput.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    Registry registry = TestLibrary.createRegistryOnUnusedPort();
    int registryPort = TestLibrary.getRegistryPort(registry);
    Registry reg = LocateRegistry.getRegistry("", registryPort);
    FooImpl fooimpl = new FooImpl();
    UnicastRemoteObject.exportObject(fooimpl, 0);
    reg.rebind("foo", fooimpl);
    Foo foostub = (Foo) reg.lookup("foo");
    FooImpl fooimpl2 = new FooImpl();
    UnicastRemoteObject.exportObject(fooimpl2, 0);
    foostub.echo(fooimpl2);
    UnicastRemoteObject.unexportObject(fooimpl, true);
    UnicastRemoteObject.unexportObject(fooimpl2, true);
}
 
Example 15
Source File: StandardRemoteKernelClientPortal.java    From openAGV with Apache License 2.0 5 votes vote down vote up
@Override
public void initialize() {
  if (isInitialized()) {
    return;
  }

  registryProvider.initialize();
  userManager.initialize();

  rmiRegistry = registryProvider.get();
  // Export this instance via RMI.
  try {
    LOG.debug("Exporting proxy...");
    UnicastRemoteObject.exportObject(this,
                                     configuration.remoteKernelServicePortalPort(),
                                     socketFactoryProvider.getClientSocketFactory(),
                                     socketFactoryProvider.getServerSocketFactory());
    LOG.debug("Binding instance with RMI registry...");
    rmiRegistry.rebind(RegistrationName.REMOTE_KERNEL_CLIENT_PORTAL, this);
    LOG.debug("Bound instance {} with registry {}.", rmiRegistry.list(), rmiRegistry);
  }
  catch (RemoteException exc) {
    LOG.error("Could not export or bind with RMI registry", exc);
    return;
  }

  for (KernelRemoteService remoteService : remoteServices) {
    remoteService.initialize();
  }

  initialized = true;
}
 
Example 16
Source File: readTest.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String args[]) throws Exception {
    try {
        testPkg.Server obj = new testPkg.Server();
        testPkg.Hello stub = (testPkg.Hello) UnicastRemoteObject.exportObject(obj, 0);
        // Bind the remote object's stub in the registry
        Registry registry =
            LocateRegistry.getRegistry(TestLibrary.READTEST_REGISTRY_PORT);
        registry.bind("Hello", stub);

        System.err.println("Server ready");

        // now, let's test client
        testPkg.Client client =
            new testPkg.Client(TestLibrary.READTEST_REGISTRY_PORT);
        String testStubReturn = client.testStub();
        if(!testStubReturn.equals(obj.hello)) {
            throw new RuntimeException("Test Fails : unexpected string from stub call");
        } else {
            System.out.println("Test passed");
        }
        registry.unbind("Hello");

    } catch (Exception e) {
        System.err.println("Server exception: " + e.toString());
        e.printStackTrace();
    }

}
 
Example 17
Source File: ReuseDefaultPort.java    From TencentKona-8 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 bug 6269166\n");
    RMISocketFactory.setSocketFactory(new SF());
    Remote impl = new ReuseDefaultPort();
    Remote stub = UnicastRemoteObject.exportObject(impl, 0);
    System.err.println("- exported object: " + stub);
    try {
        Registry registry = LocateRegistry.createRegistry(PORT);
        System.err.println("- exported registry: " + registry);
        System.err.println("TEST PASSED");
    } finally {
        UnicastRemoteObject.unexportObject(impl, true);
    }
}
 
Example 18
Source File: DGCImplInsulation.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
public Object run() throws Exception {
    return UnicastRemoteObject.exportObject(impl);
}
 
Example 19
Source File: MultipleRegistries.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {

        RemoteInterface server = null;
        RemoteInterface proxy = null;

        try {
            System.err.println("export object");
            server = new MultipleRegistries();
            proxy =
                (RemoteInterface) UnicastRemoteObject.exportObject(server, 0);

            System.err.println("proxy = " + proxy);

            System.err.println("export registries");
            Registry registryImpl1 = TestLibrary.createRegistryOnUnusedPort();
            int port1 = TestLibrary.getRegistryPort(registryImpl1);
            Registry registryImpl2 = TestLibrary.createRegistryOnUnusedPort();
            int port2 = TestLibrary.getRegistryPort(registryImpl2);
            System.err.println("bind remote object in registries");
            Registry registry1 = LocateRegistry.getRegistry(port1);
            Registry registry2 = LocateRegistry.getRegistry(port2);

            registry1.bind(NAME, proxy);
            registry2.bind(NAME, proxy);

            System.err.println("lookup remote object in registries");

            RemoteInterface remote1 = (RemoteInterface) registry1.lookup(NAME);
            RemoteInterface remote2 = (RemoteInterface) registry2.lookup(NAME);

            System.err.println("invoke methods on remote objects");
            remote1.passObject(remote1);
            remote2.passObject(remote2);

            System.err.println("TEST PASSED");

        } finally {
            if (proxy != null) {
                UnicastRemoteObject.unexportObject(server, true);
            }
        }
    }
 
Example 20
Source File: PortableRemoteObject.java    From jdk1.8-source-analysis with Apache License 2.0 3 votes vote down vote up
/**
 * Makes a server object ready to receive remote calls. Note
 * that subclasses of PortableRemoteObject do not need to call this
 * method, as it is called by the constructor.
 * @param obj the server object to export.
 * @exception RemoteException if export fails.
 */
public void exportObject(Remote obj)
    throws RemoteException {

    if (obj == null) {
        throw new NullPointerException("invalid argument");
    }

    // Has this object already been exported to IIOP?

    if (Util.getTie(obj) != null) {

        // Yes, so this is an error...

        throw new ExportException (obj.getClass().getName() + " already exported");
    }

    // Can we load a Tie?

    Tie theTie = Utility.loadTie(obj);

    if (theTie != null) {

        // Yes, so export it to IIOP...

        Util.registerTarget(theTie,obj);

    } else {

        // No, so export to JRMP. If this is called twice for the
        // same object, it will throw an ExportException...

        UnicastRemoteObject.exportObject(obj);
    }
}