?? activationgroup.java
字號:
{ SecurityManager security = System.getSecurityManager(); if (security != null) security.checkSetFactory(); if (currGroup != null) throw new ActivationException("group already exists"); if (canCreate == false) throw new ActivationException("group deactivated and " + "cannot be recreated"); try { // load group's class String groupClassName = desc.getClassName(); /* * Fix for 4252236: resolution of the default * activation group implementation name should be * delayed until now. */ if (groupClassName == null) { groupClassName = sun.rmi.server.ActivationGroupImpl.class.getName(); } final String className = groupClassName; /* * Fix for 4170955: Because the default group * implementation is a sun.* class, the group class * needs to be loaded in a privileged block of code. */ Class cl; try { cl = (Class) java.security.AccessController. doPrivileged(new PrivilegedExceptionAction() { public Object run() throws ClassNotFoundException, MalformedURLException { return RMIClassLoader. loadClass(desc.getLocation(), className); } }); } catch (PrivilegedActionException pae) { throw new ActivationException("Could not load default group " + "implementation class", pae.getException()); } // create group Constructor constructor = cl.getConstructor(groupConstrParams); Object[] params = new Object[] { id, desc.getData() }; Object obj = constructor.newInstance(params); if (obj instanceof ActivationGroup) { ActivationGroup newGroup = (ActivationGroup) obj; currSystem = id.getSystem(); newGroup.incarnation = incarnation; newGroup.monitor = currSystem.activeGroup(id, newGroup, incarnation); currGroup = newGroup; currGroupID = id; canCreate = false; } else { throw new ActivationException("group not correct class: " + obj.getClass().getName()); } } catch (java.lang.reflect.InvocationTargetException e) { e.getTargetException().printStackTrace(); throw new ActivationException("exception in group constructor", e.getTargetException()); } catch (ActivationException e) { throw e; } catch (Exception e) { throw new ActivationException("exception creating group", e); } return currGroup; } /** * Returns the current activation group's identifier. Returns null * if no group is currently active for this VM. * @return the activation group's identifier * @since 1.2 */ public static synchronized ActivationGroupID currentGroupID() { return currGroupID; } /** * Returns the activation group identifier for the VM. If an * activation group does not exist for this VM, a default * activation group is created. A group can be created only once, * so if a group has already become active and deactivated. * * @return the activation group identifier * @exception ActivationException if error occurs during group * creation, if security manager is not set, or if the group * has already been created and deactivated. */ static synchronized ActivationGroupID internalCurrentGroupID() throws ActivationException { if (currGroupID == null) throw new ActivationException("nonexistent group"); return currGroupID; } /** * Set the activation system for the VM. The activation system can * only be set it if no group is currently active. If the activation * system is not set via this call, then the <code>getSystem</code> * method attempts to obtain a reference to the * <code>ActivationSystem</code> by looking up the name * "java.rmi.activation.ActivationSystem" in the Activator's * registry. By default, the port number used to look up the * activation system is defined by * <code>ActivationSystem.SYSTEM_PORT</code>. This port can be overridden * by setting the property <code>java.rmi.activation.port</code>. * * <p>If there is a security manager, this method first * calls the security manager's <code>checkSetFactory</code> method. * This could result in a SecurityException. * * @param system remote reference to the <code>ActivationSystem</code> * @exception ActivationException if activation system is already set * @exception SecurityException if permission to set the activation system is denied. * (Note: The default implementation of the security manager * <code>checkSetFactory</code> * method requires the RuntimePermission "setFactory") * @see #getSystem * @see SecurityManager#checkSetFactory * @since 1.2 */ public static synchronized void setSystem(ActivationSystem system) throws ActivationException { SecurityManager security = System.getSecurityManager(); if (security != null) security.checkSetFactory(); if (currSystem != null) throw new ActivationException("activation system already set"); currSystem = system; } /** * Returns the activation system for the VM. The activation system * may be set by the <code>setSystem</code> method. If the * activation system is not set via the <code>setSystem</code> * method, then the <code>getSystem</code> method attempts to * obtain a reference to the <code>ActivationSystem</code> by * looking up the name "java.rmi.activation.ActivationSystem" in * the Activator's registry. By default, the port number used to * look up the activation system is defined by * <code>ActivationSystem.SYSTEM_PORT</code>. This port can be * overridden by setting the property * <code>java.rmi.activation.port</code>. * * @return the activation system for the VM/group * @exception ActivationException if activation system cannot be * obtained or is not bound * (means that it is not running) * @see #setSystem * @since 1.2 */ public static synchronized ActivationSystem getSystem() throws ActivationException { if (currSystem == null) { try { int port; port = ((Integer)java.security.AccessController.doPrivileged( new GetIntegerAction("java.rmi.activation.port", ActivationSystem.SYSTEM_PORT))).intValue(); currSystem = (ActivationSystem) Naming.lookup("//:" + port + "/java.rmi.activation.ActivationSystem"); } catch (Exception e) { throw new ActivationException( "unable to obtain ActivationSystem", e); } } return currSystem; } /** * This protected method is necessary for subclasses to * make the <code>activeObject</code> callback to the group's * monitor. The call is simply forwarded to the group's * <code>ActivationMonitor</code>. * * @param id the object's identifier * @param mobj a marshalled object containing the remote object's stub * @exception UnknownObjectException if object is not registered * @exception RemoteException if call informing monitor fails * @exception ActivationException if an activation error occurs * @since 1.2 */ protected void activeObject(ActivationID id, MarshalledObject mobj) throws ActivationException, UnknownObjectException, RemoteException { getMonitor().activeObject(id, mobj); } /** * This protected method is necessary for subclasses to * make the <code>inactiveGroup</code> callback to the group's * monitor. The call is simply forwarded to the group's * <code>ActivationMonitor</code>. Also, the current group * for the VM is set to null. * * @exception UnknownGroupException if group is not registered * @exception RemoteException if call informing monitor fails * @since 1.2 */ protected void inactiveGroup() throws UnknownGroupException, RemoteException { try { getMonitor().inactiveGroup(groupID, incarnation); } finally { destroyGroup(); } } /** * Returns the monitor for the activation group. */ private ActivationMonitor getMonitor() throws RemoteException { synchronized (ActivationGroup.class) { if (monitor != null) { return monitor; } } throw new RemoteException("monitor not received"); } /** * Destroys the current group. */ private static synchronized void destroyGroup() { currGroup = null; currGroupID = null; // NOTE: don't set currSystem to null since it may be needed } /** * Returns the current group for the VM. * @exception ActivationException if current group is null (not active) */ static synchronized ActivationGroup currentGroup() throws ActivationException { if (currGroup == null) { throw new ActivationException("group is not active"); } return currGroup; } }
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -