Top Description Methods
org.apache.avalon.framework.service

public Interface ServiceManager


A ServiceManager selects Objects based on a role. The contract is that all the Objects implement the differing roles and there is one Object per role. If you need to select on of many Objects that implement the same role, then you need to use a ServiceSelector. Roles are usually the full interface name. A role is better understood by the analogy of a play. There are many different roles in a script. Any actor or actress can play any given part and you get the same results (phrases said, movements made, etc.). The exact nuances of the performance is different. Below is a list of things that might be considered the different roles: The ServiceManager does not specify the methodology of getting the Object, merely the interface used to get it. Therefore the ServiceManager can be implemented with a factory pattern, an object pool, or a simple Hashtable.
Author
Avalon Development Team
Version
$Id: ServiceManager.java 506231 2007-02-12 02:36:54Z crossley $
See Also
org.apache.avalon.framework.service.Serviceable, org.apache.avalon.framework.service.ServiceSelector

Method Summary

Modifier and TypeMethod and Description
public boolean

Returns:

True if the object exists, False if it does not.
hasService
(String
a string identifying the key to check.
key
)

Check to see if a Object exists for a key.

public Object

Returns:

an Object value
lookup
(String
The lookup key of the Object to retrieve.
key
)

Get the Object associated with the given key.

public void
release(Object
The Object we are releasing, may also be a null reference
object
)

Return the Object when you are finished with it.

Method Detail

hasServiceback to summary
public boolean hasService(String key)

Check to see if a Object exists for a key.

Parameters
key:String

a string identifying the key to check.

Returns:boolean

True if the object exists, False if it does not.

lookupback to summary
public Object lookup(String key) throws ServiceException

Get the Object associated with the given key. For instance, If the ServiceManager had a LoggerComponent stored and referenced by key, the following could be used:

try
{
    LoggerComponent log;
    myComponent = (LoggerComponent) manager.lookup( LoggerComponent.ROLE );
}
catch (...)
{
    ...
}
Parameters
key:String

The lookup key of the Object to retrieve.

Returns:Object

an Object value

Exceptions
ServiceException:
if an error occurs
releaseback to summary
public void release(Object object)

Return the Object when you are finished with it. This allows the ServiceManager to handle the End-Of-Life Lifecycle events associated with the Object. Please note, that no Exception should be thrown at this point. This is to allow easy use of the ServiceManager system without having to trap Exceptions on a release.

Parameters
object:Object

The Object we are releasing, may also be a null reference