felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pde...@apache.org
Subject svn commit: r987874 - /felix/trunk/dependencymanager/annotation/src/main/java/org/apache/felix/dm/annotation/api/LifecycleController.java
Date Sun, 22 Aug 2010 11:45:21 GMT
Author: pderop
Date: Sun Aug 22 11:45:21 2010
New Revision: 987874

URL: http://svn.apache.org/viewvc?rev=987874&view=rev
Log:
forgot to add this file in the previous commit

Added:
    felix/trunk/dependencymanager/annotation/src/main/java/org/apache/felix/dm/annotation/api/LifecycleController.java

Added: felix/trunk/dependencymanager/annotation/src/main/java/org/apache/felix/dm/annotation/api/LifecycleController.java
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/annotation/src/main/java/org/apache/felix/dm/annotation/api/LifecycleController.java?rev=987874&view=auto
==============================================================================
--- felix/trunk/dependencymanager/annotation/src/main/java/org/apache/felix/dm/annotation/api/LifecycleController.java
(added)
+++ felix/trunk/dependencymanager/annotation/src/main/java/org/apache/felix/dm/annotation/api/LifecycleController.java
Sun Aug 22 11:45:21 2010
@@ -0,0 +1,76 @@
+package org.apache.felix.dm.annotation.api;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/**
+ * Injects a <code>Runnable</code> object in a Service for starting/stopping
it programatically.
+ * By default, a Service is implicitly started when the service's bundle is started and when

+ * all required dependencies are satisfied. However, it is sometimes required to programatically

+ * take control of when the service started or stopped. In this case, the injected <code>Runnable</code>

+ * can be invoked in order to start (and eventually register) a Service at any time. When
this annotation 
+ * is used, then the Service on which this annotation is applied is not provided once the
Service is ready, 
+ * as it is the case by default and you have to call the injected Runnable yourself. 
+ * <p>
+ * <h3>Usage Examples</h3>
+ * <blockquote>
+ * 
+ * <pre>
+ * &#47;**
+ *   * This Service will be registered programatically into the OSGi registry, using the
publisher attribute.
+ *   *&#47;
+ * &#64;Service
+ * class X implements Z {
+ *     &#64;LifecycleController
+ *     Runnable m_starter
+ *   
+ *     &#64;Init
+ *     void init() {
+ *         // Our component won't be started by default once the bundle is started and when
all
+ *         // required dependencies are injected. Our Component will be registered only when
we
+ *         // decide to invoke the Runnable injected by the LifecycleController annotation.
+ *     }
+ *   
+ *     public void registerServiceWheneverIWant() {
+ *         m_starter.run(); // start our component.
+ *     }
+ *     
+ *     public void start() {
+ *         // This method will be called after we invoke our m_starter Runnable.
+ *     }
+ * }
+ * </pre>
+ * </blockquote> 
+ */ 
+@Retention(RetentionPolicy.CLASS)
+@Target(ElementType.FIELD)
+public @interface LifecycleController
+{
+    /**
+     * Specify the action to be performed when the Injected runnable is invoked. By default,
the
+     * Runnable will fire a Service Component activation, when invoked. If you specify this
attribute
+     * to false, then the Service Component will be stopped, when the runnable is invoked.
+     */
+    public boolean start() default true;
+}



Mime
View raw message