felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pde...@apache.org
Subject svn commit: r947788 - in /felix/trunk/dependencymanager: annotation/src/main/java/org/apache/felix/dm/annotation/api/dependency/ annotation/src/main/java/org/apache/felix/dm/annotation/plugin/bnd/ runtime/src/main/java/org/apache/felix/dm/runtime/ test...
Date Mon, 24 May 2010 20:22:30 GMT
Author: pderop
Date: Mon May 24 20:22:29 2010
New Revision: 947788

URL: http://svn.apache.org/viewvc?rev=947788&view=rev
Log:
Removed TemporalServiceDependency, but added a timeout attribute in the ServiceDependency
annotation

Removed:
    felix/trunk/dependencymanager/annotation/src/main/java/org/apache/felix/dm/annotation/api/dependency/TemporalServiceDependency.java
Modified:
    felix/trunk/dependencymanager/annotation/src/main/java/org/apache/felix/dm/annotation/api/dependency/ServiceDependency.java
    felix/trunk/dependencymanager/annotation/src/main/java/org/apache/felix/dm/annotation/plugin/bnd/AnnotationCollector.java
    felix/trunk/dependencymanager/annotation/src/main/java/org/apache/felix/dm/annotation/plugin/bnd/EntryType.java
    felix/trunk/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/DependencyBuilder.java
    felix/trunk/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/JSONMetaData.java
    felix/trunk/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/MetaData.java
    felix/trunk/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/temporal/TemporalTest.java

Modified: felix/trunk/dependencymanager/annotation/src/main/java/org/apache/felix/dm/annotation/api/dependency/ServiceDependency.java
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/annotation/src/main/java/org/apache/felix/dm/annotation/api/dependency/ServiceDependency.java?rev=947788&r1=947787&r2=947788&view=diff
==============================================================================
--- felix/trunk/dependencymanager/annotation/src/main/java/org/apache/felix/dm/annotation/api/dependency/ServiceDependency.java
(original)
+++ felix/trunk/dependencymanager/annotation/src/main/java/org/apache/felix/dm/annotation/api/dependency/ServiceDependency.java
Mon May 24 20:22:29 2010
@@ -66,4 +66,42 @@ public @interface ServiceDependency
      * The callback method to invoke when the service is lost.
      */
     String removed() default "";
+    
+    /** 
+     * The max time in millis to wait for the dependency availability. 
+     * Specifying a positive number allow to block the caller thread between service updates.
Only
+     * useful for required stateless dependencies that can be replaced transparently.
+     * A Dynamic Proxy is used to wrap the actual service dependency (which must be an interface).

+     * When the dependency goes away, an attempt is made to replace it with another one which
satisfies 
+     * the service dependency criteria. If no service replacement is available, then any
method invocation 
+     * (through the dynamic proxy) will block during a configurable timeout. On timeout,
an unchecked 
+     * <code>IllegalStateException</code> exception is raised (but the service
is not deactivated).<p>
+     * Notice that the changed/removed callbacks are not used when the timeout parameter
is > -1.
+     * <p> 
+     * 
+     * -1 means no timeout at all (default). 0 means that invocation on a missing service
will fail 
+     * immediately. A positive number represents the max timeout in millisends to wait for
the service availability.
+     * 
+     * <p> Sample Code:<p>
+     * <blockquote><pre>
+     * &#64;Service
+     * class MyServer implements Runnable {
+     *   &#64;ServiceDependency(timeout=15000)
+     *   MyDependency _dependency;.
+     *   
+     *   &#64;Start
+     *   void start() {
+     *     (new Thread(this)).start();
+     *   }
+     *   
+     *   public void run() {
+     *     try {
+     *       _dependency.doWork();
+     *     } catch (IllegalStateException e) {
+     *       t.printStackTrace();
+     *     }
+     *   }   
+     * </pre></blockquote>
+     */
+    long timeout() default -1;
 }

Modified: felix/trunk/dependencymanager/annotation/src/main/java/org/apache/felix/dm/annotation/plugin/bnd/AnnotationCollector.java
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/annotation/src/main/java/org/apache/felix/dm/annotation/plugin/bnd/AnnotationCollector.java?rev=947788&r1=947787&r2=947788&view=diff
==============================================================================
--- felix/trunk/dependencymanager/annotation/src/main/java/org/apache/felix/dm/annotation/plugin/bnd/AnnotationCollector.java
(original)
+++ felix/trunk/dependencymanager/annotation/src/main/java/org/apache/felix/dm/annotation/plugin/bnd/AnnotationCollector.java
Mon May 24 20:22:29 2010
@@ -42,7 +42,6 @@ import org.apache.felix.dm.annotation.ap
 import org.apache.felix.dm.annotation.api.dependency.ConfigurationDependency;
 import org.apache.felix.dm.annotation.api.dependency.ResourceDependency;
 import org.apache.felix.dm.annotation.api.dependency.ServiceDependency;
-import org.apache.felix.dm.annotation.api.dependency.TemporalServiceDependency;
 import org.osgi.framework.Bundle;
 
 import aQute.lib.osgi.Annotation;
@@ -68,8 +67,6 @@ public class AnnotationCollector extends
         + ServiceDependency.class.getName().replace('.', '/') + ";";
     private final static String A_CONFIGURATION_DEPENDENCY = "L"
         + ConfigurationDependency.class.getName().replace('.', '/') + ";";
-    private final static String A_TEMPORAL_SERVICE_DEPENDENCY = "L"
-        + TemporalServiceDependency.class.getName().replace('.', '/') + ";";
     private final static String A_BUNDLE_DEPENDENCY = "L"
         + BundleDependency.class.getName().replace('.', '/') + ";";
     private final static String A_RESOURCE_DEPENDENCY = "L"
@@ -239,16 +236,12 @@ public class AnnotationCollector extends
         }
         else if (annotation.getName().equals(A_SERVICE_DEP))
         {
-            parseServiceDependencyAnnotation(annotation, false);
+            parseServiceDependencyAnnotation(annotation);
         }
         else if (annotation.getName().equals(A_CONFIGURATION_DEPENDENCY))
         {
             parseConfigurationDependencyAnnotation(annotation);
         }
-        else if (annotation.getName().equals(A_TEMPORAL_SERVICE_DEPENDENCY))
-        {
-            parseServiceDependencyAnnotation(annotation, true);
-        }
         else if (annotation.getName().equals(A_BUNDLE_DEPENDENCY))
         {
             parseBundleDependencyAnnotation(annotation);
@@ -317,13 +310,12 @@ public class AnnotationCollector extends
     }
 
     /**
-     * Parses a ServiceDependency or a TemporalServiceDependency Annotation.
+     * Parses a ServiceDependency Annotation.
      * @param annotation the ServiceDependency Annotation.
      */
-    private void parseServiceDependencyAnnotation(Annotation annotation, boolean temporal)
+    private void parseServiceDependencyAnnotation(Annotation annotation)
     {
-        EntryWriter writer = new EntryWriter(temporal ? EntryType.TemporalServiceDependency
-            : EntryType.ServiceDependency);
+        EntryWriter writer = new EntryWriter(EntryType.ServiceDependency);
         m_writers.add(writer);
 
         // service attribute
@@ -365,22 +357,22 @@ public class AnnotationCollector extends
         // added callback
         writer.putString(annotation, EntryParam.added, (!m_isField) ? m_method : null);
 
-        if (temporal)
+        // timeout parameter
+        writer.putString(annotation, EntryParam.timeout, null);
+        Long t = (Long) annotation.get(EntryParam.timeout.toString());
+        if (t != null && t.longValue() < -1)
         {
-            // timeout attribute (only valid if parsing a temporal service dependency)
-            writer.putString(annotation, EntryParam.timeout, null);
+            throw new IllegalArgumentException("Invalid timeout value " + t + " in ServiceDependency
annotation in class " + m_className);
         }
-        else
-        {
-            // required attribute (not valid if parsing a temporal service dependency)
-            writer.putString(annotation, EntryParam.required, null);
+        
+        // required attribute (not valid if parsing a temporal service dependency)
+        writer.putString(annotation, EntryParam.required, null);
 
-            // changed callback
-            writer.putString(annotation, EntryParam.changed, null);
+        // changed callback
+        writer.putString(annotation, EntryParam.changed, null);
 
-            // removed callback
-            writer.putString(annotation, EntryParam.removed, null);
-        }
+        // removed callback
+        writer.putString(annotation, EntryParam.removed, null);       
     }
 
     /**

Modified: felix/trunk/dependencymanager/annotation/src/main/java/org/apache/felix/dm/annotation/plugin/bnd/EntryType.java
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/annotation/src/main/java/org/apache/felix/dm/annotation/plugin/bnd/EntryType.java?rev=947788&r1=947787&r2=947788&view=diff
==============================================================================
--- felix/trunk/dependencymanager/annotation/src/main/java/org/apache/felix/dm/annotation/plugin/bnd/EntryType.java
(original)
+++ felix/trunk/dependencymanager/annotation/src/main/java/org/apache/felix/dm/annotation/plugin/bnd/EntryType.java
Mon May 24 20:22:29 2010
@@ -12,7 +12,6 @@ public enum EntryType
     ResourceAdapterService,
     FactoryConfigurationAdapterService,
     ServiceDependency, 
-    TemporalServiceDependency, 
     ConfigurationDependency,
     BundleDependency,
     ResourceDependency,

Modified: felix/trunk/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/DependencyBuilder.java
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/DependencyBuilder.java?rev=947788&r1=947787&r2=947788&view=diff
==============================================================================
--- felix/trunk/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/DependencyBuilder.java
(original)
+++ felix/trunk/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/DependencyBuilder.java
Mon May 24 20:22:29 2010
@@ -72,11 +72,7 @@ public class DependencyBuilder
         switch (type)
         {
             case ServiceDependency:
-                dp = createServiceDependency(b, dm, false, instanceBound);
-                break;
-
-            case TemporalServiceDependency:
-                dp = createServiceDependency(b, dm, true, instanceBound);
+                dp = createServiceDependency(b, dm, instanceBound);
                 break;
 
             case ConfigurationDependency:
@@ -94,8 +90,7 @@ public class DependencyBuilder
         return dp;
     }
 
-    private Dependency createServiceDependency(Bundle b, DependencyManager dm, boolean temporal,
-        boolean instanceBound)
+    private Dependency createServiceDependency(Bundle b, DependencyManager dm, boolean instanceBound)
         throws ClassNotFoundException
     {
         String service = m_metaData.getString(Params.service);
@@ -105,24 +100,24 @@ public class DependencyBuilder
         Class<?> defaultServiceImplClass =
             (defaultServiceImpl != null) ? b.loadClass(defaultServiceImpl) : null;
         String added = m_metaData.getString(Params.added, null);
-        String changed = temporal ? null : m_metaData.getString(Params.changed, null);
-        String removed = temporal ? null : m_metaData.getString(Params.removed, null);
+        long timeout = m_metaData.getLong(Params.timeout, -1L);
+        String changed = timeout != -1 ? null : m_metaData.getString(Params.changed, null);
+        String removed = timeout != -1 ? null : m_metaData.getString(Params.removed, null);
         String autoConfigField = m_metaData.getString(Params.autoConfig, null);
         boolean required = "true".equals(m_metaData.getString(Params.required, "true"));
-        String timeout = m_metaData.getString(Params.timeout, null);
 
-        Dependency dp = createServiceDependency(dm, temporal, serviceClass,
+        Dependency dp = createServiceDependency(dm, serviceClass,
             serviceFilter, defaultServiceImplClass, added, changed,
             removed, autoConfigField, timeout, required, instanceBound);
         return dp;
     }
 
-    private Dependency createServiceDependency(DependencyManager dm, boolean temporal,
-        Class<?> serviceClass, String serviceFilter, Class<?> defaultServiceImplClass,
String added,
-        String changed, String removed, String autoConfigField, String timeout, boolean required,
+    private Dependency createServiceDependency(DependencyManager dm, Class<?> serviceClass,

+        String serviceFilter, Class<?> defaultServiceImplClass, String added,
+        String changed, String removed, String autoConfigField, long timeout, boolean required,
         boolean instanceBound)
     {
-        ServiceDependency sd = temporal ? dm.createTemporalServiceDependency()
+        ServiceDependency sd = timeout != -1 ? dm.createTemporalServiceDependency()
             : dm.createServiceDependency();
         sd.setService(serviceClass, serviceFilter);
         if (defaultServiceImplClass != null)
@@ -134,13 +129,9 @@ public class DependencyBuilder
         {
             sd.setAutoConfig(autoConfigField);
         }
-        if (temporal)
+        if (timeout != -1)
         {
-            // Set the timeout value for a temporal service dependency
-            if (timeout != null)
-            {
-                ((TemporalServiceDependency) sd).setTimeout(Long.parseLong(timeout));
-            }
+            ((TemporalServiceDependency) sd).setTimeout(timeout);
             // Set required flag (always true for a temporal dependency)
             sd.setRequired(true);
         }

Modified: felix/trunk/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/JSONMetaData.java
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/JSONMetaData.java?rev=947788&r1=947787&r2=947788&view=diff
==============================================================================
--- felix/trunk/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/JSONMetaData.java
(original)
+++ felix/trunk/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/JSONMetaData.java
Mon May 24 20:22:29 2010
@@ -171,6 +171,51 @@ public class JSONMetaData implements Met
         }
     }
 
+    public long getLong(Params key)
+    {
+        String value = getString(key, null);
+        if (value != null)
+        {
+            try
+            {
+                return Long.parseLong(value);
+            }
+            catch (NumberFormatException e)
+            {
+                throw new IllegalArgumentException("parameter " + key
+                    + " is not a long value: "
+                    + value);
+            }
+        }
+        else
+        {
+            throw new IllegalArgumentException("missing " + key
+                + " parameter from annotation");
+        }
+    }
+
+    public long getLong(Params key, long def)
+    {
+        String value = getString(key, null);
+        if (value != null)
+        {
+            try
+            {
+                return Long.parseLong(value);
+            }
+            catch (NumberFormatException e)
+            {
+                throw new IllegalArgumentException("parameter " + key
+                    + " is not a long value: "
+                    + value);
+            }
+        }
+        else
+        {
+            return def;
+        }
+    }
+
     public String[] getStrings(Params key)
     {
         Object array = m_metadata.get(key.toString());

Modified: felix/trunk/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/MetaData.java
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/MetaData.java?rev=947788&r1=947787&r2=947788&view=diff
==============================================================================
--- felix/trunk/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/MetaData.java
(original)
+++ felix/trunk/dependencymanager/runtime/src/main/java/org/apache/felix/dm/runtime/MetaData.java
Mon May 24 20:22:29 2010
@@ -44,6 +44,16 @@ public interface MetaData extends Clonea
      * Returns a String descriptor entry parameter value.
      */
     int getInt(Params key, int def);
+    
+    /**
+     * Returns a String descriptor entry parameter value.
+     */
+    long getLong(Params key);
+
+    /**
+     * Returns a String descriptor entry parameter value.
+     */
+    long getLong(Params key, long def);
 
     /**
      * Returns a String array descriptor entry parameter value.

Modified: felix/trunk/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/temporal/TemporalTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/temporal/TemporalTest.java?rev=947788&r1=947787&r2=947788&view=diff
==============================================================================
--- felix/trunk/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/temporal/TemporalTest.java
(original)
+++ felix/trunk/dependencymanager/test/src/main/java/org/apache/felix/dm/test/bundle/annotation/temporal/TemporalTest.java
Mon May 24 20:22:29 2010
@@ -22,7 +22,6 @@ import org.apache.felix.dm.annotation.ap
 import org.apache.felix.dm.annotation.api.Start;
 import org.apache.felix.dm.annotation.api.Stop;
 import org.apache.felix.dm.annotation.api.dependency.ServiceDependency;
-import org.apache.felix.dm.annotation.api.dependency.TemporalServiceDependency;
 import org.apache.felix.dm.test.bundle.annotation.sequencer.Sequencer;
 
 /**
@@ -36,7 +35,7 @@ public class TemporalTest implements Run
     @ServiceDependency
     Sequencer m_sequencer;
 
-    @TemporalServiceDependency(timeout = 1000L, filter = "(test=temporal)")
+    @ServiceDependency(timeout = 1000L, filter = "(test=temporal)")
     Runnable m_service;
 
     @Start



Mime
View raw message