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

The following examples show how to use java.rmi.server.UnicastRemoteObject#unexportObject() . 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
@Override
public void terminate() {
  if (!isInitialized()) {
    return;
  }

  try {
    LOG.debug("Unbinding from RMI registry...");
    rmiRegistry.unbind(RegistrationName.REMOTE_DISPATCHER_SERVICE);
    LOG.debug("Unexporting RMI interface...");
    UnicastRemoteObject.unexportObject(this, true);
  }
  catch (RemoteException | NotBoundException exc) {
    LOG.warn("Exception shutting down RMI interface", exc);
  }

  initialized = false;
}
 
Example 2
private void checkInactiveGroup() {
    boolean groupMarkedInactive = false;
    synchronized (this) {
        if (active.size() == 0 && lockedIDs.size() == 0 &&
            groupInactive == false)
        {
            groupInactive = true;
            groupMarkedInactive = true;
        }
    }

    if (groupMarkedInactive) {
        try {
            super.inactiveGroup();
        } catch (Exception ignoreDeactivateFailure) {
        }

        try {
            UnicastRemoteObject.unexportObject(this, true);
        } catch (NoSuchObjectException allowUnexportedGroup) {
        }
    }
}
 
Example 3
Source Project: openAGV   File: StandardRemoteKernel.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void terminate() {
  if (!isInitialized()) {
    return;
  }
  try {
    LOG.debug("Unbinding from RMI registry...");
    rmiRegistry.unbind(org.opentcs.access.rmi.RemoteKernel.REGISTRATION_NAME);
    LOG.debug("Unexporting RMI interface...");
    UnicastRemoteObject.unexportObject(this, true);
  }
  catch (RemoteException | NotBoundException exc) {
    LOG.warn("Exception shutting down RMI interface", exc);
  }
  userManager.terminate();
  registryProvider.terminate();
  enabled = false;
}
 
Example 4
@Override
public void terminate() {
  if (!isInitialized()) {
    return;
  }

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

  try {
    LOG.debug("Unbinding from RMI registry...");
    rmiRegistry.unbind(RegistrationName.REMOTE_KERNEL_CLIENT_PORTAL);
    LOG.debug("Unexporting RMI interface...");
    UnicastRemoteObject.unexportObject(this, true);
  }
  catch (RemoteException | NotBoundException exc) {
    LOG.warn("Exception shutting down RMI interface", exc);
  }

  userManager.terminate();
  registryProvider.terminate();
  initialized = false;
}
 
Example 5
@Override
public void terminate() {
  if (!isInitialized()) {
    return;
  }

  try {
    LOG.debug("Unbinding from RMI registry...");
    rmiRegistry.unbind(RegistrationName.REMOTE_TRANSPORT_ORDER_SERVICE);
    LOG.debug("Unexporting RMI interface...");
    UnicastRemoteObject.unexportObject(this, true);
  }
  catch (RemoteException | NotBoundException exc) {
    LOG.warn("Exception shutting down RMI interface", exc);
  }

  initialized = false;
}
 
Example 6
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 7
public void shutdown() {
    try {
        System.err.println(
            "(ShutdownImpl.shutdown) shutdown method invoked:");

        UnicastRemoteObject.unexportObject(this, true);
        System.err.println(
            "(ShutdownImpl.shutdown) shutdown object unexported");

        Thread.sleep(500);
        System.err.println("(ShutDownImpl.shutdown) FEE");
        Thread.sleep(500);
        System.err.println("(ShutDownImpl.shutdown) FIE");
        Thread.sleep(500);
        System.err.println("(ShutDownImpl.shutdown) FOE");
        Thread.sleep(500);
        System.err.println("(ShutDownImpl.shutdown) FOO");

        monitor.declareStillAlive();
        System.err.println("(ShutDownImpl.shutdown) still alive!");
    } catch (Exception e) {
        throw new RuntimeException(
            "unexpected exception occurred in shutdown method", e);
    }
}
 
Example 8
/**
 * Unexport the registered RMI object, logging any exception that arises.
 */
private void unexportObjectSilently() {
	try {
		UnicastRemoteObject.unexportObject(this.exportedObject, true);
	}
	catch (NoSuchObjectException ex) {
		if (logger.isInfoEnabled()) {
			logger.info("RMI object for service '" + this.serviceName + "' is not exported anymore", ex);
		}
	}
}
 
Example 9
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 10
private static void unexport(Remote obj) {
    for (;;) {
        try {
            if (UnicastRemoteObject.unexportObject(obj, false) == true) {
                break;
            } else {
                Thread.sleep(100);
            }
        } catch (Exception e) {
            continue;
        }
    }
}
 
Example 11
/**
 * Unexport the registered RMI object, logging any exception that arises.
 */
private void unexportObjectSilently() {
	try {
		UnicastRemoteObject.unexportObject(this.exportedObject, true);
	}
	catch (NoSuchObjectException ex) {
		if (logger.isInfoEnabled()) {
			logger.info("RMI object for service '" + this.serviceName + "' is not exported anymore", ex);
		}
	}
}
 
Example 12
public static void main(String[] args) throws Exception {
    Remote impl2 = null;
    try {
        Remote impl = new MarshalAfterUnexport();
        System.err.println("created impl extending URO: " + impl);

        Receiver stub = (Receiver) RemoteObject.toStub(impl);
        System.err.println("stub for impl: " + stub);

        UnicastRemoteObject.unexportObject(impl, true);
        System.err.println("unexported impl");

        impl2 = new MarshalAfterUnexport();
        Receiver stub2 = (Receiver) RemoteObject.toStub(impl2);

        System.err.println("marshalling unexported object:");
        MarshalledObject mobj = new MarshalledObject(impl);

        System.err.println("passing unexported object via RMI-JRMP:");
        stub2.receive(stub);

        System.err.println("TEST PASSED");
    } finally {
        if (impl2 != null) {
            try {
                UnicastRemoteObject.unexportObject(impl2, true);
            } catch (Throwable t) {
            }
        }
    }
}
 
Example 13
/** routine to unexport an object */
public static void unexport(Remote obj) {
    if (obj != null) {
        try {
            mesg("unexporting object...");
            UnicastRemoteObject.unexportObject(obj, true);
        } catch (NoSuchObjectException munch) {
        } catch (Exception e) {
            e.getMessage();
            e.printStackTrace();
        }
    }
}
 
Example 14
/** routine to unexport an object */
public static void unexport(Remote obj) {
    if (obj != null) {
        try {
            mesg("unexporting object...");
            UnicastRemoteObject.unexportObject(obj, true);
        } catch (NoSuchObjectException munch) {
        } catch (Exception e) {
            e.getMessage();
            e.printStackTrace();
        }
    }
}
 
Example 15
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);
            }
        }
    }
 
Example 16
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 17
public static void main(String[] args) throws Exception {

        RemoteInterface server1 = null;
        RemoteInterface server2 = null;
        RemoteInterface stub = null;
        RemoteInterface proxy = null;

        try {
            System.setProperty("java.rmi.server.ignoreStubClasses", "true");

            if (System.getSecurityManager() == null) {
                System.setSecurityManager(new SecurityManager());
            }

            System.err.println("export objects");
            server1 = new ToStub();
            server2 = new ToStub();
            stub = (RemoteInterface) UnicastRemoteObject.exportObject(server1);
            proxy = (RemoteInterface)
                UnicastRemoteObject.exportObject(server2, 0);

            System.err.println("test toStub");
            if (stub != RemoteObject.toStub(server1)) {
                throw new RuntimeException(
                    "toStub returned incorrect value for server1");
            }

            if (!Proxy.isProxyClass(proxy.getClass())) {
                throw new RuntimeException("proxy is not a dynamic proxy");
            }

            if (proxy != RemoteObject.toStub(server2)) {
                throw new RuntimeException(
                    "toStub returned incorrect value for server2");
            }

            try {
                RemoteObject.toStub(new ToStub());
                throw new RuntimeException(
                    "stub returned for exported object!");
            } catch (NoSuchObjectException nsoe) {
            }

            System.err.println("invoke methods");
            Object obj = stub.passObject(stub);
            if (!stub.equals(obj)) {
                throw new RuntimeException("returned stub not equal");
            }

            obj = proxy.passObject(proxy);
            if (!proxy.equals(obj)) {
                throw new RuntimeException("returned proxy not equal");
            }

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

        } finally {
            if (stub != null) {
                UnicastRemoteObject.unexportObject(server1, true);
            }

            if (proxy != null) {
                UnicastRemoteObject.unexportObject(server2, true);
            }
        }
    }
 
Example 18
public static void main(String[] args) throws Exception {
    System.err.println("\nRegression test for bug 6261402\n");
    System.setProperty("java.rmi.activation.port",
                       Integer.toString(TestLibrary.INHERITEDCHANNELNOTSERVERSOCKET_ACTIVATION_PORT));
    RMID rmid = null;
    Callback obj = null;
    try {
        /*
         * Export callback object and bind in registry.
         */
        System.err.println("export callback object and bind in registry");
        obj = new CallbackImpl();
        Callback proxy =
            (Callback) UnicastRemoteObject.exportObject(obj, 0);
        Registry registry =
            LocateRegistry.createRegistry(
                TestLibrary.INHERITEDCHANNELNOTSERVERSOCKET_REGISTRY_PORT);
        registry.bind("Callback", proxy);

        /*
         * Start rmid.
         */
        System.err.println("start rmid with inherited channel");
        RMID.removeLog();
        rmid = RMID.createRMID(System.out, System.err, true, true,
                               TestLibrary.INHERITEDCHANNELNOTSERVERSOCKET_ACTIVATION_PORT);
        rmid.addOptions(new String[]{
            "-Djava.nio.channels.spi.SelectorProvider=" +
            "InheritedChannelNotServerSocket$SP"});
        rmid.start();

        /*
         * Get activation system and wait to be notified via callback
         * from rmid's selector provider.
         */
        System.err.println("get activation system");
        ActivationSystem system = ActivationGroup.getSystem();
        System.err.println("ActivationSystem = " + system);
        synchronized (lock) {
            while (!notified) {
                lock.wait();
            }
        }
        System.err.println("TEST PASSED");
    } finally {
        if (obj != null) {
            UnicastRemoteObject.unexportObject(obj, true);
        }
        ActivationLibrary.rmidCleanup(rmid);
    }
}
 
Example 19
public static void main(String[] args) throws Exception {
    System.err.println("\nRegression test for bug 4486732\n");

    Factory factoryImpl = new FactoryImpl();
    Factory factoryStub =
        (Factory) UnicastRemoteObject.exportObject(factoryImpl, 0);
    for (int i = 0; i < SESSIONS; i++) {
        Session session = factoryStub.getSession();
        session.ping();
    }
    UnicastRemoteObject.unexportObject(factoryImpl, true);

    Registry registryImpl = TestLibrary.createRegistryOnEphemeralPort();
    int port = TestLibrary.getRegistryPort(registryImpl);
    System.out.println("Registry listening on port " + port);

    CSF csf = new CSF();
    Reference<CSF> registryRef = new WeakReference<CSF>(csf);
    Registry registryStub = LocateRegistry.getRegistry("", port, csf);
    csf = null;
    registryStub.list();
    registryStub = null;
    UnicastRemoteObject.unexportObject(registryImpl, true);

    System.gc();
    // allow connections to time out
    Thread.sleep(3 * Long.getLong("sun.rmi.transport.connectionTimeout",
                                  15000));
    System.gc();

    if (CSF.deserializedInstances.size() != SESSIONS) {
        throw new Error("unexpected number of deserialized instances: " +
                        CSF.deserializedInstances.size());
    }

    int nonNullCount = 0;
    for (Reference<CSF> ref : CSF.deserializedInstances) {
        csf = ref.get();
        if (csf != null) {
            System.err.println("non-null deserialized instance: " + csf);
            nonNullCount++;
        }
    }
    if (nonNullCount > 0) {
        throw new Error("TEST FAILED: " +
                        nonNullCount + " non-null deserialized instances");
    }

    csf = registryRef.get();
    if (csf != null) {
        System.err.println("non-null registry instance: " + csf);
        throw new Error("TEST FAILED: non-null registry instance");
    }

    System.err.println("TEST PASSED");
}
 
Example 20
public boolean unexportObject(Remote obj, boolean force)
        throws NoSuchObjectException {
    return UnicastRemoteObject.unexportObject(obj, force);
}