activatable.java

来自「linux下建立JAVA虚拟机的源码KAFFE」· Java 代码 · 共 501 行 · 第 1/2 页

JAVA
501
字号
/* Activatable.java -- A common ancestor for the activatable objects.   Copyright (c) 1996, 1997, 1998, 1999, 2004, 2006   Free Software Foundation, Inc.This file is part of GNU Classpath.GNU Classpath is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 2, or (at your option)any later version. GNU Classpath is distributed in the hope that it will be useful, butWITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNUGeneral Public License for more details.You should have received a copy of the GNU General Public Licensealong with GNU Classpath; see the file COPYING.  If not, write to theFree Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA02110-1301 USA.Linking this library statically or dynamically with other modules ismaking a combined work based on this library.  Thus, the terms andconditions of the GNU General Public License cover the wholecombination.As a special exception, the copyright holders of this library give youpermission to link this library with independent modules to produce anexecutable, regardless of the license terms of these independentmodules, and to copy and distribute the resulting executable underterms of your choice, provided that you also meet, for each linkedindependent module, the terms and conditions of the license of thatmodule.  An independent module is a module which is not derived fromor based on this library.  If you modify this library, you may extendthis exception to your version of the library, but you are notobligated to do so.  If you do not wish to do so, delete thisexception statement from your version. */package java.rmi.activation;import gnu.java.rmi.server.ActivatableServerRef;import gnu.java.rmi.server.UnicastServer;import gnu.java.rmi.server.UnicastServerRef;import java.lang.reflect.Field;import java.rmi.MarshalledObject;import java.rmi.NoSuchObjectException;import java.rmi.Remote;import java.rmi.RemoteException;import java.rmi.server.ObjID;import java.rmi.server.RMIClientSocketFactory;import java.rmi.server.RMIServerSocketFactory;import java.rmi.server.RemoteObject;import java.rmi.server.RemoteServer;import java.rmi.server.UnicastRemoteObject;/** * A common ancestor for the implementations of the activatable objects. Such * objects require persistent access over time and can be activated by the * system. The derived classes also implements the needed interface of some * remote object and usually have the two parameter constructor, the first * parameter being the {@link ActivationID} and the second the * {@link MarshalledObject}. Activatable is the main class that developers need * to use to implement and manage activatable objects. It also contains methods * for making activatable remote objects that are not derived from the  * Activatable class. *  * @author Audrius Meskauskas (audriusa@bioinformatics.org) (from stub)  */public abstract class Activatable    extends RemoteServer{  /**   * Use SVUID for interoperability.   */  static final long serialVersionUID = - 3120617863591563455L;    /**   * The object activation id.   */  final ActivationID id;    /**   * This constructor is used to register export the object on the given port. A   * subclass of the Activatable class calls this constructor to register and   * export the object during initial construction. As a side-effect of   * activatable object construction, the remote object is both "registered"   * with the activation system and "exported" (on an anonymous port, if port is   * zero) to the RMI runtime so that it is available to accept incoming calls   * from clients.   *    * @param codebase the object code base url   * @param data the data, needed to activate the object.   * @param restart specifies reactivation mode after crash. If true, the object   *          is activated when activator is restarted or the activation group   *          is restarted. If false, the object is only activated on demand.   *          This flag does has no effect during the normal operation (the   *          object is normally activated on demand).   * @param port the port, on which the object will become available. The value   *          0 means anonymous port.   * @throws ActivationException if the activation failed   * @throws RemoteException if the remote call failed.   */  protected Activatable(String codebase, MarshalledObject data,                        boolean restart, int port) throws ActivationException,      RemoteException  {    ActivationDesc descriptor = new ActivationDesc(getClass().getName(),                                                   codebase, data, restart);    id = obtainId(descriptor);    exportObject(this, id, port);  }  /**   * This constructor is used to register export the object on the given port,   * additionally specifying the socket factories. A subclass of the Activatable   * class calls this constructor to register and export the object during   * initial construction.   *    * @param codebase the object code base url   * @param data the data, needed to activate the object.   * @param restart specifies reactivation mode after crash. If true, the object   *          is activated when activator is restarted or the activation group   *          is restarted. If false, the object is only activated on demand.   *          This flag does has no effect during the normal operation (the   *          object is normally activated on demand).   * @param port the port, on which the object will become available. The value   *          0 means anonymous port.   * @param csf the client socket factory   * @param ssf the server socket factory   * @throws ActivationException if the activation failed   * @throws RemoteException if the remote call failed.   */  protected Activatable(String codebase, MarshalledObject data,                        boolean restart, int port, RMIClientSocketFactory csf,                        RMIServerSocketFactory ssf) throws ActivationException,      RemoteException  {    ActivationDesc descriptor = new ActivationDesc(getClass().getName(),                                                   codebase, data, restart);    id = obtainId(descriptor);    exportObject(this, id, port);  }  /**   * Creates the new instance of activatable with the given activation id and is   * listening at the given port. A subclass of the Activatable class calls this   * constructor when the object itself is activated via its special   * "activation" constructor with the two parameters ({@link ActivationID},   * {@link MarshalledObject}). As a side effect, the object is exported and is   * available to accept incomming calls.   *    * @param anId the activation id   * @param port the port, on which the activatable will be listening   * @throws RemoteException if the activation failed.   */  protected Activatable(ActivationID anId, int port) throws RemoteException  {    id = anId;    try      {        exportObject(this, anId, port);      }    catch (Exception e)      {        e.printStackTrace();        RemoteException acex =           new RemoteException("cannot export Activatable", e);        throw acex;      }  }  /**   * Creates the new instance of activatable with the given activation id and is   * listening at the given port, using the specified client and server sockets   * factories. A subclass of the Activatable class calls this   * constructor when the object itself is activated via its special   * "activation" constructor with the two parameters ({@link ActivationID},   * {@link MarshalledObject}). As a side effect, the object is exported and is   * available to accept incomming calls.   *    * @param anId the activation id   * @param port the port, on which the activatable will be listening   * @param csf the client socket factory   * @param ssf the server socket factory   *    * @throws RemoteException if the remote call failed   */  protected Activatable(ActivationID anId, int port, RMIClientSocketFactory csf,                        RMIServerSocketFactory ssf) throws RemoteException  {    id = anId;    try      {        exportObject(this, anId, port, csf, ssf);      }    catch (Exception e)      {        RemoteException acex = new RemoteException();        acex.initCause(e);        throw acex;      }  }    /**   * Get the objects activation identifier.   *    * @return the object activation identifier   */  protected ActivationID getID()  {    return id;  }    /**   * Obtain the activation Id from the activation descriptor bu registering   * within the current group.   */  static ActivationID obtainId(ActivationDesc descriptor) throws RemoteException,      UnknownGroupException, ActivationException  {    return ActivationGroup.currentGroupID().getSystem().registerObject(descriptor);  }    /**   * This method registers an activatable object. The object is expected to   * be on the anonymous port (null client and server socket factories).   *    * @param desc the object description.   * @return the remote stub for the activatable object (the first call on this   *         stub will activate the object).   * @throws UnknownGroupException if the object group identifier is unknown   * @throws ActivationException if the activation system is not running   * @throws RemoteException if the remote call fails   */  public static Remote register(ActivationDesc desc)      throws UnknownGroupException, ActivationException, RemoteException  {    ActivationID id = obtainId(desc);    return id.activate(false);  }    /**   * Inactivates and unexports the object. The subsequent calls will activate   * the object again. The object is not inactivated if it is currently   * executing calls.   *    * @param id the id of the object being inactivated   * @return true if the object has been inactivated, false if it has not been

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?