📄 aglet.java
字号:
package com.ibm.aglet;/* * @(#)Aglet.java * * (c) Copyright IBM Corp. 1996, 1997, 1998 * * IBM grants you a non-exclusive, non-transferrable License to * use this program internally solely for the purposes of testing * and evaluating Java Aglet API. * You may not distribute, sublicense, lease, rent or use this * sample program externally. * * THIS ROGRAM IS PROVIDED "AS IS" WITHOUT ANY WARRANTY EXPRESS OR * IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE WARRANTY OF * NON-INFRINGEMENT AND THE WARRANTIES OF MERCHANTIBILITY AND * FITNESS FOR A PARTICULAR PURPOSE. * IBM WILL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY YOU AS * A RESULT OF USING THIS SAMPLE PROGRAM. IN NO EVENT WILL IBM BE * LIABLE FOR ANY SPECIAL, INDIRECT CONSEQUENTIAL DAMAGES OR LOST * PROFITS EVEN IF IBM HAS BEEN ADVISED OF THE POSSIBILITY OF THEIR * OCCURRENCE OR LOSS OF OR DAMAGE TO YOUR RECORDS OR DATA. * IBM WILL NOT BE LIABLE FOR ANY THIRD PARTY CLAIMS AGAINST YOU. */import java.security.PermissionCollection;import com.ibm.aglet.event.*;import java.net.URL;import java.io.IOException;import java.io.NotSerializableException;import java.awt.Image;import java.applet.AudioClip;/** * The <tt>Aglet</tt> class is the abstract base class for aglets. Use this * class to create your own personalized aglets. * * @version 2.00 $Date: 2001/07/28 06:33:50 $ * @author Danny B. Lange * @author Mitsuru Oshima */public abstract class Aglet implements java.io.Serializable { /* * Current API version of the Aglet class. */ public static final short MAJOR_VERSION = 1; public static final short MINOR_VERSION = 2; /** * State of Aglet. * @see AgletContext#getAgletProxies */ public static final int ACTIVE = 0x1; public static final int INACTIVE = 0x1 << 1; /* * The aglet's stub. This instance variable is transient to avoid * serializing the stub. */ transient AgletStub _stub = null; private CloneListener cloneListener = null; private MobilityListener mobilityListener = null; private PersistencyListener persistencyListener = null; /** * Constructs an uninitialized aglet. This method is called only * once in the life cycle of an aglet. As a rule, you should never * override this constructor. Instead, you should override * <tt>onCreation()</tt> to initialize the aglet upon creation. * @see Aglet#onCreation */ protected Aglet() {} /** * Adds the specified clone listener to receive clone events * from this aglet. * @param listener the mobility listener */ synchronized final public void addCloneListener(CloneListener listener) { if (cloneListener == null) { cloneListener = listener; } else if (cloneListener == listener) { return; } else if (cloneListener instanceof AgletEventListener) { ((AgletEventListener)cloneListener).addCloneListener(listener); } else if (cloneListener instanceof CloneListener) { cloneListener = new AgletEventListener(cloneListener, listener); } } /** * Adds the specified mobility listener to receive mobility events * from this aglet. * @param listener the mobility listener */ synchronized final public void addMobilityListener(MobilityListener listener) { if (mobilityListener == null) { mobilityListener = listener; } else if (mobilityListener == listener) { return; } else if (mobilityListener instanceof AgletEventListener) { ((AgletEventListener)mobilityListener) .addMobilityListener(listener); } else if (mobilityListener instanceof MobilityListener) { mobilityListener = new AgletEventListener(mobilityListener, listener); } } /** * Adds the specified persistency listener to receive persistency events * from this aglet. * @param listener the persistency listener */ synchronized final public void addPersistencyListener(PersistencyListener listener) { if (persistencyListener == null) { persistencyListener = listener; } else if (persistencyListener == listener) { return; } else if (persistencyListener instanceof AgletEventListener) { ((AgletEventListener)persistencyListener) .addPersistencyListener(listener); } else if (persistencyListener instanceof PersistencyListener) { persistencyListener = new AgletEventListener(persistencyListener, listener); } } /** * Clones the aglet and the proxy that holds the aglet. Notice that * it is the cloned aglet proxy which is returned by this method. * @return the cloned proxy. * @exception CloneNotSupportedException when the cloning fails. * @see CloneListener#onCloning * @see CloneListener#onClone */ public final Object clone() throws CloneNotSupportedException { return _stub.clone(); } /** * Deactivates the aglet. The aglet will temporarily be stopped and * removed from its current context. It will return to the context and * resume execution after the specified period has elapsed. * @param millisecounds duration of the aglet deactivating. * If this is 0, it will be activeted at the next startup time. * @exception NotSerializableException if the entire aglet is not * serializable. * @exception IOException if I/O failed * @exception IllegalArgumentException if the argument is negative. */ public final void deactivate(long duration) throws IOException { _stub.deactivate(duration); } /** * Dispatches the aglet to the location (host) specified by the * ticket as argument. * @param ticket ticket to dispatch destination. * @exception ServerNotFoundException if the server could not be found. * @exception java.net.UnknownHostException if the host given in the URL does not * exist. * @exception RequestRefusedException if the remote server refused the * dispatch request. * @exception ServerNotFoundException if the the destination is * unavailable * @exception NotSerializableException if the entire aglet is not * serializable * @see MobilityListener#onDispatching * @see MobilityListener#onArrival */ public final void dispatch(Ticket ticket) throws IOException, RequestRefusedException { _stub.dispatch(ticket); } /** * Dispatches the aglet to the location (host) specified by the * argument. * @param destination dispatch destination. * @exception ServerNotFoundException if the server could not be found. * @exception java.net.UnknownHostException if the host given in the URL does not * exist. * @exception RequestRefusedException if the remote server refused the * dispatch request. * @exception ServerNotFoundException if the the destination is * unavailable * @exception NotSerializableException if the entire aglet is not * serializable * @see MobilityListener#onDispatching * @see MobilityListener#onArrival */ public final void dispatch(URL destination) throws IOException, RequestRefusedException { _stub.dispatch(destination); } /** * Dispatches an event to this aglet * @param ev the aglet event */ final public void dispatchEvent(AgletEvent ev) { switch (ev.getID()) { case CloneEvent.CLONING: case CloneEvent.CLONE: case CloneEvent.CLONED: processCloneEvent((CloneEvent)ev); break; case MobilityEvent.DISPATCHING: case MobilityEvent.REVERTING: case MobilityEvent.ARRIVAL: processMobilityEvent((MobilityEvent)ev); break; case PersistencyEvent.DEACTIVATING: case PersistencyEvent.ACTIVATION: processPersistencyEvent((PersistencyEvent)ev); break; } } /** * Destroys and removes the aglet from its current aglet context. * A successful invocation of this method will kill all threads * created by the given aglet. * @see Aglet#onDisposing */ public final void dispose() { _stub.dispose(); } /** * Exits the current monitor. * @exception IllegalMonitorStateException if the current thread is not the * owner of the monitor. * @see Aglet#exitMonitor * @see waitMessage * @see notifyMessage * @see notifyAllMessages */ public void exitMonitor() { getMessageManager().exitMonitor(); } /** * Gets the context in which the aglet is currently executing. * @return the current execution context. */ public final AgletContext getAgletContext() { return _stub.getAgletContext(); } /** * Gets the id of this aglet. * @return the <tt>AgletID<tt> object of this aglet * @see aglet.AgletID */ public final AgletID getAgletID() { return getAgletInfo().getAgletID(); } /** * Gets the info object of this aglet * @return the <tt>aglet.AgletInfo<tt> object of this aglet * @see aglet.AgletID */ public final AgletInfo getAgletInfo() { return _stub.getAgletInfo(); } /** * Gets an audio data */ public final AudioClip getAudioData(URL url) throws IOException { return getAgletContext().getAudioClip(url); } /** * Gets the code base URL of this aglet * @return the <tt>java.net.URL<tt> object of this aglet * @see aglet.AgletID */ public final URL getCodeBase() { return getAgletInfo().getCodeBase(); } /** * Gets an image */ public final Image getImage(URL url) throws IOException { return getAgletContext().getImage(url); } /** * Gets an image */ public final Image getImage(URL url, String name) throws IOException { return getAgletContext().getImage(new URL(url, name)); } /** * Gets the message manager. * @return the message manager. */ public final MessageManager getMessageManager() { return _stub.getMessageManager(); } /** * Gets the protections: permission collection about * who can send what kind of messages to the aglet * @return collection of protections about who can send * what kind of messages to the aglet */ public PermissionCollection getProtections() { return _stub.getProtections(); } /** * Gets the proxy of aglet. * @return the proxy of aglet */ public final AgletProxy getProxy() { return _stub.getAgletContext().getAgletProxy(getAgletID()); } /** * Gets the message line of this Aglet. * @return the <tt>String<tt> representing a message the aglet shows. */ public final String getText() { return _stub.getText(); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -