java.rmi.server.UnicastRemoteObject Java Examples

The following examples show how to use java.rmi.server.UnicastRemoteObject. 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: StandardRemoteTransportOrderService.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.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 #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: StandardRemoteVehicleService.java    From openAGV with 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 #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: JMXReporter.java    From Flink-CEPplus with 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 #6
Source File: StandardRemoteKernelClientPortal.java    From openAGV with 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 #7
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 #8
Source File: StandardRemoteSchedulerService.java    From openAGV with 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 #9
Source File: StandardRemoteDispatcherService.java    From openAGV with 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 #10
Source File: StandardRemoteSchedulerService.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.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 #11
Source File: StandardRemotePlantModelService.java    From openAGV with 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 #12
Source File: RapidExportUnexport.java    From TencentKona-8 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 #13
Source File: StandardRemoteRouterService.java    From openAGV with 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 #14
Source File: ShutdownImpl.java    From dragonwell8_jdk with 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 #15
Source File: ShutdownImpl.java    From TencentKona-8 with 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 #16
Source File: StandardRemoteTransportOrderService.java    From openAGV with 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_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 #17
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 #18
Source File: StandardRemoteNotificationService.java    From openAGV with 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 #19
Source File: PortableRemoteObject.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
/**
 * 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 #20
Source File: RMIJRMPServerImpl.java    From jdk1.8-source-analysis with 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 #21
Source File: JMXReporter.java    From flink with 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 #22
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 #23
Source File: ActivationGroupImpl.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
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 #24
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 #25
Source File: PortableRemoteObject.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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
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 #27
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 #28
Source File: ActivationGroupImpl.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
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 #29
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 #30
Source File: ActivationGroupImpl.java    From TencentKona-8 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);
        }
    }
}