Search in sources :

Example 6 with ExportException

use of java.rmi.server.ExportException in project jdk8u_jdk by JetBrains.

the class ObjectTable method putTarget.

/**
     * Add target to object table.  If it is not a permanent entry, then
     * make sure that reaper thread is running to remove collected entries
     * and keep VM alive.
     */
static void putTarget(Target target) throws ExportException {
    ObjectEndpoint oe = target.getObjectEndpoint();
    WeakRef weakImpl = target.getWeakImpl();
    if (DGCImpl.dgcLog.isLoggable(Log.VERBOSE)) {
        DGCImpl.dgcLog.log(Log.VERBOSE, "add object " + oe);
    }
    synchronized (tableLock) {
        /**
             * Do nothing if impl has already been collected (see 6597112). Check while
             * holding tableLock to ensure that Reaper cannot process weakImpl in between
             * null check and put/increment effects.
             */
        if (target.getImpl() != null) {
            if (objTable.containsKey(oe)) {
                throw new ExportException("internal error: ObjID already in use");
            } else if (implTable.containsKey(weakImpl)) {
                throw new ExportException("object already exported");
            }
            objTable.put(oe, target);
            implTable.put(weakImpl, target);
            if (!target.isPermanent()) {
                incrementKeepAliveCount();
            }
        }
    }
}
Also used : ExportException(java.rmi.server.ExportException)

Example 7 with ExportException

use of java.rmi.server.ExportException in project jdk8u_jdk by JetBrains.

the class UnicastServerRef method exportObject.

/**
     * Export this object, create the skeleton and stubs for this
     * dispatcher.  Create a stub based on the type of the impl,
     * initialize it with the appropriate remote reference. Create the
     * target defined by the impl, dispatcher (this) and stub.
     * Export that target via the Ref.
     */
public Remote exportObject(Remote impl, Object data, boolean permanent) throws RemoteException {
    Class<?> implClass = impl.getClass();
    Remote stub;
    try {
        stub = Util.createProxy(implClass, getClientRef(), forceStubUse);
    } catch (IllegalArgumentException e) {
        throw new ExportException("remote object implements illegal remote interface", e);
    }
    if (stub instanceof RemoteStub) {
        setSkeleton(impl);
    }
    Target target = new Target(impl, this, stub, ref.getObjID(), permanent);
    ref.exportObject(target);
    hashToMethod_Map = hashToMethod_Maps.get(implClass);
    return stub;
}
Also used : Target(sun.rmi.transport.Target) RemoteStub(java.rmi.server.RemoteStub) Remote(java.rmi.Remote) ExportException(java.rmi.server.ExportException)

Example 8 with ExportException

use of java.rmi.server.ExportException in project jdk8u_jdk by JetBrains.

the class Server method start.

public static String start() throws Exception {
    int serverPort = 12345;
    ObjectName name = new ObjectName("test", "foo", "bar");
    MBeanServer jmxServer = ManagementFactory.getPlatformMBeanServer();
    SteMBean bean = new Ste();
    jmxServer.registerMBean(bean, name);
    boolean exported = false;
    Random rnd = new Random(System.currentTimeMillis());
    do {
        try {
            LocateRegistry.createRegistry(serverPort);
            exported = true;
        } catch (ExportException ee) {
            if (ee.getCause() instanceof BindException) {
                serverPort = rnd.nextInt(10000) + 4096;
            } else {
                throw ee;
            }
        }
    } while (!exported);
    JMXServiceURL serverUrl = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:" + serverPort + "/test");
    JMXConnectorServer jmxConnector = JMXConnectorServerFactory.newJMXConnectorServer(serverUrl, null, jmxServer);
    jmxConnector.start();
    return serverUrl.toString();
}
Also used : JMXServiceURL(javax.management.remote.JMXServiceURL) Random(java.util.Random) BindException(java.net.BindException) ObjectName(javax.management.ObjectName) MBeanServer(javax.management.MBeanServer) ExportException(java.rmi.server.ExportException) JMXConnectorServer(javax.management.remote.JMXConnectorServer)

Aggregations

ExportException (java.rmi.server.ExportException)8 Remote (java.rmi.Remote)3 Random (java.util.Random)3 LocateRegistry (java.rmi.registry.LocateRegistry)2 Registry (java.rmi.registry.Registry)2 UnicastRemoteObject (java.rmi.server.UnicastRemoteObject)2 JMXServiceURL (javax.management.remote.JMXServiceURL)2 IOException (java.io.IOException)1 BindException (java.net.BindException)1 MalformedURLException (java.net.MalformedURLException)1 ServerSocket (java.net.ServerSocket)1 AlreadyBoundException (java.rmi.AlreadyBoundException)1 RemoteException (java.rmi.RemoteException)1 RemoteStub (java.rmi.server.RemoteStub)1 HashMap (java.util.HashMap)1 JMException (javax.management.JMException)1 MBeanServer (javax.management.MBeanServer)1 ObjectName (javax.management.ObjectName)1 JMXConnectorServer (javax.management.remote.JMXConnectorServer)1 NewThreadAction (sun.rmi.runtime.NewThreadAction)1