T
- The type of the interface representing a Dependency Manager Dependency (must extends the Dependency interface).public abstract class AbstractDependency<T extends Dependency> extends java.lang.Object implements Dependency, DependencyContext, ComponentDependencyDeclaration
Modifier and Type | Field and Description |
---|---|
protected static java.util.Dictionary<java.lang.Object,java.lang.Object> |
EMPTY_PROPERTIES
Default empty dependency properties.
|
protected java.lang.String |
m_add
Component callback used to inject an added dependency.
|
protected boolean |
m_autoConfig
Can this Dependency be auto configured in the component instance fields ?
|
protected java.lang.String |
m_autoConfigInstance
The Component field name where the Dependency can be injected (null means any field with a compatible type
will be injected).
|
protected boolean |
m_autoConfigInvoked
Indicates if the setAutoConfig method has been invoked.
|
protected boolean |
m_available
Is this Dependency available ? Volatile because the getState method (part of the
ComponentDependencyDeclaration interface) may be called by any thread, at any time. |
protected java.lang.Object |
m_callbackInstance
The object instance on which the dependency callbacks are invoked on.
|
protected java.lang.String |
m_change
Component callback invoked when the dependency has changed.
|
protected ComponentContext |
m_component
The Component implementation is exposed to Dependencies through this interface.
|
protected boolean |
m_instanceBound
Is this Dependency "instance bound" ? A dependency is "instance bound" if it is defined within the component's
init method, meaning that it won't deactivate the component if it is not currently available when being added
from the component's init method.
|
protected boolean |
m_isStarted
Has this Dependency been started by the Component implementation ? Volatile because the getState method
(part of the
ComponentDependencyDeclaration interface) may be called by any thread, at any time. |
protected boolean |
m_propagate
Tells if the dependency service properties have to be propagated to the Component service properties.
|
protected java.lang.Object |
m_propagateCallbackInstance
The propagate callback instance that is invoked in order to supply dynamically some dependency service properties.
|
protected java.lang.String |
m_propagateCallbackMethod
The propagate callback method that is invoked in order to supply dynamically some dependency service properties.
|
protected boolean |
m_propagateOverrides
Tells if the dependency service properties should override default component service properties (false by default).
|
protected java.lang.String |
m_remove
Component callback invoked when the dependency becomes unavailable.
|
protected boolean |
m_required
Is this dependency required (false by default) ?
|
STATE_AVAILABLE_OPTIONAL, STATE_AVAILABLE_REQUIRED, STATE_NAMES, STATE_OPTIONAL, STATE_REQUIRED, STATE_UNAVAILABLE_OPTIONAL, STATE_UNAVAILABLE_REQUIRED
Constructor and Description |
---|
AbstractDependency()
Creates a new Dependency.
|
AbstractDependency(AbstractDependency<T> prototype)
Create a clone of a given Dependency.
|
Modifier and Type | Method and Description |
---|---|
void |
copyToCollection(java.util.Collection<java.lang.Object> services)
Copy all dependency service instances to the given collection.
|
void |
copyToMap(java.util.Map<java.lang.Object,java.util.Dictionary<?,?>> map)
Copy all dependency service instances to the given map (key = dependency service, value = dependency service properties.
|
abstract DependencyContext |
createCopy()
Creates a copy of this Dependency.
|
protected void |
ensureNotActive()
Checks if the component dependency is not started.
|
java.lang.String |
getAutoConfigName()
Returns the field name when the dependency can be injected to.
|
abstract java.lang.Class<?> |
getAutoConfigType()
Returns the type of the field where this dependency can be injected (auto config), or return null
if autoconfig is not supported.
|
ComponentContext |
getComponentContext()
Returns the component implementation context
|
protected java.lang.Object |
getDefaultService(boolean nullObject)
Returns the default service, or null.
|
java.lang.String |
getFilter()
Returns the dependency filter, if any.
|
java.lang.Object[] |
getInstances()
Returns the dependency callback instances
|
java.lang.String |
getName()
Returns a description of this dependency (like the dependency service class name with associated filters)
|
<K,V> java.util.Dictionary<K,V> |
getProperties()
Returns the dependency service properties (empty by default).
|
Event |
getService()
Get the highest ranked available dependency service, or null.
|
abstract java.lang.String |
getSimpleName()
Returns a simple name for this dependency (like the dependency service class name).
|
int |
getState()
Returns this dependency state.
|
abstract java.lang.String |
getType()
Returns the dependency symbolic type.
|
void |
invokeCallback(EventType type,
Event... events)
A Component callback must be invoked with dependency event(s).
|
boolean |
isAutoConfig()
Can this dependency be injected in a component class field (by reflexion, true by default) ?
|
boolean |
isAvailable()
Is this Dependency satisfied and available ?
|
boolean |
isInstanceBound()
Is this Dependency "instance bound" (has been defined within the component's init method) ?
|
boolean |
isPropagated()
Returns the propagate callback method that is invoked in order to supply dynamically some dependency service properties.
|
boolean |
isRequired()
Is this Dependency required (false by default) ?
|
boolean |
isStarted()
Indicates if this dependency has been started by the Component implementation.
|
boolean |
needsInstance()
Tells if the Component must be first instantiated before starting this dependency (false by default).
|
boolean |
overrideServiceProperties()
Determines if the propagated dependency properties must override the component service properties.
|
T |
setAutoConfig(boolean autoConfig) |
T |
setAutoConfig(java.lang.String instanceName) |
void |
setAvailable(boolean available)
Called by the Component implementation when the dependency is considered to be available.
|
T |
setCallbacks(java.lang.Object instance,
java.lang.String add,
java.lang.String remove)
Sets the callbacks for this service.
|
T |
setCallbacks(java.lang.Object instance,
java.lang.String add,
java.lang.String change,
java.lang.String remove)
Sets the callbacks for this service.
|
T |
setCallbacks(java.lang.String add,
java.lang.String remove)
Sets the add/remove callbacks.
|
T |
setCallbacks(java.lang.String add,
java.lang.String change,
java.lang.String remove)
Sets the add/change/remove callbacks.
|
void |
setComponentContext(ComponentContext component)
Called by the Component implementation before the Dependency can be started.
|
void |
setInstanceBound(boolean instanceBound)
Called by the Component implementation when the dependency is declared within the Component's init method.
|
T |
setPropagate(boolean propagate)
Activates Dependency service properties propagation (to the service properties of the component to which this
dependency is added).
|
T |
setPropagate(boolean propagate,
boolean overrideServiceProperties) |
T |
setPropagate(java.lang.Object instance,
java.lang.String method)
Sets a callback instance which can ba invoked with the given method in order to dynamically retrieve the
dependency service properties.
|
T |
setRequired(boolean required) |
void |
start()
Starts this dependency.
|
void |
stop()
Starts this dependency.
|
java.lang.String |
toString() |
protected ComponentContext m_component
protected volatile boolean m_available
ComponentDependencyDeclaration
interface) may be called by any thread, at any time.protected boolean m_instanceBound
protected volatile boolean m_required
protected volatile java.lang.String m_add
protected volatile java.lang.String m_change
protected volatile java.lang.String m_remove
protected volatile boolean m_autoConfig
protected volatile java.lang.String m_autoConfigInstance
protected volatile boolean m_autoConfigInvoked
protected volatile boolean m_isStarted
ComponentDependencyDeclaration
interface) may be called by any thread, at any time.protected volatile java.lang.Object m_callbackInstance
protected volatile boolean m_propagate
protected volatile boolean m_propagateOverrides
protected volatile java.lang.Object m_propagateCallbackInstance
protected volatile java.lang.String m_propagateCallbackMethod
#m_propagateCallbackInstance}
protected static final java.util.Dictionary<java.lang.Object,java.lang.Object> EMPTY_PROPERTIES
public AbstractDependency()
public AbstractDependency(AbstractDependency<T> prototype)
prototype
- all the fields of the prototype will be copied to this dependency.public java.lang.String toString()
toString
in class java.lang.Object
public boolean isRequired()
isRequired
in interface Dependency
true
if the dependency is requiredpublic boolean isAvailable()
isAvailable
in interface Dependency
true
if the dependency is availablepublic boolean isAutoConfig()
isAutoConfig
in interface Dependency
public java.lang.String getAutoConfigName()
getAutoConfigName
in interface Dependency
public boolean isPropagated()
isPropagated
in interface Dependency
true
if the properties should be propagated#m_propagateCallbackInstance}
public boolean overrideServiceProperties()
Dependency
overrideServiceProperties
in interface Dependency
public <K,V> java.util.Dictionary<K,V> getProperties()
getProperties
in interface Dependency
Dependency.isPropagated()
public void setComponentContext(ComponentContext component)
setComponentContext
in interface DependencyContext
component
- the Component implementation contextpublic void invokeCallback(EventType type, Event... events)
invokeCallback
in interface DependencyContext
type
- the dependency event typeevents
- the dependency service event to inject in the component.
The number of events depends on the dependency event type: ADDED/CHANGED/REMOVED types only has one event parameter,
but the SWAPPED type has two event parameters: the first one is the old event which must be replaced by the second one.ComponentContext.handleEvent(DependencyContext, EventType, Event...)
,
EventType
public void start()
start
in interface DependencyContext
public void stop()
stop
in interface DependencyContext
public boolean isStarted()
isStarted
in interface DependencyContext
public void setAvailable(boolean available)
setAvailable
in interface DependencyContext
available
- true to mark this dependency as available, false to mark it as unavailablepublic boolean isInstanceBound()
isInstanceBound
in interface DependencyContext
public void setInstanceBound(boolean instanceBound)
setInstanceBound
in interface DependencyContext
public boolean needsInstance()
needsInstance
in interface DependencyContext
public abstract java.lang.Class<?> getAutoConfigType()
getAutoConfigType
in interface DependencyContext
public Event getService()
getService
in interface DependencyContext
public void copyToCollection(java.util.Collection<java.lang.Object> services)
copyToCollection
in interface DependencyContext
services
- the collection where the dependency service instances will be copiedpublic void copyToMap(java.util.Map<java.lang.Object,java.util.Dictionary<?,?>> map)
copyToMap
in interface DependencyContext
map
- the map where the dependency service instances (with the corresponding service properties)public abstract DependencyContext createCopy()
createCopy
in interface DependencyContext
public java.lang.String getName()
getName
in interface ComponentDependencyDeclaration
public abstract java.lang.String getSimpleName()
getSimpleName
in interface ComponentDependencyDeclaration
public abstract java.lang.String getType()
getType
in interface ComponentDependencyDeclaration
public java.lang.String getFilter()
getFilter
in interface ComponentDependencyDeclaration
public int getState()
getState
in interface ComponentDependencyDeclaration
public T setPropagate(boolean propagate)
propagate
- true if the dependency service properties must be propagated to the service properties of
the component to which this dependency is added.public T setPropagate(boolean propagate, boolean overrideServiceProperties)
public T setPropagate(java.lang.Object instance, java.lang.String method)
instance
- the callback instancemethod
- the method to invoke on the callback instancepublic T setCallbacks(java.lang.String add, java.lang.String remove)
add
- the callback to invoke when a dependency is addedremove
- the callback to invoke when a dependency is removedpublic T setCallbacks(java.lang.String add, java.lang.String change, java.lang.String remove)
add
- the callback to invoke when a dependency is addedchange
- the callback to invoke when a dependency has changedremove
- the callback to invoke when a dependency is removedpublic T setCallbacks(java.lang.Object instance, java.lang.String add, java.lang.String remove)
instance
- the instance to call the callbacks onadd
- the method to call when a service was addedremove
- the method to call when a service was removedpublic T setCallbacks(java.lang.Object instance, java.lang.String add, java.lang.String change, java.lang.String remove)
instance
- the instance to call the callbacks onadd
- the method to call when a service was addedchange
- the method to call when a service was changedremove
- the method to call when a service was removedpublic java.lang.Object[] getInstances()
public T setRequired(boolean required)
ServiceDependency#setRequired(boolean)}
public T setAutoConfig(boolean autoConfig)
ServiceDependency#setAutoConfig(boolean)}
public T setAutoConfig(java.lang.String instanceName)
ServiceDependency#setAutoConfig(String instanceName)}
public ComponentContext getComponentContext()
getComponentContext
in interface DependencyContext
protected java.lang.Object getDefaultService(boolean nullObject)
nullObject
- if true, a null object may be returned.protected void ensureNotActive()