activatable.java
来自「linux下建立JAVA虚拟机的源码KAFFE」· Java 代码 · 共 501 行 · 第 1/2 页
JAVA
501 行
* inactivated because of the running or pending calls. * @throws UnknownObjectException if the object is unknown. * @throws ActivationException if the object group is not active * @throws RemoteException if the remote call fails */ public static boolean inactive(ActivationID id) throws UnknownObjectException, ActivationException, RemoteException { if (id.group!=null) id.group.inactiveObject(id); return UnicastRemoteObject.unexportObject(id.activate(false), false); } /** * Unregister the object (the object will no longer be activable with that id) * * @param id the object id * @throws UnknownObjectException if the id is unknown * @throws ActivationException if the activation system is not running * @throws RemoteException if the remote call fails. */ public static void unregister(ActivationID id) throws UnknownObjectException, ActivationException, RemoteException { ActivationGroup.currentGroupId.getSystem().unregisterObject(id); UnicastServer.unregisterActivatable(id); } /** * Register and export the object that activatable object that is not derived * from the Activatable super class. It creates and registers the object * activation descriptor. There is no need to call this method if the object * extends Activable, as its work is done in the constructor * {@link #Activatable(String, MarshalledObject, boolean, int)}. * * @param obj the object, that is exported, becoming available at the given * port. * @param location the object code location (codebase). * @param data the data, needed to activate the object * @param restart the restart mode * @param port the port, where the object will be available * * @return the created object activation ID. * * @throws ActivationException if the activation group is not active * @throws RemoteException if the registration or export fails */ public static ActivationID exportObject(Remote obj, String location, MarshalledObject data, boolean restart, int port) throws ActivationException, RemoteException { ActivationDesc descriptor = new ActivationDesc(obj.getClass().getName(), location, data, restart); ActivationID id = obtainId(descriptor); Remote stub = exportObject(obj, id, port); return id; } /** * Register and export the object that activatable object that is not derived * from the Activatable super class. It creates and registers the object * activation descriptor. There is no need to call this method if the object * extends Activable, as its work is done in the constructor * {@link #Activatable(String, MarshalledObject, boolean, int, RMIClientSocketFactory, RMIServerSocketFactory)} * * @param obj the object, that is exported, becoming available at the given * port. * @param location the object code location (codebase). * @param data the data, needed to activate the object * @param restart the restart mode * @param port the port, where the object will be available * @param csf the client socket factory * @param ssf the server socket factory * * @return the created object activation ID. * * @throws ActivationException if the activation group is not active * @throws RemoteException if the registration or export fails */ public static ActivationID exportObject(Remote obj, String location, MarshalledObject data, boolean restart, int port, RMIClientSocketFactory csf, RMIServerSocketFactory ssf) throws ActivationException, RemoteException { ActivationDesc descriptor = new ActivationDesc(obj.getClass().getName(), location, data, restart); ActivationID id = obtainId(descriptor); Remote stub = exportObject(obj, id, port, csf, ssf); return id; } /** * During activation, this exportObject method should be invoked explicitly by * the activatable object, that does is not derived from the Activatable * class. There is no need to call this method if the object extends * Activable, as its work is done in the constructor * {@link #Activatable(ActivationID, int)} * * @param obj the object * @param id the known activation id * @param port the object port * * @return the remote stub of the activatable object * * @throws RemoteException if the object export fails */ public static Remote exportObject(Remote obj, ActivationID id, int port) throws RemoteException { Remote stub = export(id, obj, port, null); return stub; } /** * During activation, this exportObject method should be invoked explicitly by * the activatable object, that does is not derived from the Activatable * class. There is no need to call this method if the object extends * Activable, as its work is done in the constructor * {@link #Activatable(ActivationID, int)} * * @param obj the object * @param id the known activation id * @param port the object port * @param csf the client socket factory * @param ssf the server socket factory * * @return the remote stub of the activatable object * * @throws RemoteException if the object export fails */ public static Remote exportObject(Remote obj, ActivationID id, int port, RMIClientSocketFactory csf, RMIServerSocketFactory ssf) throws RemoteException { Remote stub = export(id, obj, port, ssf); return stub; } /** * Make the remote object unavailable for incoming calls. This method also * unregisters the object, so it cannot be activated again by incomming call * (unless registered). * * @param obj the object to unexport * @param force if true, cancel all pending or running calls to that object * (if false, the object with such calls is not unexported and false * is returned by this method). * @return if the object was successfully unexported, false otherwise * @throws NoSuchObjectException if such object is not known */ public static boolean unexportObject(Remote obj, boolean force) throws NoSuchObjectException { Object aref = UnicastServer.getExportedRef(obj); // Unregister it also (otherwise will be activated during the subsequent // call. if (aref instanceof ActivatableServerRef) { ActivatableServerRef aar = (ActivatableServerRef) aref; UnicastServer.unregisterActivatable(aar.actId); } return UnicastRemoteObject.unexportObject(obj, force); } static Remote exportObject(Remote obj, int port, RMIServerSocketFactory serverSocketFactory) throws RemoteException { UnicastServerRef sref = null; if (obj instanceof RemoteObject) sref = (UnicastServerRef) ((RemoteObject) obj).getRef(); if (sref == null) sref = new UnicastServerRef(new ObjID(), port, serverSocketFactory); Remote stub = sref.exportObject(obj); // addStub(obj, stub); // TODO Need to change the place of the stub repository return stub; } /** * Create and export the new remote object, making it available at the given * port, using sockets, produced by the specified factories. * * @param port the port, on that the object should become available. Zero * means anonymous port. * @param serverSocketFactory the server socket factory */ public static Remote export(ActivationID id, Remote obj, int port, RMIServerSocketFactory serverSocketFactory) throws RemoteException { UnicastServerRef sref = null; if (obj instanceof RemoteObject) sref = (UnicastServerRef) ((RemoteObject) obj).getRef(); if (sref == null) sref = new ActivatableServerRef(makeId(id), id, port, serverSocketFactory); Remote stub = sref.exportObject(obj); // addStub(obj, stub); // need probably the stub repository elsewhere return stub; } /** * Make the object ID from the activation ID. The same activation ID always * produces the identical object id. * * @param aid the activation id * * @return the object id */ public static ObjID makeId(ActivationID aid) { ObjID id = new ObjID(0); // The fields of both ObjID and ActivationID must be package private, // so we need to use the reflection to access them anyway. // Probably other implementations use some very different approach. try { Field idUid = ObjID.class.getDeclaredField("space"); Field aidUid = ActivationID.class.getDeclaredField("uid"); aidUid.setAccessible(true); idUid.setAccessible(true); idUid.set(id, aidUid.get(aid)); } catch (Exception e) { InternalError ierr = new InternalError("Unable to set UID field"); ierr.initCause(e); throw ierr; } return id; } }
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?