Java Reference
In-Depth Information
must be present when used by the component. How does i POJO ensure this? It blocks
the calling thread if a matching service isn't available.
Declaring a temporal dependency is similar to a normal service dependency. Con-
sider a temporal dependency for a log service:
@Requires
private LogService m_log;
Although the name is the same, this isn't the same @Requires annotation. The origi-
nal annotation is org.apache.felix.ipojo.annotations.Requires ; this annotation
is org.apache.felix.ipojo.handler.temporal.Requires . By using it, whenever a
thread accesses m_log , it either gets a log service or blocks until one is available. You
can use the timeout annotation attribute to specify a timeout value, which when
expired results in a service exception. If you'd rather not receive an exception, you
can use the onTimeout annotation attribute to indicate that you'd rather receive a
null value, a null object, or a default implementation.
Damping, anyone?
The behavior of iPOJO's temporal dependencies is similar to the damping concept
used by Blueprint. Technically, if you used temporal dependencies liberally, you'd end
up with a similar effect of having all your dependencies damped. Although this is pos-
sible, it isn't the intended use case for temporal dependencies, and we advise
against it. Generally speaking, most service dependencies are either mandatory or
optional. Temporal dependencies are for specific situations as described. The use of
damped dependencies may result in systems that exhibit odd behavior when faced
with service dynamism.
LIFECYCLE CALLBACK METHODS
i POJO defines two method-level annotations for declaring lifecycle callback methods
in components: @Validate and @Invalidate . The @Validate annotation is applied to
component methods to be called when all mandatory service dependencies are
satisfied. For example, the paint frame component uses this mechanism to make its
frame visible:
@Validate
protected void activate() {
SwingUtils.invokeAndWait(new Runnable() {
public void run() {
setVisible(true);
}
});
}
The @Invalidate annotation is applied to component methods to be called when any
of the mandatory service references become unsatisfied and i POJO is going to release
the component instance. The paint frame component likewise uses this mechanism to
close and dispose of its frame:
 
Search WWH ::




Custom Search