felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From clem...@apache.org
Subject svn commit: r728714 [1/2] - in /felix/trunk/ipojo: annotations/src/main/java/org/apache/felix/ipojo/handler/temporal/ handler/temporal/src/main/java/org/apache/felix/ipojo/handler/temporal/ tests/core/annotations/src/main/java/org/apache/felix/ipojo/te...
Date Mon, 22 Dec 2008 15:46:13 GMT
Author: clement
Date: Mon Dec 22 07:46:12 2008
New Revision: 728714

URL: http://svn.apache.org/viewvc?rev=728714&view=rev
Log:
Fix issue Felix-855 and Felix-860

Felix-855:
iPOJO Temporal dependencies now support Collection. So aggregate dependencies can be injected inside collections. When using a collection, the dependency description must specify the service specification thanks to the 'specification' attribute. 

Felix-860
iPOJO temporal dependencies is now able to inject proxies. So injected objects can be given to collaborators. 

Added:
    felix/trunk/ipojo/handler/temporal/src/main/java/org/apache/felix/ipojo/handler/temporal/ServiceCollection.java   (with props)
    felix/trunk/ipojo/handler/temporal/src/main/java/org/apache/felix/ipojo/handler/temporal/ServiceProxy.java   (with props)
    felix/trunk/ipojo/tests/core/annotations/src/main/java/org/apache/felix/ipojo/test/scenarios/component/temporal/TemporalCollection.java   (with props)
    felix/trunk/ipojo/tests/handler/temporal/src/main/java/org/apache/felix/ipojo/test/scenarios/component/CollectionCheckServiceProvider.java   (with props)
    felix/trunk/ipojo/tests/handler/temporal/src/main/java/org/apache/felix/ipojo/test/scenarios/component/proxy/
    felix/trunk/ipojo/tests/handler/temporal/src/main/java/org/apache/felix/ipojo/test/scenarios/component/proxy/CheckServiceProviderHelper.java   (with props)
    felix/trunk/ipojo/tests/handler/temporal/src/main/java/org/apache/felix/ipojo/test/scenarios/component/proxy/CollectionCheckServiceProviderHelper.java   (with props)
    felix/trunk/ipojo/tests/handler/temporal/src/main/java/org/apache/felix/ipojo/test/scenarios/component/proxy/HelpedCheckServiceProvider.java   (with props)
    felix/trunk/ipojo/tests/handler/temporal/src/main/java/org/apache/felix/ipojo/test/scenarios/component/proxy/HelpedCollectionCheckServiceProvider.java   (with props)
    felix/trunk/ipojo/tests/handler/temporal/src/main/java/org/apache/felix/ipojo/test/scenarios/temporal/EmptyTest.java   (with props)
Removed:
    felix/trunk/ipojo/tests/handler/temporal/src/main/java/org/apache/felix/ipojo/test/scenarios/temporal/EmptyArrayTest.java
Modified:
    felix/trunk/ipojo/annotations/src/main/java/org/apache/felix/ipojo/handler/temporal/Requires.java
    felix/trunk/ipojo/handler/temporal/src/main/java/org/apache/felix/ipojo/handler/temporal/TemporalDependency.java
    felix/trunk/ipojo/handler/temporal/src/main/java/org/apache/felix/ipojo/handler/temporal/TemporalHandler.java
    felix/trunk/ipojo/tests/core/annotations/src/main/java/org/apache/felix/ipojo/test/scenarios/annotations/TemporalDependencies.java
    felix/trunk/ipojo/tests/handler/temporal/src/main/java/org/apache/felix/ipojo/test/scenarios/temporal/DefaultImplementationTest.java
    felix/trunk/ipojo/tests/handler/temporal/src/main/java/org/apache/felix/ipojo/test/scenarios/temporal/DelayTest.java
    felix/trunk/ipojo/tests/handler/temporal/src/main/java/org/apache/felix/ipojo/test/scenarios/temporal/NoDelayTest.java
    felix/trunk/ipojo/tests/handler/temporal/src/main/java/org/apache/felix/ipojo/test/scenarios/temporal/NullTest.java
    felix/trunk/ipojo/tests/handler/temporal/src/main/java/org/apache/felix/ipojo/test/scenarios/temporal/NullableTest.java
    felix/trunk/ipojo/tests/handler/temporal/src/main/java/org/apache/felix/ipojo/test/scenarios/temporal/TemporalTestSuite.java
    felix/trunk/ipojo/tests/handler/temporal/src/main/resources/metadata.xml

Modified: felix/trunk/ipojo/annotations/src/main/java/org/apache/felix/ipojo/handler/temporal/Requires.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/annotations/src/main/java/org/apache/felix/ipojo/handler/temporal/Requires.java?rev=728714&r1=728713&r2=728714&view=diff
==============================================================================
--- felix/trunk/ipojo/annotations/src/main/java/org/apache/felix/ipojo/handler/temporal/Requires.java (original)
+++ felix/trunk/ipojo/annotations/src/main/java/org/apache/felix/ipojo/handler/temporal/Requires.java Mon Dec 22 07:46:12 2008
@@ -45,11 +45,24 @@
     
     /**
      * Set the on timeout action.
-     * Supports null, nullable, empty-array, and default-implementation.
+     * Supports null, nullable, empty, and default-implementation.
      * In this latter case, you must specify the qualified class name
      * of the default-implementation (instead of default-implementation).
-     * Default: no action (i.e throw a runtime exception)
+     * Default: no action (i.e throws a runtime exception)
      */
     String onTimeout() default "";
+    
+    /**
+     * Set the service specification (for Collection fields).
+     * This attribute is mandatory for Collections.
+     */
+    String specification() default "";
+    
+    /**
+     * Inject a proxy instead of the real object.
+     * This allows passing this reference to collaborators.
+     * Default: false
+     */
+    boolean proxy() default false;
 
 }

Added: felix/trunk/ipojo/handler/temporal/src/main/java/org/apache/felix/ipojo/handler/temporal/ServiceCollection.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/handler/temporal/src/main/java/org/apache/felix/ipojo/handler/temporal/ServiceCollection.java?rev=728714&view=auto
==============================================================================
--- felix/trunk/ipojo/handler/temporal/src/main/java/org/apache/felix/ipojo/handler/temporal/ServiceCollection.java (added)
+++ felix/trunk/ipojo/handler/temporal/src/main/java/org/apache/felix/ipojo/handler/temporal/ServiceCollection.java Mon Dec 22 07:46:12 2008
@@ -0,0 +1,334 @@
+/* 
+ * 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.
+ */
+package org.apache.felix.ipojo.handler.temporal;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+
+import org.osgi.framework.ServiceReference;
+
+/**
+* Maintains a service object collection.
+* This collection wrap the temporal dependency to be accessible from a
+* {@link Collection}, that can be passed to helper objects (Collaborators).
+* 
+* The onTimeout policies are executed when the {@link Collection#iterator()},
+* {@link Collection#toArray(Object[])} and {@link Collection#toArray()} methods
+* are called. 
+* 
+* The {@link Collection#iterator()} method returns an {@link Iterator} iterating
+* on a cached copy of available service objects. In the case that there are no 
+* available services when the timeout is reached, the policies act as follows:
+* <ul>
+* <li>'null' returns a null iterator</li>
+* <li>'nullable' and default-implementation returns an iterator iterating on one object (the
+*  nullable or default-implementation object</li>
+* <li>'empty' returns an empty iterator.</li>
+* <li>'no policy' throws runtime exception</li>
+* </ul>
+* @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+*/
+public class ServiceCollection implements Collection {
+    
+    /**
+     * The wrapped temporal dependencies.
+     */
+    private TemporalDependency m_dependency;
+        
+    /**
+     * Creates a Service Collection.
+     * @param dep the wrapped temporal dependencies
+     */
+    public ServiceCollection(TemporalDependency dep) {
+        m_dependency = dep;
+    }
+
+    /**
+     * Unsupported method.
+     * @param o an object
+     * @return N/A
+     * @see java.util.Collection#add(java.lang.Object)
+     */
+    public boolean add(Object o) {
+        throw new UnsupportedOperationException("Cannot add elements inside this collection");
+    }
+
+    /**
+     * Unsupported method.
+     * @param c an object
+     * @return N/A
+     * @see java.util.Collection#addAll(java.util.Collection)
+     */
+    public boolean addAll(Collection c) {
+        throw new UnsupportedOperationException("Cannot add elements inside this collection");
+    }
+
+    /**
+     * Unsupported method.
+     * @see java.util.Collection#clear()
+     */
+    public void clear() {
+        throw new UnsupportedOperationException("Cannot remove elements from this collection");
+    }
+
+    /**
+     * Checks if the wrapped temporal dependencies has always access to the
+     * given service object.The method allows knowing if the provider returning the
+     * service object has leaved. 
+     * @param o  the service object
+     * @return <code>true</code> if the object is still available,
+     * <code>false</code> otherwise.
+     * @see java.util.Collection#contains(java.lang.Object)
+     */
+    public boolean contains(Object o) {
+        return getAvailableObjects().contains(o);
+    }
+
+    /**
+     * Checks if the wrapped temporal dependencies has always access to the
+     * given service objects.The method allows knowing if providers returning the
+     * service objects have leaved. 
+     * @param c the set of service object
+     * @return <code>true</code> if the objects are still available,
+     * <code>false</code> otherwise.
+     * @see java.util.Collection#contains(java.lang.Object)
+     */
+    public boolean containsAll(Collection c) {
+        return getAvailableObjects().containsAll(c);
+    }
+
+    /**
+     * Checks if at least one provider matching with the dependency
+     * is available.
+     * @return <code>true</code> if one provider or more satisfying the
+     * dependency are available. Otherwise, returns <code>false</code> 
+     * @see java.util.Collection#isEmpty()
+     */
+    public boolean isEmpty() {
+        return m_dependency.getSize() == 0;
+    }
+    
+    /**
+     * Helper method creating a list of available service objects.
+     * @return the list of available service objects.
+     */
+    private List getAvailableObjects() {
+        List list = new ArrayList();
+        ServiceReference[] refs = m_dependency.getServiceReferences();
+        if (refs != null) {
+            for (int i = 0; i < refs.length; i++) {
+                list.add(m_dependency.getService(refs[i]));
+            }
+        }
+        return list;
+    }
+
+    /**
+     * Gets an iterator on the actual list of available service objects.
+     * This method applies on timeout policies is no services are 
+     * available after the timeout.
+     * The returned iterator iterates on a cached copy of the service
+     * objects.
+     * @return a iterator giving access to service objects.
+     * @see java.util.Collection#iterator()
+     */
+    public Iterator iterator() {
+        ServiceReference[] refs = m_dependency.getServiceReferences();
+        if (refs != null) {
+            // Immediate return.
+            return new ServiceIterator(refs); // Create the service iterator with the service reference list.
+        } else {
+            // Begin to wait ...
+            long enter = System.currentTimeMillis();
+            boolean exhausted = false;
+            synchronized (this) {
+                while (m_dependency.getServiceReference() == null && !exhausted) {
+                    try {
+                        wait(1);
+                    } catch (InterruptedException e) {
+                        // We was interrupted ....
+                    } finally {
+                        long end = System.currentTimeMillis();
+                        exhausted = (end - enter) > m_dependency.getTimeout();
+                    }
+                }
+            }
+            // Check
+            if (exhausted) {
+                Object oto = m_dependency.onTimeout(); // Throws the RuntimeException
+                if (oto == null) { // If null, return null
+                    return null;
+                } else {
+                    // oto is an instance of collection containing either empty or with only one element
+                    return new ServiceIterator((Collection) oto);
+                }
+            } else {
+                refs = m_dependency.getServiceReferences();
+                return new ServiceIterator(refs);                
+            }
+        }
+        
+      
+    }
+    
+    /**
+     * Unsupported method.
+     * @param o a object
+     * @return N/A
+     * @see java.util.Collection#remove(java.lang.Object)
+     */
+    public boolean remove(Object o) {
+        throw new UnsupportedOperationException("Cannot remove elements from this collection");
+    }
+
+    /**
+     * Unsupported method.
+     * @param c a set of objects
+     * @return N/A
+     * @see java.util.Collection#removeAll(java.util.Collection)
+     */
+    public boolean removeAll(Collection c) {
+        throw new UnsupportedOperationException("Cannot remove elements from this collection");
+    }
+
+    /**
+     *Unsupported method.
+     * @param c a set of objects
+     * @return N/A
+     * @see java.util.Collection#retainAll(java.util.Collection)
+     */
+    public boolean retainAll(Collection c) {
+        throw new UnsupportedOperationException("Cannot remove elements from this collection");
+    }
+
+    /**
+     * Gets the number of available providers.
+     * @return the number of matching service providers.
+     * @see java.util.Collection#size()
+     */
+    public int size() {
+        return m_dependency.getSize();
+    }
+
+    /**
+     * Returns an array containing available service objects.
+     * This method executed on timeout policies if no matching
+     * providers when the timeout is reached. 
+     * @return a array containing available service objects.
+     * depending on the timeout policy, this array can also be <code>null</code>,
+     * be empty, or can contain only one element (a default-implementation
+     * object, or a nullable object).
+     * @see java.util.Collection#toArray()
+     */
+    public Object[] toArray() {
+        return toArray(new Object[0]);
+    }
+    
+    /**
+     * Returns an array containing available service objects.
+     * This method executed on timeout policies if no matching
+     * providers when the timeout is reached. 
+     * @param a the array into which the elements of this collection 
+     * are to be stored, if it is big enough; otherwise, a new array
+     * of the same runtime type is allocated for this purpose. 
+     * @return a array containing available service objects.
+     * depending on the timeout policy, this array can also be <code>null</code>,
+     * be empty, or can contain only one element (a default-implementation
+     * object, or a nullable object).
+     * @see java.util.Collection#toArray(java.lang.Object[])
+     */
+    public Object[] toArray(Object[] a) {
+        Iterator it = iterator(); // Can throw an exception.
+        if (it == null) {
+            return null;
+        }
+        // Else we get an iterator.
+        List list = new ArrayList(size());
+        while (it.hasNext()) {
+            list.add(it.next());
+        }
+        return list.toArray(a);
+    }
+    
+    /**
+     * Iterator on a set of service objects.
+     * This iterator iterates on a cached copy of service objects.
+     */
+    private final class ServiceIterator implements Iterator {
+        
+        /**
+         * Underlying iterator.
+         */
+        private Iterator m_iterator;
+        
+        /**
+         * Creates a Service Iterator iterating
+         * on the given set of providers.
+         * @param refs the available service providers
+         */
+        private ServiceIterator(ServiceReference[] refs) {
+            List objects = new ArrayList(refs.length);
+            for (int i = 0; i < refs.length; i++) {
+                objects.add(m_dependency.getService(refs[i]));
+            }           
+            m_iterator = objects.iterator();
+        }
+        
+        /**
+         * Creates a Service Iterator iterating
+         * on service object contained in the given
+         * collection.
+         * @param col a collection containing service objects.
+         */
+        private ServiceIterator(Collection col) {
+            m_iterator = col.iterator();
+        }
+
+        /**
+         * Returns <code>true</code> if the iteration has 
+         * more service objects. 
+         * @return <code>true</code> if the iterator has more elements.
+         * @see java.util.Iterator#hasNext()
+         */
+        public boolean hasNext() {
+            return m_iterator.hasNext();
+        }
+
+        /**
+         * Returns the next service objects in the iteration. 
+         * @return the next service object in the iteration. 
+         * @see java.util.Iterator#next()
+         */
+        public Object next() {
+            return m_iterator.next();
+        }
+
+        /**
+         * Unsupported operation.
+         * @see java.util.Iterator#remove()
+         */
+        public void remove() {
+            throw new UnsupportedOperationException();            
+        }
+                  
+    }
+
+}

Propchange: felix/trunk/ipojo/handler/temporal/src/main/java/org/apache/felix/ipojo/handler/temporal/ServiceCollection.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: felix/trunk/ipojo/handler/temporal/src/main/java/org/apache/felix/ipojo/handler/temporal/ServiceProxy.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/handler/temporal/src/main/java/org/apache/felix/ipojo/handler/temporal/ServiceProxy.java?rev=728714&view=auto
==============================================================================
--- felix/trunk/ipojo/handler/temporal/src/main/java/org/apache/felix/ipojo/handler/temporal/ServiceProxy.java (added)
+++ felix/trunk/ipojo/handler/temporal/src/main/java/org/apache/felix/ipojo/handler/temporal/ServiceProxy.java Mon Dec 22 07:46:12 2008
@@ -0,0 +1,131 @@
+/* 
+ * 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.
+ */
+package org.apache.felix.ipojo.handler.temporal;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+
+import org.osgi.framework.ServiceReference;
+
+/**
+ * Wrapper in front of a temporal service dependencies.
+ * This proxy can be used by collaborators. Service lookup 
+ * and on timeout policies are executed when a method is invoked.
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+public class ServiceProxy implements InvocationHandler {
+    
+    /**
+     * The wrapped temporal dependency. 
+     */
+    private TemporalDependency m_dependency;
+    
+    /**
+     * Creates a Service Proxy.
+     * @param dep the wrapped temporal dependency
+     */
+    public ServiceProxy(TemporalDependency dep) {
+        m_dependency = dep;
+    }
+
+    /**
+     * Intercept a method invocation.
+     * This method looks for a service provider, wait for timeout and
+     * depending on the lookup result either call the method
+     * on a service object or executed the on timeout policy.
+     * In this latter case, this methods can throw a {@link RuntimeException},
+     * throws a {@link NullPointerException} (null policy) or invokes the 
+     * method on a nullable/default-implementation object.
+     * @param proxy the proxy on which the method is invoked
+     * @param method the invoked method
+     * @param args the arguments
+     * @return the invocation result.
+     * @throws Exception an exception occurs either during the invocation or 
+     * is the result to the on timeout policy.
+     * @see java.lang.reflect.InvocationHandler#invoke(java.lang.Object, java.lang.reflect.Method, java.lang.Object[])
+     */
+    public Object invoke(Object proxy, Method method, Object[] args)
+        throws Exception {
+        ServiceReference ref = m_dependency.getServiceReference();
+        if (ref != null) {
+            // Immediate return.
+            return invokeOperation(ref, method, args); // Invoke the method on the service object.
+        } else {
+            // Begin to wait ...
+            long enter = System.currentTimeMillis();
+            boolean exhausted = false;
+            synchronized (this) {
+                while (m_dependency.getServiceReference() == null && !exhausted) {
+                    try {
+                        wait(1);
+                    } catch (InterruptedException e) {
+                        // We was interrupted ....
+                    } finally {
+                        long end = System.currentTimeMillis();
+                        exhausted = (end - enter) > m_dependency.getTimeout();
+                    }
+                }
+            }
+            // Check
+            if (exhausted) {
+                Object oto = m_dependency.onTimeout(); // Throws the RuntimeException
+                if (oto == null) { // If null, return null
+                    throw new NullPointerException("No service object available"); // throws an NPE in this case.
+                } else {
+                    // invoke the method on the returned object.
+                    return invokeOperation(oto, method, args);
+                }
+            } else {
+                ref = m_dependency.getServiceReference();
+                return invokeOperation(ref, method, args); // Invoke the method on the service object.
+            }
+        }
+    }
+
+    /**
+     * Helper method invoking the given method, with the given
+     * argument on the given object.
+     * @param svc the service object
+     * @param method the method object
+     * @param args the arguments
+     * @return the invocation result
+     * @throws Exception occurs when an issue happen during method invocation.
+     */
+    private Object invokeOperation(Object svc, Method method, Object[] args) 
+        throws Exception {
+        return method.invoke(svc, args);
+    }
+    
+    /**
+     * Helper method invoking the given method, with the given
+     * argument on the given service reference. This methods gets 
+     * the service object and then invokes the method.
+     * @param ref the service reference
+     * @param method the method object
+     * @param args the arguments
+     * @return the invocation result
+     * @throws Exception occurs when an issue happen during method invocation.
+     */
+    private Object invokeOperation(ServiceReference ref, Method method, Object[] args) 
+        throws Exception {
+        Object svc = m_dependency.getService(ref);
+        return method.invoke(svc, args);
+    }
+
+}

Propchange: felix/trunk/ipojo/handler/temporal/src/main/java/org/apache/felix/ipojo/handler/temporal/ServiceProxy.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: felix/trunk/ipojo/handler/temporal/src/main/java/org/apache/felix/ipojo/handler/temporal/TemporalDependency.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/handler/temporal/src/main/java/org/apache/felix/ipojo/handler/temporal/TemporalDependency.java?rev=728714&r1=728713&r2=728714&view=diff
==============================================================================
--- felix/trunk/ipojo/handler/temporal/src/main/java/org/apache/felix/ipojo/handler/temporal/TemporalDependency.java (original)
+++ felix/trunk/ipojo/handler/temporal/src/main/java/org/apache/felix/ipojo/handler/temporal/TemporalDependency.java Mon Dec 22 07:46:12 2008
@@ -20,6 +20,9 @@
 
 import java.lang.reflect.Array;
 import java.lang.reflect.Proxy;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
 
 import org.apache.felix.ipojo.FieldInterceptor;
 import org.apache.felix.ipojo.Nullable;
@@ -67,19 +70,32 @@
      * policy (0) throw a runtime exception when the timeout occurs *
      */
     private int m_policy;
+    
+    /**
+     * The dependency is injected as a collection.
+     * The field must be of the {@link Collection} type
+     */
+    private boolean m_collection;
+    
+    /**
+     * Enables the proxy mode.
+     */
+    private boolean m_proxy;
 
     /**
-     * Constructor.
-     * @param spec service specification
+     * Creates a temporal dependency.
+     * @param spec the service specification
      * @param agg is the dependency aggregate ?
-     * @param filter LDAP filter
+     * @param collection the dependency field is a collection
+     * @param proxy enable the proxy-mode
+     * @param filter the LDAP filter
      * @param context service context
      * @param timeout timeout
      * @param handler Handler managing this dependency
      * @param defaultImpl class used as default-implementation
      * @param policy onTimeout policy
      */
-    public TemporalDependency(Class spec, boolean agg, Filter filter,
+    public TemporalDependency(Class spec, boolean agg, boolean collection, boolean proxy, Filter filter,
             BundleContext context, long timeout, int policy,
             String defaultImpl, TemporalHandler handler) {
         super(spec, agg, true, filter, null,
@@ -88,6 +104,8 @@
         m_policy = policy;
         m_timeout = timeout;
         m_handler = handler;
+        m_collection = collection;
+        m_proxy = proxy;
     }
 
     /**
@@ -138,21 +156,11 @@
         ServiceReference[] refs = getServiceReferences();
         if (refs != null) {
             // Immediate return.
-            if (isAggregate()) {
-                Object[] svc = (Object[]) Array.newInstance(getSpecification(),
-                        refs.length);
-                for (int i = 0; i < svc.length; i++) {
-                    svc[i] = getService(refs[i]);
-                }
-                return svc;
-            } else {
-                return getService(refs[0]);
-            }
+            return getServiceObjects(refs);
         } else {
             // Begin to wait ...
             long enter = System.currentTimeMillis();
             boolean exhausted = false;
-            ServiceReference ref = null;
             synchronized (this) {
                 while (getServiceReference() == null && !exhausted) {
                     try {
@@ -169,17 +177,50 @@
             if (exhausted) {
                 return onTimeout();
             } else {
-                ref = getServiceReference();
-                if (isAggregate()) {
-                    Object[] svc = (Object[]) Array.newInstance(
-                            getSpecification(), 1);
-                    svc[0] = getService(ref);
+                refs = getServiceReferences();
+                return getServiceObjects(refs);
+            }
+        }
+    }
+    
+    /**
+     * Creates and returns object to inject in the dependency.
+     * This method handles aggregate, collection and proxy cases.
+     * @param refs the available service references
+     * @return the object to inject. Can be a 'simple' object, a proxy, 
+     * a collection or an array.
+     */
+    private Object getServiceObjects(ServiceReference [] refs) {
+        if (m_proxy) {
+            if (isAggregate()) { // Necessary a collection
+                return new ServiceCollection(this);
+            } else {
+                return Proxy.newProxyInstance(m_handler
+                        .getInstanceManager().getClazz().getClassLoader(),
+                        new Class[] { getSpecification() },
+                        new ServiceProxy(this)); // NOPMD
+            }
+        } else {
+            if (isAggregate()) {
+                if (m_collection) {
+                    Collection svc = new ArrayList(refs.length);  // Use an array list as collection implementation. 
+                    for (int i = 0; i < refs.length; i++) {
+                        svc.add(getService(refs[i]));
+                    }
                     return svc;
                 } else {
-                    return getService(ref);
+                    Object[] svc = (Object[]) Array.newInstance(getSpecification(),
+                            refs.length);
+                    for (int i = 0; i < svc.length; i++) {
+                        svc[i] = getService(refs[i]);
+                    }
+                    return svc;
                 }
+            } else {
+                return getService(refs[0]);
             }
         }
+        
     }
 
     /**
@@ -202,10 +243,16 @@
                             new Class[] { getSpecification(), Nullable.class },
                             new NullableObject()); // NOPMD
                     if (isAggregate()) {
-                        Object[] array = (Object[]) Array.newInstance(
+                        if (m_collection) {
+                            List list = new ArrayList(1);
+                            list.add(m_nullableObject);
+                            m_nullableObject = list;
+                        } else {
+                            Object[] array = (Object[]) Array.newInstance(
                                 getSpecification(), 1);
-                        array[0] = m_nullableObject;
-                        m_nullableObject = array;
+                            array[0] = m_nullableObject;
+                            m_nullableObject = array;
+                        }
                     }
                 } catch (NoClassDefFoundError e) {
                     // A NoClassDefFoundError is thrown if the specification
@@ -238,14 +285,24 @@
                                     + " : " + e.getMessage());
                 }
                 if (isAggregate()) {
-                    Object[] array = (Object[]) Array.newInstance(
+                    if (m_collection) {
+                        List list = new ArrayList(1);
+                        list.add(m_nullableObject);
+                        m_nullableObject = list;
+                    } else {
+                        Object[] array = (Object[]) Array.newInstance(
                             getSpecification(), 1);
-                    array[0] = m_nullableObject;
-                    m_nullableObject = array;
+                        array[0] = m_nullableObject;
+                        m_nullableObject = array;
+                    }
                 }
                 break;
-            case TemporalHandler.EMPTY_ARRAY:
-                m_nullableObject = Array.newInstance(getSpecification(), 0);
+            case TemporalHandler.EMPTY:
+                if (! m_collection) {
+                    m_nullableObject = Array.newInstance(getSpecification(), 0);
+                } else { // Empty collection
+                    m_nullableObject = new ArrayList(0);
+                }
                 break;
             default: // Cannot occurs
                 break;
@@ -275,12 +332,12 @@
      * Implements the timeout policy according to the specified configuration.
      * @return the object to return when the timeout occurs.
      */
-    private Object onTimeout() {
+    Object onTimeout() {
         switch (m_policy) {
             case TemporalHandler.NULL:
             case TemporalHandler.NULLABLE:
             case TemporalHandler.DEFAULT_IMPLEMENTATION:
-            case TemporalHandler.EMPTY_ARRAY:
+            case TemporalHandler.EMPTY:
                 return m_nullableObject;
             default:
                 // Throws a runtime exception
@@ -289,5 +346,11 @@
                         + " unavailable : timeout");
         }
     }
+    
+    long getTimeout() {
+        return m_timeout;
+    }
+    
+    
 
 }

Modified: felix/trunk/ipojo/handler/temporal/src/main/java/org/apache/felix/ipojo/handler/temporal/TemporalHandler.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/handler/temporal/src/main/java/org/apache/felix/ipojo/handler/temporal/TemporalHandler.java?rev=728714&r1=728713&r2=728714&view=diff
==============================================================================
--- felix/trunk/ipojo/handler/temporal/src/main/java/org/apache/felix/ipojo/handler/temporal/TemporalHandler.java (original)
+++ felix/trunk/ipojo/handler/temporal/src/main/java/org/apache/felix/ipojo/handler/temporal/TemporalHandler.java Mon Dec 22 07:46:12 2008
@@ -19,6 +19,7 @@
 package org.apache.felix.ipojo.handler.temporal;
 
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.Dictionary;
 import java.util.List;
 
@@ -60,7 +61,7 @@
     /**
      * Uses an empty array.
      */
-    public static final int EMPTY_ARRAY = 3;
+    public static final int EMPTY = 3;
     /**
      * Uses {@code null}. 
      */
@@ -132,10 +133,27 @@
             }
             
             boolean agg = false;
+            boolean collection = false;
             String spec = fieldmeta.getFieldType();
             if (spec.endsWith("[]")) {
                 agg = true;
                 spec = spec.substring(0, spec.length() - 2);
+            } else if (Collection.class.getName().equals(spec)) {
+                agg = true;
+                collection = true;
+                // Collection detected. Check for the specification attribute
+                spec = deps[i].getAttribute("specification");
+                if (spec == null) {
+                    error("A dependency injected inside a Collection must contain the 'specification' attribute");
+                }
+            }
+            
+            String prox = deps[i].getAttribute("proxy");
+            boolean proxy = prox != null && prox.equals("true");
+            if (proxy && agg) {
+                if (! collection) {
+                    error("Proxied aggregate temporal dependencies cannot be an array. Only collections are supported");
+                }
             }
             
             long timeout = DEFAULT_TIMEOUT;
@@ -154,8 +172,8 @@
             if (onTimeout != null) {
                 if (onTimeout.equalsIgnoreCase("nullable")) {
                     policy = NULLABLE;
-                } else if (onTimeout.equalsIgnoreCase("empty-array")) {
-                    policy = EMPTY_ARRAY;
+                } else if (onTimeout.equalsIgnoreCase("empty-array")  || onTimeout.equalsIgnoreCase("empty")) {
+                    policy = EMPTY;
                     if (! agg) {
                         // The empty array policy can only be used on aggregate dependencies
                         error("Cannot use the empty array policy for " + field + " : non aggregate dependency.");
@@ -169,7 +187,7 @@
             }
          
             Class specification = DependencyModel.loadSpecification(spec, getInstanceManager().getContext());
-            TemporalDependency dep = new TemporalDependency(specification, agg, filter, getInstanceManager().getContext(), timeout, policy, di, this);
+            TemporalDependency dep = new TemporalDependency(specification, agg, collection, proxy, filter, getInstanceManager().getContext(), timeout, policy, di, this);
             m_dependencies.add(dep);
             
             getInstanceManager().register(fieldmeta, dep);

Modified: felix/trunk/ipojo/tests/core/annotations/src/main/java/org/apache/felix/ipojo/test/scenarios/annotations/TemporalDependencies.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/tests/core/annotations/src/main/java/org/apache/felix/ipojo/test/scenarios/annotations/TemporalDependencies.java?rev=728714&r1=728713&r2=728714&view=diff
==============================================================================
--- felix/trunk/ipojo/tests/core/annotations/src/main/java/org/apache/felix/ipojo/test/scenarios/annotations/TemporalDependencies.java (original)
+++ felix/trunk/ipojo/tests/core/annotations/src/main/java/org/apache/felix/ipojo/test/scenarios/annotations/TemporalDependencies.java Mon Dec 22 07:46:12 2008
@@ -102,5 +102,54 @@
         assertEquals("Check timeout", "100", to);
             
     }
+    
+    public void testSimpleCollection() {
+        Element meta = helper.getMetadata("org.apache.felix.ipojo.test.scenarios.component.temporal.TemporalCollection");
+        Element dep = getElementPerField(meta, "fs1");
+        String spec = dep.getAttribute("specification");
+        assertNotNull("Specification not null", spec);
+        assertEquals("Check specification", "org.apache.felix.ipojo.test.scenarios.annotations.service.FooService", spec);
+    }
+    
+    public void testCollectionWithTimeout() {
+        Element meta = helper.getMetadata("org.apache.felix.ipojo.test.scenarios.component.temporal.TemporalCollection");
+        Element dep = getElementPerField(meta, "fs2");
+        String spec = dep.getAttribute("specification");
+        assertNotNull("Specification not null", spec);
+        assertEquals("Check specification", "org.apache.felix.ipojo.test.scenarios.annotations.service.FooService", spec);
+        String to = dep.getAttribute("timeout");
+        assertEquals("Check timeout", "300", to);
+    }
+    
+    public void testCollectionWithPolicy() {
+        Element meta = helper.getMetadata("org.apache.felix.ipojo.test.scenarios.component.temporal.TemporalCollection");
+        Element dep = getElementPerField(meta, "fs3");
+        String spec = dep.getAttribute("specification");
+        assertNotNull("Specification not null", spec);
+        assertEquals("Check specification", "org.apache.felix.ipojo.test.scenarios.annotations.service.FooService", spec);
+        String to = dep.getAttribute("ontimeout");
+        assertEquals("Check policy", "empty", to);
+    }
+    
+    public void testCollectionWithProxy() {
+        Element meta = helper.getMetadata("org.apache.felix.ipojo.test.scenarios.component.temporal.TemporalCollection");
+        Element dep = getElementPerField(meta, "fs4");
+        String spec = dep.getAttribute("specification");
+        assertNotNull("Specification not null", spec);
+        assertEquals("Check specification", "org.apache.felix.ipojo.test.scenarios.annotations.service.FooService", spec);
+        String proxy = dep.getAttribute("proxy");
+        assertEquals("Check proxy", "true", proxy);
+    }
+    
+    private Element getElementPerField(Element elem, String field) {
+        Element[] provs = elem.getElements("requires", "org.apache.felix.ipojo.handler.temporal");
+        assertNotNull("Temporal exists ", provs);
+        for (int i = 0; i < provs.length; i++) {
+            if (provs[i].getAttribute("field").equals(field)) {
+                return provs[i];
+            }
+        }
+        return null;
+    }
 
 }

Added: felix/trunk/ipojo/tests/core/annotations/src/main/java/org/apache/felix/ipojo/test/scenarios/component/temporal/TemporalCollection.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/tests/core/annotations/src/main/java/org/apache/felix/ipojo/test/scenarios/component/temporal/TemporalCollection.java?rev=728714&view=auto
==============================================================================
--- felix/trunk/ipojo/tests/core/annotations/src/main/java/org/apache/felix/ipojo/test/scenarios/component/temporal/TemporalCollection.java (added)
+++ felix/trunk/ipojo/tests/core/annotations/src/main/java/org/apache/felix/ipojo/test/scenarios/component/temporal/TemporalCollection.java Mon Dec 22 07:46:12 2008
@@ -0,0 +1,25 @@
+package org.apache.felix.ipojo.test.scenarios.component.temporal;
+
+import java.util.Collection;
+
+import org.apache.felix.ipojo.annotations.Component;
+import org.apache.felix.ipojo.handler.temporal.Requires;
+
+@Component
+public class TemporalCollection {
+    
+    @Requires(specification="org.apache.felix.ipojo.test.scenarios.annotations.service.FooService")
+    private Collection fs1;
+    
+    @Requires(specification="org.apache.felix.ipojo.test.scenarios.annotations.service.FooService", timeout=300)
+    private Collection fs2;
+    
+    @Requires(onTimeout="empty", specification="org.apache.felix.ipojo.test.scenarios.annotations.service.FooService")
+    private Collection fs3;
+    
+    @Requires(proxy=true, specification="org.apache.felix.ipojo.test.scenarios.annotations.service.FooService")
+    private Collection fs4;
+    
+    
+    
+}

Propchange: felix/trunk/ipojo/tests/core/annotations/src/main/java/org/apache/felix/ipojo/test/scenarios/component/temporal/TemporalCollection.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: felix/trunk/ipojo/tests/handler/temporal/src/main/java/org/apache/felix/ipojo/test/scenarios/component/CollectionCheckServiceProvider.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/tests/handler/temporal/src/main/java/org/apache/felix/ipojo/test/scenarios/component/CollectionCheckServiceProvider.java?rev=728714&view=auto
==============================================================================
--- felix/trunk/ipojo/tests/handler/temporal/src/main/java/org/apache/felix/ipojo/test/scenarios/component/CollectionCheckServiceProvider.java (added)
+++ felix/trunk/ipojo/tests/handler/temporal/src/main/java/org/apache/felix/ipojo/test/scenarios/component/CollectionCheckServiceProvider.java Mon Dec 22 07:46:12 2008
@@ -0,0 +1,58 @@
+/* 
+ * 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.
+ */
+package org.apache.felix.ipojo.test.scenarios.component;
+
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.Properties;
+
+import org.apache.felix.ipojo.test.scenarios.temporal.service.CheckService;
+import org.apache.felix.ipojo.test.scenarios.temporal.service.FooService;
+
+public class CollectionCheckServiceProvider implements CheckService {
+    
+    /**
+     * Temporal dependency.
+     */
+    private Collection fs;
+
+    public boolean check() {
+        boolean result = true;
+        //Use a local variable to avoid to wait at each access.
+        Collection col = fs;
+        if (col  != null) {
+            Iterator it = col.iterator();
+            while (it.hasNext()) {
+                FooService svc =  (FooService) it.next();
+                result = result && svc.foo();
+            }
+        }        
+        return result;
+    }
+
+    public Properties getProps() {
+        Iterator it = fs.iterator();
+        if (it.hasNext()) {
+            FooService svc = (FooService) it.next();
+            return svc.fooProps();
+        }
+        return null;
+    }
+
+}

Propchange: felix/trunk/ipojo/tests/handler/temporal/src/main/java/org/apache/felix/ipojo/test/scenarios/component/CollectionCheckServiceProvider.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: felix/trunk/ipojo/tests/handler/temporal/src/main/java/org/apache/felix/ipojo/test/scenarios/component/proxy/CheckServiceProviderHelper.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/tests/handler/temporal/src/main/java/org/apache/felix/ipojo/test/scenarios/component/proxy/CheckServiceProviderHelper.java?rev=728714&view=auto
==============================================================================
--- felix/trunk/ipojo/tests/handler/temporal/src/main/java/org/apache/felix/ipojo/test/scenarios/component/proxy/CheckServiceProviderHelper.java (added)
+++ felix/trunk/ipojo/tests/handler/temporal/src/main/java/org/apache/felix/ipojo/test/scenarios/component/proxy/CheckServiceProviderHelper.java Mon Dec 22 07:46:12 2008
@@ -0,0 +1,57 @@
+/* 
+ * 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.
+ */
+package org.apache.felix.ipojo.test.scenarios.component.proxy;
+
+import java.util.Properties;
+
+import org.apache.felix.ipojo.test.scenarios.temporal.service.CheckService;
+import org.apache.felix.ipojo.test.scenarios.temporal.service.FooService;
+
+public class CheckServiceProviderHelper implements CheckService {
+    
+    /**
+     * injected dependency.
+     */
+    private FooService fs;
+    
+    public CheckServiceProviderHelper(FooService svc) {
+        fs = svc;
+    }
+
+    public boolean check() {
+        if (fs != null) { // Cannot be null
+            try {
+                return fs.foo();
+            } catch (NullPointerException e) {
+                // Can throw a NPE for null policy.
+                System.out.println(e.getMessage());
+                return false;
+            }
+        }
+        return false;
+    }
+
+    public Properties getProps() {
+        if (fs != null) {
+            return fs.fooProps();
+        }
+        return null;
+    }
+
+}

Propchange: felix/trunk/ipojo/tests/handler/temporal/src/main/java/org/apache/felix/ipojo/test/scenarios/component/proxy/CheckServiceProviderHelper.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: felix/trunk/ipojo/tests/handler/temporal/src/main/java/org/apache/felix/ipojo/test/scenarios/component/proxy/CheckServiceProviderHelper.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: felix/trunk/ipojo/tests/handler/temporal/src/main/java/org/apache/felix/ipojo/test/scenarios/component/proxy/CollectionCheckServiceProviderHelper.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/tests/handler/temporal/src/main/java/org/apache/felix/ipojo/test/scenarios/component/proxy/CollectionCheckServiceProviderHelper.java?rev=728714&view=auto
==============================================================================
--- felix/trunk/ipojo/tests/handler/temporal/src/main/java/org/apache/felix/ipojo/test/scenarios/component/proxy/CollectionCheckServiceProviderHelper.java (added)
+++ felix/trunk/ipojo/tests/handler/temporal/src/main/java/org/apache/felix/ipojo/test/scenarios/component/proxy/CollectionCheckServiceProviderHelper.java Mon Dec 22 07:46:12 2008
@@ -0,0 +1,62 @@
+/* 
+ * 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.
+ */
+package org.apache.felix.ipojo.test.scenarios.component.proxy;
+
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.Properties;
+
+import org.apache.felix.ipojo.test.scenarios.temporal.service.CheckService;
+import org.apache.felix.ipojo.test.scenarios.temporal.service.FooService;
+
+public class CollectionCheckServiceProviderHelper implements CheckService {
+    
+    /**
+     * Injected dependency.
+     */
+    private Collection fs;
+    
+    public CollectionCheckServiceProviderHelper(Collection col) {
+        fs = col;
+    }
+
+    public boolean check() {
+        boolean result = true;
+        //Use a local variable to avoid to wait at each access.
+        Collection col = fs;
+        if (col  != null) {
+            Iterator it = col.iterator(); // Get the cached copy
+            while (it != null && it.hasNext()) {
+                FooService svc =  (FooService) it.next();
+                result = result && svc.foo();
+            }
+        }        
+        return result;
+    }
+
+    public Properties getProps() {
+        Iterator it = fs.iterator();
+        if (it.hasNext()) {
+            FooService svc = (FooService) it.next();
+            return svc.fooProps();
+        }
+        return null;
+    }
+
+}

Propchange: felix/trunk/ipojo/tests/handler/temporal/src/main/java/org/apache/felix/ipojo/test/scenarios/component/proxy/CollectionCheckServiceProviderHelper.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: felix/trunk/ipojo/tests/handler/temporal/src/main/java/org/apache/felix/ipojo/test/scenarios/component/proxy/HelpedCheckServiceProvider.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/tests/handler/temporal/src/main/java/org/apache/felix/ipojo/test/scenarios/component/proxy/HelpedCheckServiceProvider.java?rev=728714&view=auto
==============================================================================
--- felix/trunk/ipojo/tests/handler/temporal/src/main/java/org/apache/felix/ipojo/test/scenarios/component/proxy/HelpedCheckServiceProvider.java (added)
+++ felix/trunk/ipojo/tests/handler/temporal/src/main/java/org/apache/felix/ipojo/test/scenarios/component/proxy/HelpedCheckServiceProvider.java Mon Dec 22 07:46:12 2008
@@ -0,0 +1,43 @@
+/* 
+ * 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.
+ */
+package org.apache.felix.ipojo.test.scenarios.component.proxy;
+
+import java.util.Properties;
+
+import org.apache.felix.ipojo.test.scenarios.temporal.service.CheckService;
+import org.apache.felix.ipojo.test.scenarios.temporal.service.FooService;
+
+public class HelpedCheckServiceProvider implements CheckService {
+    
+    /**
+     * Temporal dependency.
+     */
+    private FooService fs;
+    
+    private CheckServiceProviderHelper helper = new CheckServiceProviderHelper(fs);
+
+    public boolean check() {
+        return helper.check();
+    }
+
+    public Properties getProps() {
+        return helper.getProps();
+    }
+
+}

Propchange: felix/trunk/ipojo/tests/handler/temporal/src/main/java/org/apache/felix/ipojo/test/scenarios/component/proxy/HelpedCheckServiceProvider.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: felix/trunk/ipojo/tests/handler/temporal/src/main/java/org/apache/felix/ipojo/test/scenarios/component/proxy/HelpedCheckServiceProvider.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: felix/trunk/ipojo/tests/handler/temporal/src/main/java/org/apache/felix/ipojo/test/scenarios/component/proxy/HelpedCollectionCheckServiceProvider.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/tests/handler/temporal/src/main/java/org/apache/felix/ipojo/test/scenarios/component/proxy/HelpedCollectionCheckServiceProvider.java?rev=728714&view=auto
==============================================================================
--- felix/trunk/ipojo/tests/handler/temporal/src/main/java/org/apache/felix/ipojo/test/scenarios/component/proxy/HelpedCollectionCheckServiceProvider.java (added)
+++ felix/trunk/ipojo/tests/handler/temporal/src/main/java/org/apache/felix/ipojo/test/scenarios/component/proxy/HelpedCollectionCheckServiceProvider.java Mon Dec 22 07:46:12 2008
@@ -0,0 +1,43 @@
+/* 
+ * 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.
+ */
+package org.apache.felix.ipojo.test.scenarios.component.proxy;
+
+import java.util.Collection;
+import java.util.Properties;
+
+import org.apache.felix.ipojo.test.scenarios.temporal.service.CheckService;
+
+public class HelpedCollectionCheckServiceProvider implements CheckService {
+    
+    /**
+     * Temporal dependency.
+     */
+    private Collection fs;
+    
+    private CollectionCheckServiceProviderHelper helper = new CollectionCheckServiceProviderHelper(fs);
+
+    public boolean check() {
+        return helper.check();
+    }
+
+    public Properties getProps() {
+        return helper.getProps();
+    }
+
+}

Propchange: felix/trunk/ipojo/tests/handler/temporal/src/main/java/org/apache/felix/ipojo/test/scenarios/component/proxy/HelpedCollectionCheckServiceProvider.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: felix/trunk/ipojo/tests/handler/temporal/src/main/java/org/apache/felix/ipojo/test/scenarios/temporal/DefaultImplementationTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/tests/handler/temporal/src/main/java/org/apache/felix/ipojo/test/scenarios/temporal/DefaultImplementationTest.java?rev=728714&r1=728713&r2=728714&view=diff
==============================================================================
--- felix/trunk/ipojo/tests/handler/temporal/src/main/java/org/apache/felix/ipojo/test/scenarios/temporal/DefaultImplementationTest.java (original)
+++ felix/trunk/ipojo/tests/handler/temporal/src/main/java/org/apache/felix/ipojo/test/scenarios/temporal/DefaultImplementationTest.java Mon Dec 22 07:46:12 2008
@@ -66,6 +66,45 @@
        under.dispose();
    }
    
+   public void testDefaultImplementationWithProxy() {
+       String prov = "provider";
+       ComponentInstance provider = Utils.getComponentInstanceByName(context, "TEMPORAL-FooProvider", prov);
+       String un = "under-1";
+       ComponentInstance under = Utils.getComponentInstanceByName(context, "TEMPORAL-DIProxiedCheckServiceProvider", un);
+       
+       ServiceReference ref_fs = Utils.getServiceReferenceByName(context, FooService.class.getName(), prov);
+       assertNotNull("Check foo availability", ref_fs);
+       
+       ServiceReference ref_cs = Utils.getServiceReferenceByName(context, CheckService.class.getName(), un);
+       assertNotNull("Check cs availability", ref_cs);
+       
+       CheckService cs = (CheckService) context.getService(ref_cs);
+       assertTrue("Check invocation", cs.check());
+       
+       // Stop the provider.
+       provider.stop();
+       ref_cs = Utils.getServiceReferenceByName(context, CheckService.class.getName(), un);
+       assertNotNull("Check cs availability - 2", ref_cs);
+       long begin = System.currentTimeMillis();
+       DelayedProvider dp = new DelayedProvider(provider, 200);
+       dp.start();
+       cs = (CheckService) context.getService(ref_cs);
+       assertTrue("Check invocation - 2", cs.check());
+       long end = System.currentTimeMillis();
+      
+       assertTrue("Assert delay", (end - begin) >= 200);
+       
+       ref_cs = Utils.getServiceReferenceByName(context, CheckService.class.getName(), un);
+       assertNotNull("Check cs availability - 3", ref_cs);
+       cs = (CheckService) context.getService(ref_cs);
+       assertTrue("Check invocation - 3", cs.check());
+       
+       provider.stop();
+       provider.dispose();
+       under.stop();
+       under.dispose();
+   }
+   
    public void testDefaultImplementationTimeout() {
        String prov = "provider";
        ComponentInstance provider = Utils.getComponentInstanceByName(context, "TEMPORAL-FooProvider", prov);
@@ -101,6 +140,41 @@
        return;
    }
    
+   public void testDefaultImplementationTimeoutWithProxy() {
+       String prov = "provider";
+       ComponentInstance provider = Utils.getComponentInstanceByName(context, "TEMPORAL-FooProvider", prov);
+       String un = "under-1";
+       ComponentInstance under = Utils.getComponentInstanceByName(context, "TEMPORAL-DIProxiedCheckServiceProvider", un);
+       
+       ServiceReference ref_fs = Utils.getServiceReferenceByName(context, FooService.class.getName(), prov);
+       assertNotNull("Check foo availability", ref_fs);
+       
+       ServiceReference ref_cs = Utils.getServiceReferenceByName(context, CheckService.class.getName(), un);
+       assertNotNull("Check cs availability", ref_cs);
+       
+       CheckService cs = (CheckService) context.getService(ref_cs);
+       assertTrue("Check invocation", cs.check());
+       
+       // Stop the provider.
+       provider.stop();
+       ref_cs = Utils.getServiceReferenceByName(context, CheckService.class.getName(), un);
+       assertNotNull("Check cs availability - 2", ref_cs);
+       cs = (CheckService) context.getService(ref_cs);
+       boolean res = false;
+       try {
+           res = cs.check();
+       } catch(RuntimeException e) {
+           fail("A nullable was expected ...");
+       }   
+       assertFalse("Check nullable", res);
+
+       provider.stop();
+       provider.dispose();
+       under.stop();
+       under.dispose();
+       return;
+   }
+   
    public void testDelayTimeout() {
        String prov = "provider";
        ComponentInstance provider = Utils.getComponentInstanceByName(context, "TEMPORAL-FooProvider", prov);
@@ -140,6 +214,45 @@
        under.dispose();
    }
    
+   public void testDelayTimeoutWithProxy() {
+       String prov = "provider";
+       ComponentInstance provider = Utils.getComponentInstanceByName(context, "TEMPORAL-FooProvider", prov);
+       String un = "under-1";
+       ComponentInstance under = Utils.getComponentInstanceByName(context, "TEMPORAL-DIProxiedCheckServiceProviderTimeout", un);
+       
+       ServiceReference ref_fs = Utils.getServiceReferenceByName(context, FooService.class.getName(), prov);
+       assertNotNull("Check foo availability", ref_fs);
+       
+       ServiceReference ref_cs = Utils.getServiceReferenceByName(context, CheckService.class.getName(), un);
+       assertNotNull("Check cs availability", ref_cs);
+       
+       CheckService cs = (CheckService) context.getService(ref_cs);
+       assertTrue("Check invocation", cs.check());
+       
+       // Stop the provider.
+       provider.stop();
+       ref_cs = Utils.getServiceReferenceByName(context, CheckService.class.getName(), un);
+       assertNotNull("Check cs availability - 2", ref_cs);
+       long begin = System.currentTimeMillis();
+       DelayedProvider dp = new DelayedProvider(provider, 200);
+       dp.start();
+       cs = (CheckService) context.getService(ref_cs);
+       assertTrue("Check invocation - 2", cs.check());
+       long end = System.currentTimeMillis();
+       
+       assertTrue("Assert delay", (end - begin) >= 200);
+       
+       ref_cs = Utils.getServiceReferenceByName(context, CheckService.class.getName(), un);
+       assertNotNull("Check cs availability - 3", ref_cs);
+       cs = (CheckService) context.getService(ref_cs);
+       assertTrue("Check invocation - 3", cs.check());
+       
+       provider.stop();
+       provider.dispose();
+       under.stop();
+       under.dispose();
+   }
+   
    public void testDefaultImplementationMultipleTimeout() {
        String prov = "provider";
        ComponentInstance provider = Utils.getComponentInstanceByName(context, "TEMPORAL-FooProvider", prov);
@@ -178,6 +291,82 @@
        return;
    }
    
+   public void testDefaultImplementationCollectionTimeout() {
+       String prov = "provider";
+       ComponentInstance provider = Utils.getComponentInstanceByName(context, "TEMPORAL-FooProvider", prov);
+       String un = "under-1";
+       ComponentInstance under = Utils.getComponentInstanceByName(context, "TEMPORAL-DIColCheckServiceProviderTimeout", un);
+       
+       ServiceReference ref_fs = Utils.getServiceReferenceByName(context, FooService.class.getName(), prov);
+       assertNotNull("Check foo availability", ref_fs);
+       
+       ServiceReference ref_cs = Utils.getServiceReferenceByName(context, CheckService.class.getName(), un);
+       assertNotNull("Check cs availability", ref_cs);
+       
+       CheckService cs = (CheckService) context.getService(ref_cs);
+       assertTrue("Check invocation", cs.check());
+       
+       // Stop the provider.
+       provider.stop();
+       ref_cs = Utils.getServiceReferenceByName(context, CheckService.class.getName(), un);
+       assertNotNull("Check cs availability - 2", ref_cs);
+       DelayedProvider dp = new DelayedProvider(provider, 400);
+       dp.start();
+       cs = (CheckService) context.getService(ref_cs);
+       boolean res = false;
+       try {
+           res = cs.check();
+       } catch(RuntimeException e) {
+           fail("A nullable was expected ...");
+       }   
+       assertFalse("Check nullable", res);
+       
+       dp.stop();
+       provider.stop();
+       provider.dispose();
+       under.stop();
+       under.dispose();
+       return;
+   }
+   
+   public void testDefaultImplementationProxiedCollectionTimeout() {
+       String prov = "provider";
+       ComponentInstance provider = Utils.getComponentInstanceByName(context, "TEMPORAL-FooProvider", prov);
+       String un = "under-1";
+       ComponentInstance under = Utils.getComponentInstanceByName(context, "TEMPORAL-DIProxiedColCheckServiceProviderTimeout", un);
+       
+       ServiceReference ref_fs = Utils.getServiceReferenceByName(context, FooService.class.getName(), prov);
+       assertNotNull("Check foo availability", ref_fs);
+       
+       ServiceReference ref_cs = Utils.getServiceReferenceByName(context, CheckService.class.getName(), un);
+       assertNotNull("Check cs availability", ref_cs);
+       
+       CheckService cs = (CheckService) context.getService(ref_cs);
+       assertTrue("Check invocation", cs.check());
+       
+       // Stop the provider.
+       provider.stop();
+       ref_cs = Utils.getServiceReferenceByName(context, CheckService.class.getName(), un);
+       assertNotNull("Check cs availability - 2", ref_cs);
+       DelayedProvider dp = new DelayedProvider(provider, 400);
+       dp.start();
+       cs = (CheckService) context.getService(ref_cs);
+       boolean res = false;
+       try {
+           res = cs.check();
+       } catch(RuntimeException e) {
+           fail("A nullable was expected ...");
+       }   
+       assertFalse("Check nullable", res);
+       
+       dp.stop();
+       provider.stop();
+       provider.dispose();
+       under.stop();
+       under.dispose();
+       return;
+   }
+   
    public void testDelayOnMultipleDependency() {
        String prov = "provider";
        ComponentInstance provider1 = Utils.getComponentInstanceByName(context, "TEMPORAL-FooProvider", prov);
@@ -228,4 +417,106 @@
        under.stop();
        under.dispose();
    }
+   
+   public void testDelayOnCollectionDependency() {
+       String prov = "provider";
+       ComponentInstance provider1 = Utils.getComponentInstanceByName(context, "TEMPORAL-FooProvider", prov);
+       String prov2 = "provider2";
+       ComponentInstance provider2 = Utils.getComponentInstanceByName(context, "TEMPORAL-FooProvider", prov2);
+       String un = "under-1";
+       ComponentInstance under = Utils.getComponentInstanceByName(context, "TEMPORAL-NullableColCheckServiceProviderTimeout", un);
+       
+       ServiceReference ref_fs = Utils.getServiceReferenceByName(context, FooService.class.getName(), prov);
+       assertNotNull("Check foo availability", ref_fs);
+       
+       ServiceReference ref_cs = Utils.getServiceReferenceByName(context, CheckService.class.getName(), un);
+       assertNotNull("Check cs availability", ref_cs);
+       
+       CheckService cs = (CheckService) context.getService(ref_cs);
+       assertTrue("Check invocation", cs.check());
+       
+       // Stop the providers.
+       provider1.stop();
+       provider2.stop();
+       ref_cs = Utils.getServiceReferenceByName(context, CheckService.class.getName(), un);
+       assertNotNull("Check cs availability - 2", ref_cs);
+       long begin = System.currentTimeMillis();
+       DelayedProvider dp = new DelayedProvider(provider1, 1500);
+       DelayedProvider dp2 = new DelayedProvider(provider2, 100);
+       dp.start();
+       dp2.start();
+       cs = (CheckService) context.getService(ref_cs);
+       assertTrue("Check invocation - 2", cs.check());
+       long end = System.currentTimeMillis();
+       System.out.println("delay = " + (end - begin));
+       assertTrue("Assert min delay", (end - begin) >= 100);
+       assertTrue("Assert max delay", (end - begin) <= 1000);
+       dp.stop();
+       dp2.stop();
+       
+       provider1.stop();
+       provider2.stop();
+       
+       ref_cs = Utils.getServiceReferenceByName(context, CheckService.class.getName(), un);
+       assertNotNull("Check cs availability - 3", ref_cs);
+       cs = (CheckService) context.getService(ref_cs);
+       
+       assertFalse("Check invocation - 3", cs.check()); // Will return false as the contained DI will return false to the foo method.
+
+       provider1.dispose();
+       provider2.dispose();
+       under.stop();
+       under.dispose();
+   }
+   
+   public void testDelayOnProxiedCollectionDependency() {
+       String prov = "provider";
+       ComponentInstance provider1 = Utils.getComponentInstanceByName(context, "TEMPORAL-FooProvider", prov);
+       String prov2 = "provider2";
+       ComponentInstance provider2 = Utils.getComponentInstanceByName(context, "TEMPORAL-FooProvider", prov2);
+       String un = "under-1";
+       ComponentInstance under = Utils.getComponentInstanceByName(context, "TEMPORAL-NullableProxiedColCheckServiceProviderTimeout", un);
+       
+       ServiceReference ref_fs = Utils.getServiceReferenceByName(context, FooService.class.getName(), prov);
+       assertNotNull("Check foo availability", ref_fs);
+       
+       ServiceReference ref_cs = Utils.getServiceReferenceByName(context, CheckService.class.getName(), un);
+       assertNotNull("Check cs availability", ref_cs);
+       
+       CheckService cs = (CheckService) context.getService(ref_cs);
+       assertTrue("Check invocation", cs.check());
+       
+       // Stop the providers.
+       provider1.stop();
+       provider2.stop();
+       ref_cs = Utils.getServiceReferenceByName(context, CheckService.class.getName(), un);
+       assertNotNull("Check cs availability - 2", ref_cs);
+       long begin = System.currentTimeMillis();
+       DelayedProvider dp = new DelayedProvider(provider1, 1500);
+       DelayedProvider dp2 = new DelayedProvider(provider2, 100);
+       dp.start();
+       dp2.start();
+       cs = (CheckService) context.getService(ref_cs);
+       assertTrue("Check invocation - 2", cs.check());
+       long end = System.currentTimeMillis();
+       System.out.println("delay = " + (end - begin));
+       assertTrue("Assert min delay", (end - begin) >= 100);
+       assertTrue("Assert max delay", (end - begin) <= 1000);
+       dp.stop();
+       dp2.stop();
+       
+       provider1.stop();
+       provider2.stop();
+       
+       ref_cs = Utils.getServiceReferenceByName(context, CheckService.class.getName(), un);
+       assertNotNull("Check cs availability - 3", ref_cs);
+       cs = (CheckService) context.getService(ref_cs);
+       
+       assertFalse("Check invocation - 3", cs.check()); // Will return false as the contained DI will return false to the foo method.
+
+       provider1.dispose();
+       provider2.dispose();
+       under.stop();
+       under.dispose();
+   }
 }

Modified: felix/trunk/ipojo/tests/handler/temporal/src/main/java/org/apache/felix/ipojo/test/scenarios/temporal/DelayTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/tests/handler/temporal/src/main/java/org/apache/felix/ipojo/test/scenarios/temporal/DelayTest.java?rev=728714&r1=728713&r2=728714&view=diff
==============================================================================
--- felix/trunk/ipojo/tests/handler/temporal/src/main/java/org/apache/felix/ipojo/test/scenarios/temporal/DelayTest.java (original)
+++ felix/trunk/ipojo/tests/handler/temporal/src/main/java/org/apache/felix/ipojo/test/scenarios/temporal/DelayTest.java Mon Dec 22 07:46:12 2008
@@ -66,6 +66,45 @@
        under.dispose();
    }
    
+   public void testDelayWithProxy() {
+       String prov = "provider";
+       ComponentInstance provider = Utils.getComponentInstanceByName(context, "TEMPORAL-FooProvider", prov);
+       String un = "under-1";
+       ComponentInstance under = Utils.getComponentInstanceByName(context, "TEMPORAL-ProxiedCheckServiceProvider", un);
+       
+       ServiceReference ref_fs = Utils.getServiceReferenceByName(context, FooService.class.getName(), prov);
+       assertNotNull("Check foo availability", ref_fs);
+       
+       ServiceReference ref_cs = Utils.getServiceReferenceByName(context, CheckService.class.getName(), un);
+       assertNotNull("Check cs availability", ref_cs);
+       
+       CheckService cs = (CheckService) context.getService(ref_cs);
+       assertTrue("Check invocation", cs.check());
+       
+       // Stop the provider.
+       provider.stop();
+       ref_cs = Utils.getServiceReferenceByName(context, CheckService.class.getName(), un);
+       assertNotNull("Check cs availability - 2", ref_cs);
+       long begin = System.currentTimeMillis();
+       DelayedProvider dp = new DelayedProvider(provider, 200);
+       dp.start();
+       cs = (CheckService) context.getService(ref_cs);
+       assertTrue("Check invocation - 2", cs.check());
+       long end = System.currentTimeMillis();
+       
+       assertTrue("Assert delay", (end - begin) >= 200);
+       
+       ref_cs = Utils.getServiceReferenceByName(context, CheckService.class.getName(), un);
+       assertNotNull("Check cs availability - 3", ref_cs);
+       cs = (CheckService) context.getService(ref_cs);
+       assertTrue("Check invocation - 3", cs.check());
+       
+       provider.stop();
+       provider.dispose();
+       under.stop();
+       under.dispose();
+   }
+   
    public void testTimeout() {
        String prov = "provider";
        ComponentInstance provider = Utils.getComponentInstanceByName(context, "TEMPORAL-FooProvider", prov);
@@ -103,6 +142,43 @@
        fail("Timeout expected");
    }
    
+   public void testTimeoutWithProxy() {
+       String prov = "provider";
+       ComponentInstance provider = Utils.getComponentInstanceByName(context, "TEMPORAL-FooProvider", prov);
+       String un = "under-1";
+       ComponentInstance under = Utils.getComponentInstanceByName(context, "TEMPORAL-ProxiedCheckServiceProvider", un);
+       
+       ServiceReference ref_fs = Utils.getServiceReferenceByName(context, FooService.class.getName(), prov);
+       assertNotNull("Check foo availability", ref_fs);
+       
+       ServiceReference ref_cs = Utils.getServiceReferenceByName(context, CheckService.class.getName(), un);
+       assertNotNull("Check cs availability", ref_cs);
+       
+       CheckService cs = (CheckService) context.getService(ref_cs);
+       assertTrue("Check invocation", cs.check());
+       
+       // Stop the provider.
+       provider.stop();
+       ref_cs = Utils.getServiceReferenceByName(context, CheckService.class.getName(), un);
+       assertNotNull("Check cs availability - 2", ref_cs);
+       DelayedProvider dp = new DelayedProvider(provider, 4000);
+       dp.start();
+       cs = (CheckService) context.getService(ref_cs);
+       try {
+           cs.check();
+       } catch(RuntimeException e) {
+           // OK
+           dp.stop();
+           provider.stop();
+           provider.dispose();
+           under.stop();
+           under.dispose();
+           return;
+       }   
+       
+       fail("Timeout expected");
+   }
+   
    public void testDelayTimeout() {
        String prov = "provider";
        ComponentInstance provider = Utils.getComponentInstanceByName(context, "TEMPORAL-FooProvider", prov);
@@ -142,6 +218,45 @@
        under.dispose();
    }
    
+   public void testDelayTimeoutWithProxy() {
+       String prov = "provider";
+       ComponentInstance provider = Utils.getComponentInstanceByName(context, "TEMPORAL-FooProvider", prov);
+       String un = "under-1";
+       ComponentInstance under = Utils.getComponentInstanceByName(context, "TEMPORAL-ProxiedCheckServiceProviderTimeout", un);
+       
+       ServiceReference ref_fs = Utils.getServiceReferenceByName(context, FooService.class.getName(), prov);
+       assertNotNull("Check foo availability", ref_fs);
+       
+       ServiceReference ref_cs = Utils.getServiceReferenceByName(context, CheckService.class.getName(), un);
+       assertNotNull("Check cs availability", ref_cs);
+       
+       CheckService cs = (CheckService) context.getService(ref_cs);
+       assertTrue("Check invocation", cs.check());
+       
+       // Stop the provider.
+       provider.stop();
+       ref_cs = Utils.getServiceReferenceByName(context, CheckService.class.getName(), un);
+       assertNotNull("Check cs availability - 2", ref_cs);
+       long begin = System.currentTimeMillis();
+       DelayedProvider dp = new DelayedProvider(provider, 200);
+       dp.start();
+       cs = (CheckService) context.getService(ref_cs);
+       assertTrue("Check invocation - 2", cs.check());
+       long end = System.currentTimeMillis();
+       
+       assertTrue("Assert delay", (end - begin) >= 200);
+       
+       ref_cs = Utils.getServiceReferenceByName(context, CheckService.class.getName(), un);
+       assertNotNull("Check cs availability - 3", ref_cs);
+       cs = (CheckService) context.getService(ref_cs);
+       assertTrue("Check invocation - 3", cs.check());
+       
+       provider.stop();
+       provider.dispose();
+       under.stop();
+       under.dispose();
+   }
+   
    public void testSetTimeout() {
        String prov = "provider";
        ComponentInstance provider = Utils.getComponentInstanceByName(context, "TEMPORAL-FooProvider", prov);
@@ -179,6 +294,43 @@
        fail("Timeout expected");
    }
    
+   public void testSetTimeoutWithProxy() {
+       String prov = "provider";
+       ComponentInstance provider = Utils.getComponentInstanceByName(context, "TEMPORAL-FooProvider", prov);
+       String un = "under-1";
+       ComponentInstance under = Utils.getComponentInstanceByName(context, "TEMPORAL-ProxiedCheckServiceProviderTimeout", un);
+       
+       ServiceReference ref_fs = Utils.getServiceReferenceByName(context, FooService.class.getName(), prov);
+       assertNotNull("Check foo availability", ref_fs);
+       
+       ServiceReference ref_cs = Utils.getServiceReferenceByName(context, CheckService.class.getName(), un);
+       assertNotNull("Check cs availability", ref_cs);
+       
+       CheckService cs = (CheckService) context.getService(ref_cs);
+       assertTrue("Check invocation", cs.check());
+       
+       // Stop the provider.
+       provider.stop();
+       ref_cs = Utils.getServiceReferenceByName(context, CheckService.class.getName(), un);
+       assertNotNull("Check cs availability - 2", ref_cs);
+       DelayedProvider dp = new DelayedProvider(provider, 400);
+       dp.start();
+       cs = (CheckService) context.getService(ref_cs);
+       try {
+           cs.check();
+       } catch(RuntimeException e) {
+           // OK
+           dp.stop();
+           provider.stop();
+           provider.dispose();
+           under.stop();
+           under.dispose();
+           return;
+       }   
+       
+       fail("Timeout expected");
+   }
+   
    public void testDelayOnMultipleDependency() {
        String prov = "provider";
        ComponentInstance provider1 = Utils.getComponentInstanceByName(context, "TEMPORAL-FooProvider", prov);
@@ -227,4 +379,102 @@
        under.stop();
        under.dispose();
    }
+   
+   public void testDelayOnCollectionDependency() {
+       String prov = "provider";
+       ComponentInstance provider1 = Utils.getComponentInstanceByName(context, "TEMPORAL-FooProvider", prov);
+       String prov2 = "provider2";
+       ComponentInstance provider2 = Utils.getComponentInstanceByName(context, "TEMPORAL-FooProvider", prov2);
+       String un = "under-1";
+       ComponentInstance under = Utils.getComponentInstanceByName(context, "TEMPORAL-ColCheckServiceProvider", un);
+       
+       ServiceReference ref_fs = Utils.getServiceReferenceByName(context, FooService.class.getName(), prov);
+       assertNotNull("Check foo availability", ref_fs);
+       
+       ServiceReference ref_cs = Utils.getServiceReferenceByName(context, CheckService.class.getName(), un);
+       assertNotNull("Check cs availability", ref_cs);
+       
+       CheckService cs = (CheckService) context.getService(ref_cs);
+       assertTrue("Check invocation", cs.check());
+       
+       // Stop the providers.
+       provider1.stop();
+       provider2.stop();
+       ref_cs = Utils.getServiceReferenceByName(context, CheckService.class.getName(), un);
+       assertNotNull("Check cs availability - 2", ref_cs);
+       long begin = System.currentTimeMillis();
+       DelayedProvider dp = new DelayedProvider(provider1, 1500);
+       DelayedProvider dp2 = new DelayedProvider(provider2, 100);
+       dp.start();
+       dp2.start();
+       cs = (CheckService) context.getService(ref_cs);
+       assertTrue("Check invocation - 2", cs.check());
+       long end = System.currentTimeMillis();
+       System.out.println("delay = " + (end - begin));
+       assertTrue("Assert min delay", (end - begin) >= 100);
+       assertTrue("Assert max delay", (end - begin) <= 1000);
+       dp.stop();
+       dp2.stop();
+       
+       ref_cs = Utils.getServiceReferenceByName(context, CheckService.class.getName(), un);
+       assertNotNull("Check cs availability - 3", ref_cs);
+       cs = (CheckService) context.getService(ref_cs);
+       assertTrue("Check invocation - 3", cs.check());
+       
+       provider1.stop();
+       provider2.stop();
+       provider1.dispose();
+       provider2.dispose();
+       under.stop();
+       under.dispose();
+   }
+   
+   public void testDelayOnProxiedCollectionDependency() {
+       String prov = "provider";
+       ComponentInstance provider1 = Utils.getComponentInstanceByName(context, "TEMPORAL-FooProvider", prov);
+       String prov2 = "provider2";
+       ComponentInstance provider2 = Utils.getComponentInstanceByName(context, "TEMPORAL-FooProvider", prov2);
+       String un = "under-1";
+       ComponentInstance under = Utils.getComponentInstanceByName(context, "TEMPORAL-ProxiedColCheckServiceProvider", un);
+       
+       ServiceReference ref_fs = Utils.getServiceReferenceByName(context, FooService.class.getName(), prov);
+       assertNotNull("Check foo availability", ref_fs);
+       
+       ServiceReference ref_cs = Utils.getServiceReferenceByName(context, CheckService.class.getName(), un);
+       assertNotNull("Check cs availability", ref_cs);
+       
+       CheckService cs = (CheckService) context.getService(ref_cs);
+       assertTrue("Check invocation", cs.check());
+       
+       // Stop the providers.
+       provider1.stop();
+       provider2.stop();
+       ref_cs = Utils.getServiceReferenceByName(context, CheckService.class.getName(), un);
+       assertNotNull("Check cs availability - 2", ref_cs);
+       long begin = System.currentTimeMillis();
+       DelayedProvider dp = new DelayedProvider(provider1, 1500);
+       DelayedProvider dp2 = new DelayedProvider(provider2, 100);
+       dp.start();
+       dp2.start();
+       cs = (CheckService) context.getService(ref_cs);
+       assertTrue("Check invocation - 2", cs.check());
+       long end = System.currentTimeMillis();
+       System.out.println("delay = " + (end - begin));
+       assertTrue("Assert min delay", (end - begin) >= 100);
+       assertTrue("Assert max delay", (end - begin) <= 1000);
+       dp.stop();
+       dp2.stop();
+       
+       ref_cs = Utils.getServiceReferenceByName(context, CheckService.class.getName(), un);
+       assertNotNull("Check cs availability - 3", ref_cs);
+       cs = (CheckService) context.getService(ref_cs);
+       assertTrue("Check invocation - 3", cs.check());
+       
+       provider1.stop();
+       provider2.stop();
+       provider1.dispose();
+       provider2.dispose();
+       under.stop();
+       under.dispose();
+   }
 }



Mime
View raw message