Search in sources :

Example 1 with ActivationException

use of java.rmi.activation.ActivationException in project jdk8u_jdk by JetBrains.

the class ActivationGroupImpl method activeObject.

/**
     * The group's <code>activeObject</code> method is called when an
     * object is exported (either by <code>Activatable</code> object
     * construction or an explicit call to
     * <code>Activatable.exportObject</code>. The group must inform its
     * <code>ActivationMonitor</code> that the object is active (via
     * the monitor's <code>activeObject</code> method) if the group
     * hasn't already done so.
     *
     * @param id the object's identifier
     * @param obj the remote object implementation
     * @exception UnknownObjectException if object is not registered
     * @exception RemoteException if call informing monitor fails
     */
public void activeObject(ActivationID id, Remote impl) throws ActivationException, UnknownObjectException, RemoteException {
    try {
        acquireLock(id);
        synchronized (this) {
            if (groupInactive == true)
                throw new ActivationException("group is inactive");
        }
        if (!active.contains(id)) {
            ActiveEntry entry = new ActiveEntry(impl);
            active.put(id, entry);
            // created new entry, so inform monitor of active object
            try {
                super.activeObject(id, entry.mobj);
            } catch (RemoteException e) {
            // daemon can still find it by calling newInstance
            }
        }
    } finally {
        releaseLock(id);
        checkInactiveGroup();
    }
}
Also used : ActivationException(java.rmi.activation.ActivationException) RemoteException(java.rmi.RemoteException)

Example 2 with ActivationException

use of java.rmi.activation.ActivationException in project jdk8u_jdk by JetBrains.

the class ActivationGroupImpl method inactiveObject.

/**
    * The group's <code>inactiveObject</code> method is called
    * indirectly via a call to the <code>Activatable.inactive</code>
    * method. A remote object implementation must call
    * <code>Activatable</code>'s <code>inactive</code> method when
    * that object deactivates (the object deems that it is no longer
    * active). If the object does not call
    * <code>Activatable.inactive</code> when it deactivates, the
    * object will never be garbage collected since the group keeps
    * strong references to the objects it creates. <p>
    *
    * The group's <code>inactiveObject</code> method
    * unexports the remote object from the RMI runtime so that the
    * object can no longer receive incoming RMI calls. This call will
    * only succeed if the object has no pending/executing calls. If
    * the object does have pending/executing RMI calls, then false
    * will be returned.
    *
    * If the object has no pending/executing calls, the object is
    * removed from the RMI runtime and the group informs its
    * <code>ActivationMonitor</code> (via the monitor's
    * <code>inactiveObject</code> method) that the remote object is
    * not currently active so that the remote object will be
    * re-activated by the activator upon a subsequent activation
    * request.
    *
    * @param id the object's activation identifier
    * @returns true if the operation succeeds (the operation will
    * succeed if the object in currently known to be active and is
    * either already unexported or is currently exported and has no
    * pending/executing calls); false is returned if the object has
    * pending/executing calls in which case it cannot be deactivated
    * @exception UnknownObjectException if object is unknown (may already
    * be inactive)
    * @exception RemoteException if call informing monitor fails
    */
public boolean inactiveObject(ActivationID id) throws ActivationException, UnknownObjectException, RemoteException {
    try {
        acquireLock(id);
        synchronized (this) {
            if (groupInactive == true)
                throw new ActivationException("group is inactive");
        }
        ActiveEntry entry = active.get(id);
        if (entry == null) {
            // REMIND: should this be silent?
            throw new UnknownObjectException("object not active");
        }
        try {
            if (Activatable.unexportObject(entry.impl, false) == false)
                return false;
        } catch (NoSuchObjectException allowUnexportedObjects) {
        }
        try {
            super.inactiveObject(id);
        } catch (UnknownObjectException allowUnregisteredObjects) {
        }
        active.remove(id);
    } finally {
        releaseLock(id);
        checkInactiveGroup();
    }
    return true;
}
Also used : ActivationException(java.rmi.activation.ActivationException) NoSuchObjectException(java.rmi.NoSuchObjectException) UnknownObjectException(java.rmi.activation.UnknownObjectException)

Example 3 with ActivationException

use of java.rmi.activation.ActivationException in project jdk8u_jdk by JetBrains.

the class ActivationGroupImpl method newInstance.

/**
     * Creates a new instance of an activatable remote object. The
     * <code>Activator</code> calls this method to create an activatable
     * object in this group. This method should be idempotent; a call to
     * activate an already active object should return the previously
     * activated object.
     *
     * Note: this method assumes that the Activator will only invoke
     * newInstance for the same object in a serial fashion (i.e.,
     * the activator will not allow the group to see concurrent requests
     * to activate the same object.
     *
     * @param id the object's activation identifier
     * @param desc the object's activation descriptor
     * @return a marshalled object containing the activated object's stub
     */
public MarshalledObject<? extends Remote> newInstance(final ActivationID id, final ActivationDesc desc) throws ActivationException, RemoteException {
    RegistryImpl.checkAccess("ActivationInstantiator.newInstance");
    if (!groupID.equals(desc.getGroupID()))
        throw new ActivationException("newInstance in wrong group");
    try {
        acquireLock(id);
        synchronized (this) {
            if (groupInactive == true)
                throw new InactiveGroupException("group is inactive");
        }
        ActiveEntry entry = active.get(id);
        if (entry != null)
            return entry.mobj;
        String className = desc.getClassName();
        final Class<? extends Remote> cl = RMIClassLoader.loadClass(desc.getLocation(), className).asSubclass(Remote.class);
        Remote impl = null;
        final Thread t = Thread.currentThread();
        final ClassLoader savedCcl = t.getContextClassLoader();
        ClassLoader objcl = cl.getClassLoader();
        final ClassLoader ccl = covers(objcl, savedCcl) ? objcl : savedCcl;
        /*
             * Fix for 4164971: allow non-public activatable class
             * and/or constructor, create the activatable object in a
             * privileged block
             */
        try {
            /*
                 * The code below is in a doPrivileged block to
                 * protect against user code which code might have set
                 * a global socket factory (in which case application
                 * code would be on the stack).
                 */
            impl = AccessController.doPrivileged(new PrivilegedExceptionAction<Remote>() {

                public Remote run() throws InstantiationException, NoSuchMethodException, IllegalAccessException, InvocationTargetException {
                    Constructor<? extends Remote> constructor = cl.getDeclaredConstructor(ActivationID.class, MarshalledObject.class);
                    constructor.setAccessible(true);
                    try {
                        /*
                               * Fix for 4289544: make sure to set the
                               * context class loader to be the class
                               * loader of the impl class before
                               * constructing that class.
                               */
                        t.setContextClassLoader(ccl);
                        return constructor.newInstance(id, desc.getData());
                    } finally {
                        t.setContextClassLoader(savedCcl);
                    }
                }
            });
        } catch (PrivilegedActionException pae) {
            Throwable e = pae.getException();
            // narrow the exception's type and rethrow it
            if (e instanceof InstantiationException) {
                throw (InstantiationException) e;
            } else if (e instanceof NoSuchMethodException) {
                throw (NoSuchMethodException) e;
            } else if (e instanceof IllegalAccessException) {
                throw (IllegalAccessException) e;
            } else if (e instanceof InvocationTargetException) {
                throw (InvocationTargetException) e;
            } else if (e instanceof RuntimeException) {
                throw (RuntimeException) e;
            } else if (e instanceof Error) {
                throw (Error) e;
            }
        }
        entry = new ActiveEntry(impl);
        active.put(id, entry);
        return entry.mobj;
    } catch (NoSuchMethodException | NoSuchMethodError e) {
        /* user forgot to provide activatable constructor?
             * or code recompiled and user forgot to provide
             *  activatable constructor?
             */
        throw new ActivationException("Activatable object must provide an activation" + " constructor", e);
    } catch (InvocationTargetException e) {
        throw new ActivationException("exception in object constructor", e.getTargetException());
    } catch (Exception e) {
        throw new ActivationException("unable to activate object", e);
    } finally {
        releaseLock(id);
        checkInactiveGroup();
    }
}
Also used : ActivationException(java.rmi.activation.ActivationException) PrivilegedActionException(java.security.PrivilegedActionException) Remote(java.rmi.Remote) PrivilegedExceptionAction(java.security.PrivilegedExceptionAction) InvocationTargetException(java.lang.reflect.InvocationTargetException) NoSuchObjectException(java.rmi.NoSuchObjectException) ActivationException(java.rmi.activation.ActivationException) PrivilegedActionException(java.security.PrivilegedActionException) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) RemoteException(java.rmi.RemoteException) UnknownObjectException(java.rmi.activation.UnknownObjectException) RMIClassLoader(java.rmi.server.RMIClassLoader)

Example 4 with ActivationException

use of java.rmi.activation.ActivationException in project jdk8u_jdk by JetBrains.

the class PipeWriter method addLogRecord.

/**
     * Add a record to the activation log. If the number of updates
     * passes a predetermined threshold, record a snapshot.
     */
private void addLogRecord(LogRecord rec) throws ActivationException {
    synchronized (log) {
        checkShutdown();
        try {
            log.update(rec, true);
        } catch (Exception e) {
            numUpdates = snapshotInterval;
            System.err.println(getTextResource("rmid.log.update.warning"));
            e.printStackTrace();
        }
        if (++numUpdates < snapshotInterval) {
            return;
        }
        try {
            log.snapshot(this);
            numUpdates = 0;
        } catch (Exception e) {
            System.err.println(getTextResource("rmid.log.snapshot.warning"));
            e.printStackTrace();
            try {
                // shutdown activation system because snapshot failed
                system.shutdown();
            } catch (RemoteException ignore) {
            // can't happen
            }
            // warn the client of the original update problem
            throw new ActivationException("log snapshot failed", e);
        }
    }
}
Also used : ActivationException(java.rmi.activation.ActivationException) RemoteException(java.rmi.RemoteException) ActivationException(java.rmi.activation.ActivationException) UnknownGroupException(java.rmi.activation.UnknownGroupException) ConnectIOException(java.rmi.ConnectIOException) NotBoundException(java.rmi.NotBoundException) MissingResourceException(java.util.MissingResourceException) InvocationTargetException(java.lang.reflect.InvocationTargetException) RemoteException(java.rmi.RemoteException) AccessControlException(java.security.AccessControlException) UnknownObjectException(java.rmi.activation.UnknownObjectException) NoSuchObjectException(java.rmi.NoSuchObjectException) AccessException(java.rmi.AccessException) SocketException(java.net.SocketException) ConnectException(java.rmi.ConnectException) IOException(java.io.IOException) AlreadyBoundException(java.rmi.AlreadyBoundException)

Example 5 with ActivationException

use of java.rmi.activation.ActivationException in project jdk8u_jdk by JetBrains.

the class IdempotentActiveGroup method main.

public static void main(String[] args) {
    System.err.println("\nRegression test for bug 4720528\n");
    TestLibrary.suggestSecurityManager("java.lang.SecurityManager");
    RMID rmid = null;
    ActivationInstantiator inst1 = null;
    ActivationInstantiator inst2 = null;
    try {
        RMID.removeLog();
        rmid = RMID.createRMID();
        rmid.start();
        System.err.println("Create group descriptor");
        ActivationGroupDesc groupDesc = new ActivationGroupDesc(null, null);
        ActivationSystem system = ActivationGroup.getSystem();
        System.err.println("Register group descriptor");
        ActivationGroupID groupID = system.registerGroup(groupDesc);
        inst1 = new FakeInstantiator();
        inst2 = new FakeInstantiator();
        System.err.println("Invoke activeGroup with inst1");
        system.activeGroup(groupID, inst1, 0);
        try {
            System.err.println("Invoke activeGroup with inst2");
            system.activeGroup(groupID, inst2, 0);
            throw new RuntimeException("TEST FAILED: activeGroup with unequal groups succeeded!");
        } catch (ActivationException expected) {
            System.err.println("Caught expected ActivationException");
            System.err.println("Test 1 (of 2) passed");
        }
        try {
            System.err.println("Invoke activeGroup with inst1");
            system.activeGroup(groupID, inst1, 0);
            System.err.println("activeGroup call succeeded");
            System.err.println("Test 2 (of 2) passed");
        } catch (ActivationException unexpected) {
            throw new RuntimeException("TEST FAILED: activeGroup with equal groups failed!", unexpected);
        }
    } catch (Exception e) {
        TestLibrary.bomb("test failed", e);
    } finally {
        try {
            if (inst1 != null) {
                UnicastRemoteObject.unexportObject(inst1, true);
            }
            if (inst2 != null) {
                UnicastRemoteObject.unexportObject(inst2, true);
            }
        } catch (NoSuchObjectException unexpected) {
            throw new AssertionError(unexpected);
        }
        ActivationLibrary.rmidCleanup(rmid);
    }
}
Also used : ActivationSystem(java.rmi.activation.ActivationSystem) ActivationGroupID(java.rmi.activation.ActivationGroupID) ActivationInstantiator(java.rmi.activation.ActivationInstantiator) ActivationException(java.rmi.activation.ActivationException) ActivationGroupDesc(java.rmi.activation.ActivationGroupDesc) NoSuchObjectException(java.rmi.NoSuchObjectException) NoSuchObjectException(java.rmi.NoSuchObjectException) ActivationException(java.rmi.activation.ActivationException) RemoteException(java.rmi.RemoteException)

Aggregations

ActivationException (java.rmi.activation.ActivationException)6 RemoteException (java.rmi.RemoteException)5 NoSuchObjectException (java.rmi.NoSuchObjectException)4 UnknownObjectException (java.rmi.activation.UnknownObjectException)3 IOException (java.io.IOException)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 SocketException (java.net.SocketException)1 AccessException (java.rmi.AccessException)1 AlreadyBoundException (java.rmi.AlreadyBoundException)1 ConnectException (java.rmi.ConnectException)1 ConnectIOException (java.rmi.ConnectIOException)1 NotBoundException (java.rmi.NotBoundException)1 Remote (java.rmi.Remote)1 ActivationGroupDesc (java.rmi.activation.ActivationGroupDesc)1 ActivationGroupID (java.rmi.activation.ActivationGroupID)1 ActivationInstantiator (java.rmi.activation.ActivationInstantiator)1 ActivationSystem (java.rmi.activation.ActivationSystem)1 UnknownGroupException (java.rmi.activation.UnknownGroupException)1 RMIClassLoader (java.rmi.server.RMIClassLoader)1 ServerCloneException (java.rmi.server.ServerCloneException)1