com.ibm.aglets
Class AgletContextImpl

java.lang.Object
  extended bycom.ibm.aglets.AgletContextImpl
All Implemented Interfaces:
AgletContext

public final class AgletContextImpl
extends java.lang.Object
implements AgletContext

The AgletContextImpl class is the execution context for running aglets. It provides means for maintaining and managing running aglets in an environment where the aglets are protected from each other and the host system is secured against malicious aglets.

Version:
1.20 $Date: 2002/01/19 22:10:43 $
Author:
Danny B. Lange, Mitsuru Oshima, ONO Kouichi

Nested Class Summary
(package private)  class AgletContextImpl.EventRunner
           
 
Field Summary
private  java.util.Hashtable _agletProxies
           
(package private)  java.util.Properties _contextProperties
           
private  java.net.URL _hostingURL
           
private  java.lang.String _name
           
private  Persistence _persistence
           
private  ResourceManagerFactory _rm_factory
           
private  boolean _secure
           
(package private)  SubscriberManager _subscriberManager
           
(package private)  AgletTimer _timer
           
private static ContextPermission ADD_LISTENER_PERMISSION
           
private  java.util.Hashtable clips
           
(package private)  AgletID context_aid
           
private  int creating
           
private  java.lang.Object creationLock
           
(package private)  AgletContextImpl.EventRunner erunner
           
private  java.util.Hashtable images
           
(package private)  ContextListener listeners
           
private static LogCategory logCategory
           
private static ContextPermission REMOVE_LISTENER_PERMISSION
           
private static ContextPermission SHUTDOWN_PERMISSION
           
private  boolean shutting_down
           
private static ContextPermission START_PERMISSION
           
 
Constructor Summary
(package private) AgletContextImpl(java.lang.String name)
          Creates an execution context for aglets.
(package private) AgletContextImpl(java.lang.String name, boolean secure)
           
 
Method Summary
(package private)  void addAgletProxy(AgletID aid, AgletProxyImpl proxy)
           
 void addContextListener(ContextListener o)
          Adds the specified context listener to receive context events from this context.
(package private)  void checkPermission(java.security.Permission p)
           
 void clearCache(java.net.URL codebase)
          Clear the cache
private  AgletProxy createAglet(java.net.URL url, java.lang.String classname, java.security.cert.Certificate owner, java.lang.Object init)
          Creates an instance of the specified aglet located at the specified URL.
 AgletProxy createAglet(java.net.URL url, java.lang.String classname, java.lang.Object init)
          Creates an instance of the specified aglet located at the specified URL.
(package private)  ResourceManager createResourceManager(java.net.URL codebase, java.security.cert.Certificate owner, ClassName[] table)
           
(package private)  void endCreation()
           
 java.util.Enumeration getAgletProxies()
          Gets the aglet proxies in the current execution context.
 java.util.Enumeration getAgletProxies(int type)
          Gets the aglet proxies in the current execution context.
 AgletProxy getAgletProxy(AgletID aid)
          Gets the proxy for an aglet specified by its identity.
 AgletProxy getAgletProxy(java.net.URL host, AgletID aid)
          Deprecated.  
 java.applet.AudioClip getAudioClip(java.net.URL url)
          Gets an audio clip.
 java.net.URL getHostingURL()
          Returns the URL of the daemon serving all current execution contexts.
 java.awt.Image getImage(ImageData d)
          Gets an image.
 java.awt.Image getImage(java.net.URL url)
          Gets an image.
 ImageData getImageData(java.net.URL url)
          Gets an image data.
 java.lang.String getName()
          Gets the name of the context
 Persistence getPersistence()
           
 java.lang.Object getProperty(java.lang.String key)
          Gets the context property indicated by the key.
 java.lang.Object getProperty(java.lang.String key, java.lang.Object def)
          Gets the context property indicated by the key and default value.
 ResourceManagerFactory getResourceManagerFactory()
           
(package private)  boolean getSecurity()
           
(package private)  java.lang.Object handleMessage(Message msg)
           
(package private)  void log(java.lang.String kind, java.lang.String msg)
           
 ReplySet multicastMessage(Message msg)
          Sends a multicast message to the subscribers in the context.
(package private)  boolean noResponseAglet(AgletProxy proxy)
           
 void postEvent(ContextEvent event, boolean sync)
           
 void postEvent0(ContextEvent event)
           
 void receiveAglet(Name agent_name, ClassName[] classnames, java.lang.String codebase, byte[] agent, java.lang.String sender)
          Receives an aglet.
(package private)  void removeAgletProxy(AgletID aid, AgletProxyImpl proxy)
           
 void removeContextListener(ContextListener o)
          Removes the specified context listener.
 AgletProxy retractAglet(Ticket ticket, AgletID aid)
           
 AgletProxy retractAglet(java.net.URL url)
          Deprecated.  
 AgletProxy retractAglet(java.net.URL url, AgletID aid)
          Retracts the Aglet specified by its url: scheme://host-domain-name/[user-name]#aglet-identity.
 void setPersistence(Persistence p)
           
 void setProperty(java.lang.String key, java.lang.Object value)
          Sets the context property
 void setResourceManagerFactory(ResourceManagerFactory rmf)
           
(package private)  void setSecurity(boolean secure)
           
 void showDocument(java.net.URL url)
          Shows a new document.
 void shutdown()
          Shutdown the context.
 void shutdown(Message msg)
          Shutdown the context with the specific message object.
 void start()
          Starts
 void start(boolean reactivate)
          Starts the context.
(package private)  void startCreation()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logCategory

private static LogCategory logCategory

_secure

private boolean _secure

START_PERMISSION

private static ContextPermission START_PERMISSION

SHUTDOWN_PERMISSION

private static ContextPermission SHUTDOWN_PERMISSION

ADD_LISTENER_PERMISSION

private static ContextPermission ADD_LISTENER_PERMISSION

REMOVE_LISTENER_PERMISSION

private static ContextPermission REMOVE_LISTENER_PERMISSION

_hostingURL

private java.net.URL _hostingURL

_name

private java.lang.String _name

_persistence

private Persistence _persistence

_agletProxies

private java.util.Hashtable _agletProxies

_contextProperties

java.util.Properties _contextProperties

_subscriberManager

SubscriberManager _subscriberManager

_rm_factory

private ResourceManagerFactory _rm_factory

_timer

AgletTimer _timer

creationLock

private java.lang.Object creationLock

creating

private int creating

shutting_down

private boolean shutting_down

context_aid

AgletID context_aid

listeners

ContextListener listeners

erunner

AgletContextImpl.EventRunner erunner

images

private java.util.Hashtable images

clips

private java.util.Hashtable clips
Constructor Detail

AgletContextImpl

AgletContextImpl(java.lang.String name)
Creates an execution context for aglets.


AgletContextImpl

AgletContextImpl(java.lang.String name,
                 boolean secure)
Method Detail

addAgletProxy

void addAgletProxy(AgletID aid,
                   AgletProxyImpl proxy)
             throws InvalidAgletException
Throws:
InvalidAgletException

addContextListener

public void addContextListener(ContextListener o)
Description copied from interface: AgletContext
Adds the specified context listener to receive context events from this context.

Specified by:
addContextListener in interface AgletContext
Parameters:
o - the context listener

checkPermission

void checkPermission(java.security.Permission p)

clearCache

public void clearCache(java.net.URL codebase)
Clear the cache

Specified by:
clearCache in interface AgletContext
Parameters:
codebase - the codebase of the cache to clean up. if null, entire cache in this context is cleared.

createAglet

public AgletProxy createAglet(java.net.URL url,
                              java.lang.String classname,
                              java.lang.Object init)
                       throws java.io.IOException,
                              AgletException,
                              java.lang.ClassNotFoundException,
                              java.lang.InstantiationException
Creates an instance of the specified aglet located at the specified URL.

Specified by:
createAglet in interface AgletContext
Parameters:
url - the URL to load the aglet class from.
classname - code gives the name of the file that contains the aglet's compiled class code. This file is relative to the base URL of the aglet, and cannot be absolute.
init - init is an object passed on to the aglet's onCreation method.
Returns:
a newly instantiated and initialized Aglet.
Throws:
java.lang.ClassNotFoundException - if the class was not found
java.lang.InstantiationException - if failed to instantiate the Aglet.
AgletException - if the aglets can not be created.
java.io.IOException
See Also:
Aglet.onCreation(java.lang.Object)

createAglet

private AgletProxy createAglet(java.net.URL url,
                               java.lang.String classname,
                               java.security.cert.Certificate owner,
                               java.lang.Object init)
                        throws java.io.IOException,
                               AgletException,
                               java.lang.ClassNotFoundException,
                               java.lang.InstantiationException
Creates an instance of the specified aglet located at the specified URL.

Parameters:
url - the URL to load the aglet class from.
Returns:
a newly instantiated and initialized Aglet.
Throws:
java.lang.ClassNotFoundException - if the class was not found
java.lang.InstantiationException - if failed to instantiate the Aglet.
java.io.IOException
AgletException

createResourceManager

ResourceManager createResourceManager(java.net.URL codebase,
                                      java.security.cert.Certificate owner,
                                      ClassName[] table)

endCreation

void endCreation()

getAgletProxies

public java.util.Enumeration getAgletProxies()
Gets the aglet proxies in the current execution context.

Specified by:
getAgletProxies in interface AgletContext
Returns:
an enumeration of aglet proxies.

getAgletProxies

public java.util.Enumeration getAgletProxies(int type)
Gets the aglet proxies in the current execution context.

Specified by:
getAgletProxies in interface AgletContext
Parameters:
type - the type of aglets. ACTIVE, INACTIVE or ACTIVE | INACTIVE,
Returns:
an enumeration of aglet proxies.
See Also:
Aglet.ACTIVE, Aglet.INACTIVE

getAgletProxy

public AgletProxy getAgletProxy(AgletID aid)
Gets the proxy for an aglet specified by its identity.

Specified by:
getAgletProxy in interface AgletContext
Parameters:
aid - the identity of the aglet.
Returns:
the aglet proxy.

getAgletProxy

public AgletProxy getAgletProxy(java.net.URL host,
                                AgletID aid)
Deprecated.  

Gets the proxy for a remote aglet specified by url

Specified by:
getAgletProxy in interface AgletContext
Parameters:
aid - the identity of the aglet.
host - the address specifing a remote context.
Returns:
the aglet proxy
See Also:
getName

getAudioClip

public java.applet.AudioClip getAudioClip(java.net.URL url)
Description copied from interface: AgletContext
Gets an audio clip.

Specified by:
getAudioClip in interface AgletContext
Parameters:
url - an absolute URL giving the location of the audio file.
Returns:
the Audio clip object give by the URL.

getHostingURL

public java.net.URL getHostingURL()
Returns the URL of the daemon serving all current execution contexts.

Specified by:
getHostingURL in interface AgletContext
Returns:
the URL of the daemon. null if the hosting information is not available.
Throws:
AgletException - if the hosting URL cannot be determined.

getImage

public java.awt.Image getImage(ImageData d)
Description copied from interface: AgletContext
Gets an image. This is a tempolary solution.

Specified by:
getImage in interface AgletContext
Parameters:
d - a serializable image data.
Returns:
the image object converted from the image data.

getImage

public java.awt.Image getImage(java.net.URL url)
Description copied from interface: AgletContext
Gets an image.

Specified by:
getImage in interface AgletContext
Parameters:
url - an absolute URL giving the location of the image file.
Returns:
the image object give by the URL.

getImageData

public ImageData getImageData(java.net.URL url)
Description copied from interface: AgletContext
Gets an image data. This is a tempolary solution.

Specified by:
getImageData in interface AgletContext
Parameters:
url - an absolute URL giving the location of the image file.
Returns:
the serializable image data.

getName

public java.lang.String getName()
Gets the name of the context

Specified by:
getName in interface AgletContext
Returns:
the name of the context

getPersistence

public Persistence getPersistence()
                           throws java.io.IOException
Throws:
java.io.IOException

getProperty

public java.lang.Object getProperty(java.lang.String key)
Gets the context property indicated by the key.

Specified by:
getProperty in interface AgletContext
Parameters:
key - the name of the context property.
Returns:
the value of the specified key.

getProperty

public java.lang.Object getProperty(java.lang.String key,
                                    java.lang.Object def)
Gets the context property indicated by the key and default value.

Specified by:
getProperty in interface AgletContext
Parameters:
key - the name of the context property.
def - the value to use if this property is not set.
Returns:
the value of the specified key.

getResourceManagerFactory

public ResourceManagerFactory getResourceManagerFactory()

getSecurity

boolean getSecurity()

handleMessage

java.lang.Object handleMessage(Message msg)
                         throws NotHandledException,
                                MessageException
Throws:
NotHandledException
MessageException

log

void log(java.lang.String kind,
         java.lang.String msg)

multicastMessage

public ReplySet multicastMessage(Message msg)
Description copied from interface: AgletContext
Sends a multicast message to the subscribers in the context.

Specified by:
multicastMessage in interface AgletContext
Returns:
ReplySet containing FutureReplies

noResponseAglet

boolean noResponseAglet(AgletProxy proxy)

postEvent

public void postEvent(ContextEvent event,
                      boolean sync)

postEvent0

public void postEvent0(ContextEvent event)

receiveAglet

public void receiveAglet(Name agent_name,
                         ClassName[] classnames,
                         java.lang.String codebase,
                         byte[] agent,
                         java.lang.String sender)
                  throws AgletException,
                         java.lang.ClassNotFoundException
Receives an aglet. Will start the aglet and return its proxy.

Throws:
AgletException - if it is not received.
java.lang.ClassNotFoundException

removeAgletProxy

void removeAgletProxy(AgletID aid,
                      AgletProxyImpl proxy)

removeContextListener

public void removeContextListener(ContextListener o)
Description copied from interface: AgletContext
Removes the specified context listener.

Specified by:
removeContextListener in interface AgletContext
Parameters:
o - the context listener

retractAglet

public AgletProxy retractAglet(Ticket ticket,
                               AgletID aid)
                        throws java.io.IOException,
                               AgletException
Throws:
java.io.IOException
AgletException

retractAglet

public AgletProxy retractAglet(java.net.URL url)
                        throws java.io.IOException,
                               AgletException
Deprecated.  

Retracts the Aglet specified by its url: scheme://host-domain-name/[user-name]#aglet-identity.

Specified by:
retractAglet in interface AgletContext
Parameters:
url - the location and aglet identity of the aglet to be retracted.
Returns:
the aglet proxy for the retracted aglet.
Throws:
AgletException - when the method failed to retract the aglet.
java.io.IOException

retractAglet

public AgletProxy retractAglet(java.net.URL url,
                               AgletID aid)
                        throws java.io.IOException,
                               AgletException
Retracts the Aglet specified by its url: scheme://host-domain-name/[user-name]#aglet-identity.

Specified by:
retractAglet in interface AgletContext
Parameters:
url - the location and aglet identity of the aglet to be retracted.
aid - the aglet identity of the aglet to be retracted.
Returns:
the aglet proxy for the retracted aglet.
Throws:
AgletException - when the method failed to retract the aglet.
java.io.IOException

setPersistence

public void setPersistence(Persistence p)
                    throws AgletException
Throws:
AgletException

setProperty

public void setProperty(java.lang.String key,
                        java.lang.Object value)
Sets the context property

Specified by:
setProperty in interface AgletContext
Parameters:
key - the name of the context property.
value - the value to be stored.
Returns:
the value of the specified key.

setResourceManagerFactory

public void setResourceManagerFactory(ResourceManagerFactory rmf)

setSecurity

void setSecurity(boolean secure)

showDocument

public void showDocument(java.net.URL url)
Shows a new document. This may be ignored by the aglet context. ContextPermission("showDocument", url) is required.

Specified by:
showDocument in interface AgletContext
Parameters:
url - an url to be shown

shutdown

public void shutdown()
Description copied from interface: AgletContext
Shutdown the context. This is ignored if the context is already stopped.

Specified by:
shutdown in interface AgletContext
See Also:
start

shutdown

public void shutdown(Message msg)
Description copied from interface: AgletContext
Shutdown the context with the specific message object. This message object is delivered to all aglets in the context before all aglets are killed. This is ignored if the context is already stopped.

Specified by:
shutdown in interface AgletContext
See Also:
start

start

public void start()
Starts

Specified by:
start in interface AgletContext

start

public void start(boolean reactivate)
Description copied from interface: AgletContext
Starts the context. This is ignored if the context is already runnig.

Specified by:
start in interface AgletContext
Parameters:
reactivate - if false, it does not activate aglets in the deactivation spool

startCreation

void startCreation()
             throws ShuttingDownException
Throws:
ShuttingDownException