SOMA.agent
Class AgentSystem

java.lang.Object
  extended bySOMA.agent.AgentSystem
All Implemented Interfaces:
IMUMBaseFacilities, IMUMFacilitiesLocalCacheEnabled

public class AgentSystem
extends java.lang.Object
implements IMUMBaseFacilities, IMUMFacilitiesLocalCacheEnabled

Classe di interfaccia fra agenti e sistema.

Si tratta dell'unico riferimento fornito ad un agente al momento dell'attivazione in un place. Quindi, per interagire con il mondo esterno l'agente dovra' necessariamente utilizzare riferimenti e metodi dell'AgentSystem che gli e' stato associato.

L'AgentSystem, se necessario, effettuerà i dovuti controlli di sicurezza prima di consentire ad un agente l'accesso ad una determinata risorsa.

E' possibile costruire sottoclassi di AgentSystem in modo da fornire interfacce di tipo diverso ad agenti diversi per motivi di flessibilità, efficienza o compatibilità.


Author:
Livio Profiri
See Also:
Agent, AgentWorker

Field Summary
 IndexHashtable sharedObjects
          Contenitore per oggetti condivisi fra agenti.
 
Constructor Summary
AgentSystem(Environment env)
          Costruttore.
 
Method Summary
 void addCacheManager(ICacheManager cacheManager)
          This method is used for runtime deploy of the cache manager.
 boolean addComponent(MyComponent component)
          This method let the agent to add a component of the local component repository.
 void addMultimediaClient(AgentID agent, IClientSessionManager csm)
          This method add a new client to a place
 void addMultimediaServer(java.lang.String classPath, java.lang.String interfaceName, java.lang.Object[] param)
          This method istantiate a multimedia service (which has to be present on the place) to the multimedia services directory.
 int agentsNumber()
          Restituisce il numero di worker e quindi di agenti del place.
 ICacheManager getCacheManager()
          Returns the cache manager reference if it has already been installed, null otherwise
 MyComponent getComponent(java.lang.String packageName, java.lang.String interfaceName)
          Get a component for the requested packageName and class, or null in case of error
 java.lang.Object getComponentInstance(java.lang.String packageName, java.lang.String interfaceName, java.lang.Object[] arguments)
          This method let agent get an instance of the required class of the required packageName.
 ICPUStatusNotifier getCPUStatusNotifier()
          This method returns a reference to the CPU status notifier
 PlaceID[] getDomains()
          Restituisce l'elenco degli identificatori dei domini, o un array vuoto se non e' presente un Domain Name Service, perche' non siamo in un default place.
 IDownloadManager getDownloadManager(ISwDownloadedListener listener)
          Gets the download manager, this call is suspensive until the agent is ready
 Environment getEnvironment()
           
 java.io.PrintStream getErr()
           
 java.io.InputStream getIn()
           
 IInitManager getInitManager(IInitListener listener, IProfile profile, AgentID clientAgent)
          Gets the init manager
 IPresentationMetadataRepository getMetadataAgent()
          This method returns an agent which can interact with the meta data container
 IClientSessionManager getMultimediaClient(AgentID agent)
          This method requires a client reference
 ComponentInfo getMultimediaComponentInfo(java.lang.String classPath, java.lang.String interfaceName)
          This method gets the ComponentInfo (host:port) of the multimedia service passed as argument
 java.io.PrintStream getOut()
           
 Path getPathToTheRoot()
          This method returns the path to the root, assuming that the system doesn't change its topology at the runtime.
 PlaceID getPlaceID()
           
 PlaceID[] getPlaces()
          Restituisce l'elenco degli identificatori dei place di questo dominio.
 IProfileContainerManager getProfileManager()
          This method returns an agent which can interact with the profile container
 Threshold getResourceConsumptionThresholds()
          Metodo usato da un agente per conoscere i valori delle soglie di consumo del place
 AgentInfo[] getResourceDiffConsumption(Agent ag)
          Metodo usato da un agente per conoscere i consumi differenziali, cioè relativi ad un intervallo di t secondi, di ciascuno dei suoi thread
 AgentInfo[] getResourceTotalConsumption(Agent ag)
          Metodo usato da un agente per conoscere i consumi complessivi dei suoi thread dal momento del lancio
 IMetaDataToResourceTranslator getResourceTranslator()
          This method returns a reference to the resource translator
protected  void go(Agent agent, PlaceID destination)
          Metodo di migrazione.
protected  void idle(Agent agent)
           
 boolean insertComponentDescriptor(ComponentDescriptor componentDescriptor)
          This method introduce a new entry in the DB
 MUM.repository.proxy.cache.IMetaDataCache isInCache(IMetadata metadata)
          Requires if the metadata is present into the local cache.
 MUM.repository.proxy.cache.IMetaDataCache isInCacheNoHit(IMetadata metadata)
          Requires if the metadata is present into the local cache.
 boolean isInitiated()
          Verifies if the local cache is present and initiated...
 boolean isMultimediaService(java.lang.String classPath, java.lang.String interfaceName)
          This method checks if the multiemdia service passed as argument is present in the multimedia service directory.
 boolean isONMultimediaService(java.lang.String classPath, java.lang.String interfaceName)
          This method checks if the multiemdia service passed as argument is ON.
 boolean isPresentComponentDescriptor(java.lang.String packageName, java.lang.String interfaceName)
          This method let the agent ask the database.
 boolean resetInUseFromCache(IMetadata requiredMetadata)
          This method returns true, if it finds that the required metadata is streamed from the cache, false otherwise.
 void sendMessage(Message message)
          Spedizione di un messaggio Non e' possibile statilire se il messaggio sara' correttamente recapitato.
 boolean setInUseFromCache(IMetadata requiredMetadata)
          This method returns true, if it finds that the required metadata will be streamed from the cache, false otherwise.
 void startMultimediaServer(java.lang.String classPath, java.lang.String interfaceName, java.lang.Object[] param)
          This method starts the multimedia service.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

sharedObjects

public IndexHashtable sharedObjects
Contenitore per oggetti condivisi fra agenti.

Ad ogni oggetto e' associato un indice di tipo int.

Constructor Detail

AgentSystem

public AgentSystem(Environment env)
Costruttore.

Method Detail

go

protected void go(Agent agent,
                  PlaceID destination)
           throws CantGoException
Metodo di migrazione.

Effettua i controlli di sicurezza, quindi invoca il metodo AgentWorker.go( PlaceID destination ).

Throws:
CantGoException

idle

protected void idle(Agent agent)

getResourceConsumptionThresholds

public Threshold getResourceConsumptionThresholds()
Metodo usato da un agente per conoscere i valori delle soglie di consumo del place


getResourceTotalConsumption

public AgentInfo[] getResourceTotalConsumption(Agent ag)
Metodo usato da un agente per conoscere i consumi complessivi dei suoi thread dal momento del lancio


getResourceDiffConsumption

public AgentInfo[] getResourceDiffConsumption(Agent ag)
Metodo usato da un agente per conoscere i consumi differenziali, cioè relativi ad un intervallo di t secondi, di ciascuno dei suoi thread


addComponent

public boolean addComponent(MyComponent component)
This method let the agent to add a component of the local component repository.

Returns:
Returns true if the operation was successful, false otherwise

isPresentComponentDescriptor

public boolean isPresentComponentDescriptor(java.lang.String packageName,
                                            java.lang.String interfaceName)
This method let the agent ask the database. If at least one implementation of the required interface is present it returns true. Otherwise false.

Parameters:
packageName - this is the uniquer identifier for a class of similar components. It will be defined by implemetation of this interface

getComponent

public MyComponent getComponent(java.lang.String packageName,
                                java.lang.String interfaceName)
Get a component for the requested packageName and class, or null in case of error


getDownloadManager

public IDownloadManager getDownloadManager(ISwDownloadedListener listener)
Gets the download manager, this call is suspensive until the agent is ready


getInitManager

public IInitManager getInitManager(IInitListener listener,
                                   IProfile profile,
                                   AgentID clientAgent)
Gets the init manager


getComponentInstance

public java.lang.Object getComponentInstance(java.lang.String packageName,
                                             java.lang.String interfaceName,
                                             java.lang.Object[] arguments)
This method let agent get an instance of the required class of the required packageName.

Specified by:
getComponentInstance in interface IMUMBaseFacilities
Parameters:
packageName - this is the uniquer identifier for a package
interfaceName - this is the name of the ADT we are interested in.
Returns:
The required instance, and null otherwise (NOTE: you must controll this)

insertComponentDescriptor

public boolean insertComponentDescriptor(ComponentDescriptor componentDescriptor)
This method introduce a new entry in the DB

Returns:
false if the table already contains the componentDescriptor

getMetadataAgent

public IPresentationMetadataRepository getMetadataAgent()
This method returns an agent which can interact with the meta data container

Returns:
a metadata agent which implements IPresentationsMetaDataRepository interface to interact with the metadata server

getProfileManager

public IProfileContainerManager getProfileManager()
This method returns an agent which can interact with the profile container

Returns:
a metadata agent which implements IPresentationsMetaDataRepository interface to interact with the metadata server

getPathToTheRoot

public Path getPathToTheRoot()
This method returns the path to the root, assuming that the system doesn't change its topology at the runtime. This assumption is strong, but in this case we haven't to send an agent up to the root for each new request. Note that this method works only in the ip. that we are using the visual version and not the text one...

Specified by:
getPathToTheRoot in interface IMUMBaseFacilities

addMultimediaServer

public void addMultimediaServer(java.lang.String classPath,
                                java.lang.String interfaceName,
                                java.lang.Object[] param)
                         throws SoftwareToAddNotFoundException
This method istantiate a multimedia service (which has to be present on the place) to the multimedia services directory. In case the SW to istantiate is not found this method throws a SOMA.MUM.MultimediaServicesService.SoftwareToAddNotFoundException

Throws:
SoftwareToAddNotFoundException

addMultimediaClient

public void addMultimediaClient(AgentID agent,
                                IClientSessionManager csm)
This method add a new client to a place


getMultimediaClient

public IClientSessionManager getMultimediaClient(AgentID agent)
This method requires a client reference


isInitiated

public boolean isInitiated()
Verifies if the local cache is present and initiated...

Specified by:
isInitiated in interface IMUMFacilitiesLocalCacheEnabled

addCacheManager

public void addCacheManager(ICacheManager cacheManager)
This method is used for runtime deploy of the cache manager. PAY ATTENTION!! If a local cache manager is already present and you call this method you overwrite it. Therefore before calling this method you should call the getCacheManager method.

Parameters:
cacheManager - the reference to the cache manager that will be used

getCacheManager

public ICacheManager getCacheManager()
Returns the cache manager reference if it has already been installed, null otherwise

Returns:
a reference to the cache manager service, null otherwise

isInCache

public MUM.repository.proxy.cache.IMetaDataCache isInCache(IMetadata metadata)
Requires if the metadata is present into the local cache. NOTE!! As a side effect if the presentation is present there is a cache hit for the metadata required. To change this look at the call chain...

Specified by:
isInCache in interface IMUMFacilitiesLocalCacheEnabled
Parameters:
metadata - the required metadata
Returns:
null if the Metadata is present in the cache, an IMetaDataCache otherwise.

isInCacheNoHit

public MUM.repository.proxy.cache.IMetaDataCache isInCacheNoHit(IMetadata metadata)
Requires if the metadata is present into the local cache. NOTE!! This method has no side effects, i.e. it does not produce locally any cache hit...

Specified by:
isInCacheNoHit in interface IMUMFacilitiesLocalCacheEnabled
Parameters:
metadata - the required metadata
Returns:
the currespondent IMetaDataCache, null if it is not present.

setInUseFromCache

public boolean setInUseFromCache(IMetadata requiredMetadata)
This method returns true, if it finds that the required metadata will be streamed from the cache, false otherwise. As a side effect the method sets the is-in-use flag on the local IMetaDataCache object. Produces no cache hit.

Specified by:
setInUseFromCache in interface IMUMFacilitiesLocalCacheEnabled

resetInUseFromCache

public boolean resetInUseFromCache(IMetadata requiredMetadata)
This method returns true, if it finds that the required metadata is streamed from the cache, false otherwise. As a side effect the method resets the is-in-use flag on the local IMetaDataCache object. Produces no cache hit.

Specified by:
resetInUseFromCache in interface IMUMFacilitiesLocalCacheEnabled

getMultimediaComponentInfo

public ComponentInfo getMultimediaComponentInfo(java.lang.String classPath,
                                                java.lang.String interfaceName)
                                         throws MultimediaServiceNotInstantiatedException
This method gets the ComponentInfo (host:port) of the multimedia service passed as argument

Throws:
MultimediaServiceNotInstantiatedException

isMultimediaService

public boolean isMultimediaService(java.lang.String classPath,
                                   java.lang.String interfaceName)
This method checks if the multiemdia service passed as argument is present in the multimedia service directory.


isONMultimediaService

public boolean isONMultimediaService(java.lang.String classPath,
                                     java.lang.String interfaceName)
This method checks if the multiemdia service passed as argument is ON. If the method returns false this could mean both that the multimedia service hasn't been instantiated yet, or that it is off. Thus this method should be called after the isMultimediaService method.


startMultimediaServer

public void startMultimediaServer(java.lang.String classPath,
                                  java.lang.String interfaceName,
                                  java.lang.Object[] param)
                           throws MultimediaServiceNotInstantiatedException
This method starts the multimedia service. Throws an exception if the multimedia service hasn't been instantiated

Throws:
MultimediaServiceNotInstantiatedException

getResourceTranslator

public IMetaDataToResourceTranslator getResourceTranslator()
This method returns a reference to the resource translator


getCPUStatusNotifier

public ICPUStatusNotifier getCPUStatusNotifier()
This method returns a reference to the CPU status notifier


getPlaceID

public PlaceID getPlaceID()

getIn

public java.io.InputStream getIn()

getOut

public java.io.PrintStream getOut()

getErr

public java.io.PrintStream getErr()

getEnvironment

public Environment getEnvironment()

getPlaces

public PlaceID[] getPlaces()
Restituisce l'elenco degli identificatori dei place di questo dominio.


getDomains

public PlaceID[] getDomains()
Restituisce l'elenco degli identificatori dei domini, o un array vuoto se non e' presente un Domain Name Service, perche' non siamo in un default place.


sendMessage

public void sendMessage(Message message)
Spedizione di un messaggio

Non e' possibile statilire se il messaggio sara' correttamente recapitato.

Questo metodo richiama {@AgentWorker.sendMessage( Message )


agentsNumber

public int agentsNumber()
Restituisce il numero di worker e quindi di agenti del place.



Copyright © 2004 Luca Foschini