public class ServiceContainer
extends java.lang.Object
The current implementation does not downcast the provided service class when searching for an appropriate service implementation. For example:
class Derived extends Base {} serviceContainer.add(Derived.class, instanceOfDerived); // Searching for the base class returns null assert(null == serviceContainer.get(Base.class, instanceOfDerived));
Constructor and Description |
---|
ServiceContainer() |
Modifier and Type | Method and Description |
---|---|
void |
addCleaner(BiConsumer<java.lang.String,java.lang.String> cleaner)
Registers a new cleaner.
|
<T> T |
addService(java.lang.Class<T> serviceClass,
T service)
Adds the specified service to this
ServiceContainer . |
void |
cleanOplet(java.lang.String jobId,
java.lang.String elementId)
Invokes all the registered cleaners in the context of the specified
job and element.
|
<T> T |
getService(java.lang.Class<T> serviceClass)
Returns the service to which the specified service class key is
mapped, or
null if this ServiceContainer contains no
service for that key. |
<T> T |
removeService(java.lang.Class<T> serviceClass)
Removes the specified service from this
ServiceContainer . |
public <T> T addService(java.lang.Class<T> serviceClass, T service)
ServiceContainer
.
Associates the specified service with the service class. If the container has previously contained a service for the class, the old value is replaced by the specified value.
T
- service class typeserviceClass
- the class of service to add.service
- service to add to this container.serviceClass
, or
null
if there was no registered mapping.java.lang.NullPointerException
- if the specified service class or
service is null.public <T> T removeService(java.lang.Class<T> serviceClass)
ServiceContainer
.T
- service class typeserviceClass
- the class of service to remove.null
if there was no registered service.java.lang.NullPointerException
- if the specified service class is null.public <T> T getService(java.lang.Class<T> serviceClass)
null
if this ServiceContainer
contains no
service for that key.T
- service class typeserviceClass
- the class whose associated service is to be returnednull
if no service is registered for the class.public void addCleaner(BiConsumer<java.lang.String,java.lang.String> cleaner)
A cleaner is a hook which is invoked when the runtime
closes an element of Job
.
When an element of job is closed cleaner.accept(jobId, elementId)
is called where jobId
is the job identifier
and
elementId
is the unique identifier for the element.
cleaner
- The cleaner.public void cleanOplet(java.lang.String jobId, java.lang.String elementId)
jobId
- The job identifier.elementId
- The element identifier.Copyright © 2016 The Apache Software Foundation. All Rights Reserved - bbe71fa-20161201-1641