Example usage for java.rmi.server UnicastRemoteObject unexportObject

List of usage examples for java.rmi.server UnicastRemoteObject unexportObject

Introduction

In this page you can find the example usage for java.rmi.server UnicastRemoteObject unexportObject.

Prototype

public static boolean unexportObject(Remote obj, boolean force) throws java.rmi.NoSuchObjectException 

Source Link

Document

Removes the remote object, obj, from the RMI runtime.

Usage

From source file:au.com.jwatmuff.genericp2p.rmi.RMIPeerManager.java

@Override
public void refreshServices() {
    try {/*w w w.  j  ava  2s  .c o  m*/
        // Restart RMI Registry
        UnicastRemoteObject.unexportObject(registry, true);
        registry = LocateRegistry.createRegistry(registryPort);

        // Re-export services to new RMI Registry
        for (PeerService service : peerServiceMap.values()) {
            refreshService(service);
        }

        addSelf();
    } catch (Exception e) {
        log.error("Failed to refresh services", e);
    }
}

From source file:net.sf.ehcache.distribution.RMICacheManagerPeerListener.java

/**
 * Unbinds an RMICachePeer and unexports it.
 * <p/>/* www .  ja va 2  s.  co m*/
 * We unbind from the registry first before unexporting.
 * Unbinding first removes the very small possibility of a client
 * getting the object from the registry while we are trying to unexport it.
 * <p/>
 * This method may take up to 4 seconds to complete, if we are having trouble
 * unexporting the peer.
 *
 * @param rmiCachePeer the bound and exported cache peer
 * @throws Exception
 */
protected void unbind(RMICachePeer rmiCachePeer) throws Exception {
    String url = rmiCachePeer.getUrl();
    try {
        Naming.unbind(url);
    } catch (NotBoundException e) {
        LOG.warn(url + " not bound therefore not unbinding.");
    }
    // Try to gracefully unexport before forcing it.
    boolean unexported = UnicastRemoteObject.unexportObject(rmiCachePeer, false);
    for (int count = 1; (count < NAMING_UNBIND_MAX_RETRIES) && !unexported; count++) {
        try {
            Thread.sleep(NAMING_UNBIND_RETRY_INTERVAL);
        } catch (InterruptedException ie) {
            // break out of the unexportObject loop
            break;
        }
        unexported = UnicastRemoteObject.unexportObject(rmiCachePeer, false);
    }

    // If we still haven't been able to unexport, force the unexport
    // as a last resort.
    if (!unexported) {
        if (!UnicastRemoteObject.unexportObject(rmiCachePeer, true)) {
            LOG.warn("Unable to unexport rmiCachePeer: " + rmiCachePeer.getUrl() + ".  Skipping.");
        }
    }
}

From source file:org.wso2.andes.server.management.JMXManagedObjectRegistry.java

public void close() {
    if (_cs != null) {
        // Stopping the JMX ConnectorServer
        try {//  w ww .j  av a  2 s.c o m
            CurrentActor.get().message(ManagementConsoleMessages.SHUTTING_DOWN("JMX RMIConnectorServer",
                    _cs.getAddress().getPort()));
            _cs.stop();
        } catch (IOException e) {
            _log.error("Exception while closing the JMX ConnectorServer: " + e.getMessage());
        }
    }

    if (_rmiRegistry != null) {
        // Stopping the RMI registry
        CurrentActor.get().message(ManagementConsoleMessages.SHUTTING_DOWN("RMI Registry",
                _cs.getAddress().getPort() - PORT_EXPORT_OFFSET));
        try {
            UnicastRemoteObject.unexportObject(_rmiRegistry, false);
        } catch (NoSuchObjectException e) {
            _log.error("Exception while closing the RMI Registry: " + e.getMessage());
        }
    }

    //ObjectName query to gather all Qpid related MBeans
    ObjectName mbeanNameQuery = null;
    try {
        mbeanNameQuery = new ObjectName(ManagedObject.DOMAIN + ":*");
    } catch (Exception e1) {
        _log.warn("Unable to generate MBean ObjectName query for close operation");
    }

    for (ObjectName name : _mbeanServer.queryNames(mbeanNameQuery, null)) {
        try {
            _mbeanServer.unregisterMBean(name);
        } catch (JMException e) {
            _log.error("Exception unregistering MBean '" + name + "': " + e.getMessage());
        }
    }

    CurrentActor.get().message(ManagementConsoleMessages.STOPPED());
}

From source file:com.healthmarketscience.rmiio.RemoteStreamServerTest.java

@SuppressWarnings("unchecked")
public static List<List<File>> mainTest(String[] args, final List<Throwable> clientExceptions,
        final List<AccumulateRemoteStreamMonitor<?>> monitors) throws Exception {
    final String testFile = args[0];
    final boolean doAbort = ((args.length > 1) ? Boolean.parseBoolean(args[1]) : false);
    final boolean reverse = ((args.length > 2) ? Boolean.parseBoolean(args[2]) : false);
    final boolean doSkip = ((args.length > 3) ? Boolean.parseBoolean(args[3]) : false);
    final boolean doFastTests = ((args.length > 4) ? Boolean.parseBoolean(args[4]) : false);
    final List<List<File>> tempFiles = Arrays.asList(Collections.synchronizedList(new LinkedList<File>()),
            Collections.synchronizedList(new LinkedList<File>()));

    FileServer server = new FileServer(testFile, tempFiles, monitors);
    final RemoteFileServer stub = (RemoteFileServer) simulateRemote(
            UnicastRemoteObject.exportObject(server, 0));
    LOG.debug("Server ready");

    LOG.debug("Sleeping 3000 ms...");
    Thread.sleep(3000);/*from w  ww.  ja  v a  2s. com*/

    LOG.debug("Running 'reliable' tests");
    Thread clientThread = new Thread(new Runnable() {
        public void run() {
            clientExceptions.addAll(FileClient.main(stub, testFile, tempFiles, doAbort, reverse, doSkip, false,
                    doFastTests, monitors));
        }
    });
    clientThread.start();
    clientThread.join();

    if (!doFastTests) {
        server.setUnreliable(true);

        LOG.debug("Running 'unreliable' tests");
        clientThread = new Thread(new Runnable() {
            public void run() {
                clientExceptions.addAll(FileClient.main(stub, testFile, tempFiles, doAbort, reverse, doSkip,
                        true, doFastTests, monitors));
            }
        });
        clientThread.start();
        clientThread.join();
    }

    LOG.debug("Unexporting server");
    UnicastRemoteObject.unexportObject(server, true);

    return tempFiles;
}

From source file:de.tudarmstadt.lt.lm.app.StartLM.java

void stopRMI() {
    if (_app_serves_rmi_registry)
        try {/*  w w w .jav  a 2 s .  co m*/
            UnicastRemoteObject.unexportObject(_registry, true);
            LOG.info("Stopped RMI server.");
        } catch (NoSuchObjectException e) {
            /* handle silently */ }
}

From source file:org.ops4j.pax.exam.karaf.container.internal.KarafTestContainer.java

@Override
public synchronized TestContainer stop() {
    LOGGER.debug("Shutting down the test container (Pax Runner)");
    try {/*from w w  w. ja v a2s.co m*/
        if (started) {
            target.stop();
            RemoteBundleContextClient remoteBundleContextClient = target.getClientRBC();
            if (remoteBundleContextClient != null) {
                remoteBundleContextClient.stop();

            }
            if (runner != null) {
                runner.shutdown();
            }
            try {
                UnicastRemoteObject.unexportObject(rgstry, true);
                /*
                 * NOTE: javaRunner.waitForExit() works for Equinox and Felix, but not for Knopflerfish,
                 * need to investigate why. OTOH, it may be better to kill the process as we're doing
                 * now, just to be on the safe side.
                 */
            } catch (NoSuchObjectException exc) {
                throw new TestContainerException(exc);
            }

        } else {
            throw new RuntimeException("Container never came up");
        }
    } finally {
        started = false;
        target = null;
        if (shouldDeleteRuntime()) {
            system.clear();
            try {
                FileUtils.forceDelete(targetFolder);
            } catch (IOException e) {
                forceCleanup();
            }
        }
    }
    return this;
}

From source file:de.clusteval.framework.ClustevalBackendServer.java

/**
 * A helper method for {@link #shutdown(String, long)}, which terminates
 * this framework after a certain timeout.
 * /*from  w  w  w .  ja  v  a 2 s .  c  o m*/
 * <p>
 * This method first interrupts the supervisor thread (see
 * {@link SupervisorThread}) and waits for its termination until the timeout
 * was reached.
 * 
 * <p>
 * Then the backend server instance is unregistered from the RMI registry
 * and the repository of this framework is removed from the set of all
 * registered repositories.
 * 
 * @throws InterruptedException
 * 
 */
private void terminate(final long forceTimeout) throws InterruptedException {
    this.repository.terminateSupervisorThread();

    try {
        Registry registry = LocateRegistry.getRegistry(port);
        registry.unbind("EvalServer");
        UnicastRemoteObject.unexportObject(this, true);
    } catch (NoSuchObjectException e) {
        e.printStackTrace();
    } catch (AccessException e) {
        e.printStackTrace();
    } catch (RemoteException e) {
        e.printStackTrace();
    } catch (NotBoundException e) {
        e.printStackTrace();
    }
    /*
     * unregister repository
     */
    Repository.unregister(this.repository);
    // should work without, just to be sure
    // System.exit(0);
}

From source file:org.apache.jackrabbit.j2ee.RepositoryStartupServlet.java

/**
 * Unregisters the repository from the RMI registry, if it has previously
 * been registered./* w ww.  j ava2  s. c om*/
 */
private void unregisterRMI() {
    if (rmiRepository != null) {
        // Forcibly unexport the repository;
        try {
            UnicastRemoteObject.unexportObject(rmiRepository, true);
        } catch (NoSuchObjectException e) {
            log.warn("Odd, the RMI repository was not exported", e);
        }
        // drop strong reference to remote repository
        rmiRepository = null;

        // unregister repository
        try {
            Naming.unbind(config.getRmiConfig().getRmiUri());
        } catch (Exception e) {
            log("Error while unbinding repository from JNDI: " + e);
        }
    }

    if (rmiRegistry != null) {
        try {
            UnicastRemoteObject.unexportObject(rmiRegistry, true);
        } catch (NoSuchObjectException e) {
            log.warn("Odd, the RMI registry was not exported", e);
        }
        rmiRegistry = null;
    }
}

From source file:org.viafirma.nucleo.Nucleo.java

/**
 * Muestra un mensaje cuando se apacha el Nucleo.
 * /*from   w  ww.jav  a2 s.  c  o  m*/
 * @see javax.servlet.ServletContextListener#contextDestroyed(javax.servlet.ServletContextEvent)
 */
@Override
public void contextDestroyed(ServletContextEvent contextEvent) {
    // apagamos las diferentes caches.
    cacheCertificados.getCacheManager().removalAll();
    CacheManager.getInstance().shutdown();
    // Detenemos el registro RMI
    if (rmiRegistry != null) {
        try {
            rmiRegistry.unbind(Constantes.NOMBRE_CONECOR_RMI_PUBLICADO);
            // Detenemos el registro RMI.
            UnicastRemoteObject.unexportObject(rmiRegistry, true);
            rmiRegistry = null;
        } catch (Exception e) {
            log.warn("No se puede detener el registro RMI del motor de formularios." + e.getMessage());
        }
        log.info("Desactivando el registro RMI");
    }
    // Desactivamos el manejador de conexiones http
    MultiThreadedHttpConnectionManager.shutdownAll();

    System.out.println("Nucleo Viafirma apagado. " + this);
    super.contextDestroyed(contextEvent);

}

From source file:org.gtdfree.GTDFree.java

private void aborting() {

    logger.debug("Cleanup while engine aborting."); //$NON-NLS-1$

    if (closed) {
        return;//from w  w w.  j  a v a  2  s .c  o  m
    }

    if (monitor != null) {
        monitor.close();
    }

    if (flasher != null) {
        flasher.dispose();
    }

    if (dbInfoDialog != null) {
        dbInfoDialog.dispose();
    }
    if (jFrame != null) {
        jFrame.dispose();
    }
    if (trayIconPopup != null) {
        trayIconPopup.setVisible(false);
    }
    if (trayIcon != null) {
        SystemTray.getSystemTray().remove(trayIcon);
    }

    if (stub != null) {
        try {
            stub = null;
            UnicastRemoteObject.unexportObject(this, true);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}