public abstract class Component
extends java.lang.Object
Component
is a component in the sense of Inversion of Control (IoC).
Its primary responsibility is to govern the life-cycle of a modular component. It can be started and it can be stopped.
The order in which Component
s are started and stopped, is the responsibility of the ComponentLoader
s that loads them.
This class is not thread-safe.
Modifier | Constructor and Description |
---|---|
protected |
Component()
Constructs a new
Component instance. |
protected |
Component(java.lang.String name)
Constructs a new
Component instance. |
protected |
Component(java.lang.String name,
java.lang.String id)
Constructs a new
Component instance. |
Modifier and Type | Method and Description |
---|---|
protected abstract void |
doStart()
Starts this
Component instance, if not already running. |
protected abstract void |
doStop()
Stops this
Component instance, if it's currently running. |
boolean |
equals(java.lang.Object object)
Compares this
Component instance to object for equality. |
java.lang.String |
getId()
Returns the ID of this
Component instance. |
java.lang.String |
getName()
Returns the name of this
Component instance. |
int |
hashCode()
Returns a hash-code for this
Component instance. |
boolean |
isRunning()
Returns
true if, and only if, this Component instance is currently running, false otherwise. |
void |
start()
Starts this
Component instance, if not already running. |
void |
stop()
Stops this
Component instance, if it's currently running. |
protected Component()
Component
instance.
Both name and ID will be set to the fully qualified name of its Class
.
This new Component
instance will not be started automatically.
protected Component(java.lang.String name)
Component
instance.
Sets the name to name
and ID to the fully qualified name of its Class
.
If name
is null
, a NullPointerException
will be thrown.
This new Component
instance will not be started automatically.
name
- the name of this Component
instancejava.lang.NullPointerException
- thrown if, and only if, name
is null
protected Component(java.lang.String name, java.lang.String id)
Component
instance.
Sets the name to name
and ID to id
.
If either name
or id
are null
, a NullPointerException
will be thrown.
This new Component
instance will not be started automatically.
name
- the name of this Component
instanceid
- the ID of this Component
instancejava.lang.NullPointerException
- thrown if, and only if, either name
or id
are null
public final boolean equals(java.lang.Object object)
Component
instance to object
for equality.
Returns true
if, and only if, this Component
instance is equal to object
, false
otherwise.
Two Component
s are said to be equal if, and only if, both of their ID are exactly the same.
equals
in class java.lang.Object
object
- the Object
to compare this Component
instance to for equalitytrue
if, and only if, this Component
instance is equal to object
, false
otherwisepublic final boolean isRunning()
true
if, and only if, this Component
instance is currently running, false
otherwise.true
if, and only if, this Component
instance is currently running, false
otherwisepublic final int hashCode()
Component
instance.hashCode
in class java.lang.Object
Component
instancepublic final java.lang.String getId()
Component
instance.
The default ID is the fully qualified name of its Class
.
The ID of a Component
must, in contrast to its name, be unique.
Component
instancepublic final java.lang.String getName()
Component
instance.
The default name is the same as its ID.
The name of a Component
should preferably be easy to remember for any user of the modular application you're creating. Two Component
s may have the same name, although we do not encourage that. But we
do encourage a name that is internationalized.
Component
instancepublic final void start()
Component
instance, if not already running.
If this Component
was not running prior to calling this method, its doStart()
method will be called.
public final void stop()
Component
instance, if it's currently running.
If this Component
was running prior to calling this method, its doStop()
method will be called.
protected abstract void doStart()
Component
instance, if not already running.
This method will be called by the start()
method, if this Component
instance is not already running.
This method is intended to be overridden by subclasses to handle their own start logic.
protected abstract void doStop()
Component
instance, if it's currently running.
This method will be called by the stop()
method, if this Component
instance is currently running.
This method is intended to be overridden by subclasses to handle their own stop logic.