Java Code Examples for java.rmi.server.UnicastRemoteObject

The following are top voted examples for showing how to use java.rmi.server.UnicastRemoteObject. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: lams   File: QuartzScheduler.java   View source code 7 votes vote down vote up
/**
 * <p>
 * Un-bind the scheduler from an RMI registry.
 * </p>
 */
private void unBind() throws RemoteException {
    String host = resources.getRMIRegistryHost();
    // don't un-export if we're not configured to do so...
    if (host == null || host.length() == 0) {
        return;
    }

    Registry registry = LocateRegistry.getRegistry(resources
            .getRMIRegistryHost(), resources.getRMIRegistryPort());

    String bindName = resources.getRMIBindName();
    
    try {
        registry.unbind(bindName);
        UnicastRemoteObject.unexportObject(this, true);
    } catch (java.rmi.NotBoundException nbe) {
    }

    getLog().info("Scheduler un-bound from name '" + bindName + "' in RMI registry");
}
 
Example 2
Project: OpenJSharp   File: RMIJRMPServerImpl.java   View source code 7 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 3
Project: JavaRushTasks   File: Solution.java   View source code 6 votes vote down vote up
@Override
public void run() {
    //напишите тут ваш код
    try {
        //создание объекта для удаленного доступа
        final Animal cat = new Cat("Barsik");
        final Animal dog = new Dog("Palkan");

        //создание реестра расшареных объетов
        registry = LocateRegistry.createRegistry(2099);

        //создание "заглушки" – приемника удаленных вызовов
        Remote stubCat = UnicastRemoteObject.exportObject(cat, 0);
        Remote stubDog = UnicastRemoteObject.exportObject(dog, 0);

        //регистрация "заглушки" в реесте
        registry.bind(BINDING_NAME1, stubCat);
        registry.bind(BINDING_NAME2, stubDog);

    } catch (RemoteException | AlreadyBoundException e) {
        e.printStackTrace();
    }
}
 
Example 4
Project: asura   File: QuartzScheduler.java   View source code 6 votes vote down vote up
/**
 * <p>
 * Un-bind the scheduler from an RMI registry.
 * </p>
 */
private void unBind() throws RemoteException {
    String host = resources.getRMIRegistryHost();
    // don't un-export if we're not configured to do so...
    if (host == null || host.length() == 0) {
        return;
    }

    Registry registry = LocateRegistry.getRegistry(resources
            .getRMIRegistryHost(), resources.getRMIRegistryPort());

    String bindName = resources.getRMIBindName();
    
    try {
        registry.unbind(bindName);
        UnicastRemoteObject.unexportObject(this, true);
    } catch (java.rmi.NotBoundException nbe) {
    }

    getLog().info("Scheduler un-bound from name '" + bindName + "' in RMI registry");
}
 
Example 5
Project: OpenJSharp   File: PortableRemoteObject.java   View source code 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 6
Project: OpenJSharp   File: ActivationGroupImpl.java   View source code 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 7
Project: OpenJSharp   File: ActivationGroupImpl.java   View source code 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 8
Project: monarch   File: ManagementAgent.java   View source code 6 votes vote down vote up
public synchronized void stopAgent() {
  stopHttpService();

  if (!this.running) {
    return;
  }

  if (logger.isDebugEnabled()) {
    logger.debug("Stopping jmx manager agent");
  }
  try {
    jmxConnectorServer.stop();
    UnicastRemoteObject.unexportObject(registry, true);
  } catch (Exception e) {
    throw new ManagementException(e);
  }

  this.running = false;
}
 
Example 9
Project: jdk8u-jdk   File: ActivationGroupImpl.java   View source code 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 10
Project: jdk8u-jdk   File: ActivationGroupImpl.java   View source code 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 11
Project: jdk8u-jdk   File: RMIJRMPServerImpl.java   View source code 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 12
Project: jdk8u-jdk   File: ExportObjs.java   View source code 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 13
Project: jdk8u-jdk   File: RapidExportUnexport.java   View source code 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 14
Project: jdk8u-jdk   File: ShutdownImpl.java   View source code 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
Project: jdk8u-jdk   File: ShutdownImpl.java   View source code 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 16
Project: openjdk-jdk10   File: PortableRemoteObject.java   View source code 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 17
Project: openjdk-jdk10   File: ActivationGroupImpl.java   View source code 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 18
Project: openjdk-jdk10   File: ActivationGroupImpl.java   View source code 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 19
Project: openjdk-jdk10   File: RMIJRMPServerImpl.java   View source code 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 20
Project: openjdk-jdk10   File: ExportObjs.java   View source code 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 21
Project: openjdk-jdk10   File: DummyApp.java   View source code 6 votes vote down vote up
public static void main(String args[]) {
    try {
        Hello obj = new Server();
        Hello stub = (Hello) UnicastRemoteObject.exportObject(obj, 0);

        Client client = new Client(stub);
        String testStubReturn = client.testStub();
        System.out.println("Stub is: " + testStubReturn);
        if (!testStubReturn.equals(obj.sayHello())) {
            throw new RuntimeException("Unexpected string from stub call, expected \""
                    + testStubReturn + "\", actual \"" + obj.sayHello() + "\"");
        } else {
            System.out.println("Test passed");
        }

        System.exit(0);
    } catch (Throwable e) {
        e.printStackTrace();
        System.exit(-1);
    }
}
 
Example 22
Project: openjdk-jdk10   File: RapidExportUnexport.java   View source code 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, 0);
        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 23
Project: openjdk-jdk10   File: ShutdownImpl.java   View source code 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 24
Project: openjdk-jdk10   File: ShutdownImpl.java   View source code 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 25
Project: openjdk9   File: PortableRemoteObject.java   View source code 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
Project: openjdk9   File: ActivationGroupImpl.java   View source code 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 27
Project: openjdk9   File: ActivationGroupImpl.java   View source code 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 28
Project: openjdk9   File: RMIJRMPServerImpl.java   View source code 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 29
Project: intellij-ce-playground   File: MavenServerManager.java   View source code 6 votes vote down vote up
@SuppressWarnings("ConstantConditions")
@Override
@NotNull
protected synchronized MavenServer create() throws RemoteException {
  MavenServer result;
  try {
    result = mySupport.acquire(this, "");
  }
  catch (Exception e) {
    throw new RemoteException("Cannot start maven service", e);
  }

  myLoggerExported = UnicastRemoteObject.exportObject(myLogger, 0) != null;
  if (!myLoggerExported) throw new RemoteException("Cannot export logger object");

  myDownloadListenerExported = UnicastRemoteObject.exportObject(myDownloadListener, 0) != null;
  if (!myDownloadListenerExported) throw new RemoteException("Cannot export download listener object");

  result.set(myLogger, myDownloadListener);

  return result;
}
 
Example 30
Project: openjdk9   File: DummyApp.java   View source code 6 votes vote down vote up
public static void main(String args[]) {
    try {
        Hello obj = new Server();
        Hello stub = (Hello) UnicastRemoteObject.exportObject(obj, 0);

        Client client = new Client(stub);
        String testStubReturn = client.testStub();
        System.out.println("Stub is: " + testStubReturn);
        if (!testStubReturn.equals(obj.sayHello())) {
            throw new RuntimeException("Unexpected string from stub call, expected \""
                    + testStubReturn + "\", actual \"" + obj.sayHello() + "\"");
        } else {
            System.out.println("Test passed");
        }

        System.exit(0);
    } catch (Throwable e) {
        e.printStackTrace();
        System.exit(-1);
    }
}
 
Example 31
Project: openjdk9   File: ShutdownImpl.java   View source code 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 32
Project: openjdk9   File: ShutdownImpl.java   View source code 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 33
Project: jdk8u_jdk   File: ShutdownImpl.java   View source code 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 34
Project: lookaside_java-1.8.0-openjdk   File: PortableRemoteObject.java   View source code 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 35
Project: HDFS-Implementation   File: Namenode.java   View source code 6 votes vote down vote up
public static void main(String[] args) {
    map_filename_blocks = new HashMap<>();
    block_number = 0;
    map_block_datanode = new HashMap<>();
    /* Write the existing data */
    restoreFilelist();
    setDatanodeIps();
    String myip = getMyIp();
    if (myip.equals("")) {
        System.err.println("Error in Getting My ip");
        System.exit(-1);
    }
    System.setProperty("java.rmi.server.hostname", myip);
    try {
        Namenode obj = new Namenode();
        Namenodedef stub = (Namenodedef) UnicastRemoteObject.exportObject(obj, 0);
        Registry reg = LocateRegistry.getRegistry("0.0.0.0", 1099);
        reg.rebind("NameNode", stub);
    } catch (RemoteException e) {
        e.printStackTrace();
    }
}
 
Example 36
Project: lookaside_java-1.8.0-openjdk   File: RMIJRMPServerImpl.java   View source code 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 37
Project: flink   File: JMXReporter.java   View source code 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 38
Project: TinSpin   File: TestRunnerLocal.java   View source code 6 votes vote down vote up
public static void main(String[] args) {
	System.out.println("TestRunnerLocal: started: " + args[0] + " " + args[1] + " " + args[2]);
	//System.out.println("TestRunnerLocal time: " + new Date());
	
	System.setSecurityManager (new NoSecurityManager());
       try {
           TestRunnerLocal engine = new TestRunnerLocal();
           TestRunnerAPI stub =
               (TestRunnerAPI) UnicastRemoteObject.exportObject(engine, 0);
           Registry registry = LocateRegistry.getRegistry();
           registry.rebind(TestManagerRMI.RMI_NAME, stub);
           //System.out.println("TestRunnerLocal bound");
       } catch (Exception e) {
           System.err.println("TestRunnerLocal exception:");
           e.printStackTrace();
       }
	
	//System.out.println("TestRunnerLocal finished: " + args[0]);
}
 
Example 39
Project: lookaside_java-1.8.0-openjdk   File: ActivationGroupImpl.java   View source code 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 40
Project: jdk8u_corba   File: PortableRemoteObject.java   View source code 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.");
        }
    }
}