The temporal dependency handler
Regular service dependencies participate to the instance lifecycle. Moreover, the injected service object is either available or not available. A temporal dependency handler is a little different and provides a different resolution pattern. Indeed, the temporal dependency does not invalidate the instance. Moreover, if not available, the temporal dependency waits (and so blocks the current thread) for a provider. Of course, the maximum waiting time can be specified. If a timeout occurs, the handler throws a runtime exception.
Using the handler
First of all, you need to configure the component type to use the handler such as:
<iPOJO xmlns:temporal="org.apache.felix.ipojo.handler.temporal"> <component className="org.apache.felix.ipojo.example.Temporal"> <!-—Temporal dependency configuration --> <temporal:requires field="mytemporal" /> <provides /> </component> </iPOJO>
Notice that, this handler is an external handler. So, it uses the "org.apache.felix.ipojo.handler.temporal" namespace.
Once described, you can implement your component. The specified field will be mapped to the temporal dependency. As for regular field injection, aggregation, targeted service specification (i.e. interface) are discovered automatically. Filter, comparator and binding policy are also supported. However, the optional attribute is not supported. In fact, this attribute is meaningless in the case of a temporal dependency.
Using the field in your code will try to find a matching service provider. If a provider is available, the field receives the service object immediately. Else, the thread is stopped and waits for a provider. The default wait time is 3s (you can also specify this time). If no provider is available after this time, the thread throws a RuntimeException. If a provider becomes available during this time, the field receives immediately the value and the execution can continue.
Configuration
The handler has only one mandatory attributes:
- Field: the implementation field supporting the dependency
The handler supports on specific optional attributes:
- Timeout: the maximum time waited in order to find a provider (default: 3s)
The attribute form regular dependencies are also supported.
Download
The handler is available on the download page.
Sources are available on the Felix trunk at the following location: https://svn.apache.org/repos/asf/felix/trunk/ipojo/temporal.dependency.handler
Overview
Getting Started
- iPOJO in 10 minutes
- How to use iPOJO Annotations
- iPOJO Hello Word (Maven-Based) tutorial
- iPOJO Advanced Tutorial
- iPOJO Composition Tutorial
User Guide
- Describing components (handler list)
- Using XML Schemas
- Describing components with the iPOJO-API
- Testing components
- Advanced Topics
- Eclipse Integration
- FAQ
- iPOJO Reference Card
Tools
- iPOJO Eclipse Plug-in
- iPOJO Ant Task
- iPOJO Maven Plug-in
- Online-Manipulator
- iPOJO Arch Command
- iPOJO Webconsole plugin
- Junit4OSGi
Developer Guide
- Javadoc: 1.2
- How to write your own handler
- How to use iPOJO Manipulation Metadata
- Dive into the iPOJO Manipulation depths
Misc & Contact
- Issues Tracker
- Supported JVMs
- Supported OSGi Implementations
- iPOJO's Dark Side Blog
- Future Ideas
- Article & Presentations
Experimentation