Java Code Examples for java.rmi.server.UnicastRemoteObject

The following examples show how to use java.rmi.server.UnicastRemoteObject. 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
Source Project: Flink-CEPplus   Source File: JMXReporter.java    License: Apache License 2.0 6 votes vote down vote up
public void stop() throws IOException {
	if (connector != null) {
		try {
			connector.stop();
		} finally {
			connector = null;
		}
	}
	if (rmiRegistry != null) {
		try {
			UnicastRemoteObject.unexportObject(rmiRegistry, true);
		} catch (NoSuchObjectException e) {
			throw new IOException("Could not un-export our RMI registry", e);
		} finally {
			rmiRegistry = null;
		}
	}
}
 
Example 2
Source Project: openAGV   Source File: StandardRemoteDispatcherService.java    License: 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 Project: openAGV   Source File: StandardRemoteDispatcherService.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(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 4
Source Project: openAGV   Source File: StandardRemoteRouterService.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(RegistrationName.REMOTE_ROUTER_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 5
Source Project: openAGV   Source File: StandardRemotePlantModelService.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(RegistrationName.REMOTE_PLANT_MODEL_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
Source Project: openAGV   Source File: StandardRemoteSchedulerService.java    License: 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.remoteSchedulerServicePort(),
                                     socketFactoryProvider.getClientSocketFactory(),
                                     socketFactoryProvider.getServerSocketFactory());
    LOG.debug("Binding instance with RMI registry...");
    rmiRegistry.rebind(RegistrationName.REMOTE_SCHEDULER_SERVICE, this);
  }
  catch (RemoteException exc) {
    LOG.error("Could not export or bind with RMI registry", exc);
    return;
  }

  initialized = true;
}
 
Example 7
Source Project: openAGV   Source File: StandardRemoteSchedulerService.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(RegistrationName.REMOTE_SCHEDULER_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 8
Source Project: openAGV   Source File: StandardRemoteVehicleService.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(RegistrationName.REMOTE_VEHICLE_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 9
Source Project: openAGV   Source File: StandardRemoteKernel.java    License: 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 10
Source Project: TencentKona-8   Source File: ShutdownImpl.java    License: GNU General Public License v2.0 6 votes vote down vote up
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 11
Source Project: openAGV   Source File: StandardRemoteKernelClientPortal.java    License: Apache License 2.0 6 votes vote down vote up
@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 12
@Override
public void initialize() {
  if (isInitialized()) {
    return;
  }

  rmiRegistry = registryProvider.get();

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

  initialized = true;
}
 
Example 13
@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 14
Source Project: openAGV   Source File: StandardRemoteNotificationService.java    License: 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 15
Source Project: openAGV   Source File: StandardRemoteNotificationService.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(RegistrationName.REMOTE_NOTIFICATION_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 16
/**
 * Deregisters a server object from the runtime, allowing the object to become
 * available for garbage collection.
 * @param obj the object to unexport.
 * @exception NoSuchObjectException if the remote object is not
 * currently exported.
 */
public void unexportObject(Remote obj)
    throws NoSuchObjectException {

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

    if (StubAdapter.isStub(obj) ||
        obj instanceof java.rmi.server.RemoteStub) {
        throw new NoSuchObjectException(
            "Can only unexport a server object.");
    }

    Tie theTie = Util.getTie(obj);
    if (theTie != null) {
        Util.unexportObject(obj);
    } else {
        if (Utility.loadTie(obj) == null) {
            UnicastRemoteObject.unexportObject(obj,true);
        } else {
            throw new NoSuchObjectException("Object not exported.");
        }
    }
}
 
Example 17
Source Project: jdk1.8-source-analysis   Source File: RMIJRMPServerImpl.java    License: Apache License 2.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 18
Source Project: flink   Source File: JMXReporter.java    License: Apache License 2.0 6 votes vote down vote up
public void stop() throws IOException {
	if (connector != null) {
		try {
			connector.stop();
		} finally {
			connector = null;
		}
	}
	if (rmiRegistry != null) {
		try {
			UnicastRemoteObject.unexportObject(rmiRegistry, true);
		} catch (NoSuchObjectException e) {
			throw new IOException("Could not un-export our RMI registry", e);
		} finally {
			rmiRegistry = null;
		}
	}
}
 
Example 19
/**
 * 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 20
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 21
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 22
Source Project: dragonwell8_jdk   Source File: ExportObjs.java    License: 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 23
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 24
Source Project: dragonwell8_jdk   Source File: ShutdownImpl.java    License: GNU General Public License v2.0 6 votes vote down vote up
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 25
/**
 * Deregisters a server object from the runtime, allowing the object to become
 * available for garbage collection.
 * @param obj the object to unexport.
 * @exception NoSuchObjectException if the remote object is not
 * currently exported.
 */
public void unexportObject(Remote obj)
    throws NoSuchObjectException {

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

    if (StubAdapter.isStub(obj) ||
        obj instanceof java.rmi.server.RemoteStub) {
        throw new NoSuchObjectException(
            "Can only unexport a server object.");
    }

    Tie theTie = Util.getTie(obj);
    if (theTie != null) {
        Util.unexportObject(obj);
    } else {
        if (Utility.loadTie(obj) == null) {
            UnicastRemoteObject.unexportObject(obj,true);
        } else {
            throw new NoSuchObjectException("Object not exported.");
        }
    }
}
 
Example 26
/**
 * 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 27
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 28
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 29
Source Project: TencentKona-8   Source File: ExportObjs.java    License: 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 30
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");
}