[israfil-micro commit] r75 - add docs for upcoming lifecycle.

0 views
Skip to first unread message

codesite...@google.com

unread,
Apr 24, 2009, 2:06:36 AM4/24/09
to israfil-...@googlegroups.com
Author: christianedwardgruber
Date: Thu Apr 23 23:01:32 2009
New Revision: 75

Modified:
trunk/israfil-micro-container/src/site/apt/lifecycle.apt

Log:
add docs for upcoming lifecycle.

Modified: trunk/israfil-micro-container/src/site/apt/lifecycle.apt
==============================================================================
--- trunk/israfil-micro-container/src/site/apt/lifecycle.apt (original)
+++ trunk/israfil-micro-container/src/site/apt/lifecycle.apt Thu Apr 23
23:01:32 2009
@@ -34,78 +34,17 @@
Implementors should start whatever they need to in order to be ready to
accept calls, including marshalling any resources necessary, etc.

- Care should be taken to time-out appropriately, as the container offers
- its thread to the component during this initialization, and faulty
- initialization can lock the container.
-
-Registering components with dependencies
-
- Registration of components with dependencies is a bit more complicated,
as it
- requires an adapter:
-
--------------------
-
-public void registerType(Object key, AutoWiringAdapter componentAdapter);
-
--------------------
-
- AutoWiringAdapters can be created on the fly, for instance by using an
anonymous
- inner class that implements AutoWiringAdapter or extending
AbstractAutoWiringAdapter:
-
--------------------
-
-container.registerType(ComponentThree.class,new AbstractAutoWiringAdapter(
- ComponentThree.class, new Object[] {ComponentOne.class}
- ) {
- public Object create(Object[] params) throws IllegalAccessException,
InstantiationException {
- return new ComponentThreeImpl((ComponentOne)params[0]);
- }
-});
-
--------------------
-
- Another option is to create a constant adapter on the component itself
-
--------------------
-
-public class ComponentThreeImpl implements ComponentThree {
- public static final AutoWiringAdapter adapter = new
AbstractAutoWiringAdapter(
- ComponentThree.class, new Object[] {ComponentOne.class}
- ) {
- public Object create(Object[] params) throws
IllegalAccessException, InstantiationException {
- return new ComponentThreeImpl((ComponentOne)params[0]);
- }
- });
-
- private final ComponentOne one;
-
- public ComponentThreeImpl(ComponentOne one) {
- this.one = one;
- }
-
- public void doStuff() { one.whatever(); }
-}
-
--------------------
-
- Having created this adapter constant, you can then more easily register
the
- component in the following way:
-
--------------------
-
-container.registerType(ComponentThree.class,ComponentThreeImpl.adapter);
-
--------------------
-
-Retrieving components
-
- Retrieving components is quite simple, using the getComponent method.
+ Care should be taken to indicate the likely startup time, and time-out
+ appropriately, as the container offers its thread to the component during
+ this initialization, and faulty initialization can lock the container.
+ Alternately there are register() methods that provide a timeout parameter
+ (in milliseconds) which will cause the container to launch a thread to
+ start the component, then monitor the thread until either the timeout is
+ reached, or the component is started.

-------------------

-ComponentThree three =
(ComponentThree)container.getComponent(ComponentThree.class);
-three.doStuff();
-
+container.registerType(ComponentOne.class,ComponentOneImpl.class, 10);
+
-------------------
-

Reply all
Reply to author
Forward
0 new messages