You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by cl...@apache.org on 2008/05/16 18:12:13 UTC

svn commit: r657122 - in /felix/sandbox/clement/temporal/org.apache.felix.ipojo.handler.temporal/src/main: java/org/apache/felix/ipojo/handler/temporal/ resources/

Author: clement
Date: Fri May 16 09:12:12 2008
New Revision: 657122

URL: http://svn.apache.org/viewvc?rev=657122&view=rev
Log:
Refactor the code to be compliant with the coding style

Modified:
    felix/sandbox/clement/temporal/org.apache.felix.ipojo.handler.temporal/src/main/java/org/apache/felix/ipojo/handler/temporal/TemporalDependency.java
    felix/sandbox/clement/temporal/org.apache.felix.ipojo.handler.temporal/src/main/java/org/apache/felix/ipojo/handler/temporal/TemporalHandler.java
    felix/sandbox/clement/temporal/org.apache.felix.ipojo.handler.temporal/src/main/resources/metadata.xml

Modified: felix/sandbox/clement/temporal/org.apache.felix.ipojo.handler.temporal/src/main/java/org/apache/felix/ipojo/handler/temporal/TemporalDependency.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/temporal/org.apache.felix.ipojo.handler.temporal/src/main/java/org/apache/felix/ipojo/handler/temporal/TemporalDependency.java?rev=657122&r1=657121&r2=657122&view=diff
==============================================================================
--- felix/sandbox/clement/temporal/org.apache.felix.ipojo.handler.temporal/src/main/java/org/apache/felix/ipojo/handler/temporal/TemporalDependency.java (original)
+++ felix/sandbox/clement/temporal/org.apache.felix.ipojo.handler.temporal/src/main/java/org/apache/felix/ipojo/handler/temporal/TemporalDependency.java Fri May 16 09:12:12 2008
@@ -1,3 +1,21 @@
+/* 
+ * 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.Array;
@@ -8,27 +26,74 @@
 import org.osgi.framework.Filter;
 import org.osgi.framework.ServiceReference;
 
+/**
+* Temporal dependency.
+* A temporal dependency waits (block) for the availability of the service.
+* If no provider arrives in the specified among of time, a runtime exception is thrown.
+* @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+*/
 public class TemporalDependency extends DependencyModel implements FieldInterceptor {
     
-    private long timeout;
-    private String field;
-
+    /**
+     * Timeout.
+     */
+    private long m_timeout;
+
+    /**
+     * Constructor.
+     * @param spec : service specification
+     * @param agg : is the dependency aggregate ?
+     * @param filter : LDAP filter
+     * @param context : service context
+     * @param timeout : timeout
+     * @param handler : Handler managing this dependency
+     */
     public TemporalDependency(Class spec, String field, boolean agg, Filter filter, BundleContext context, long timeout, TemporalHandler handler) {
         super(spec, agg, true, filter, null, DependencyModel.DYNAMIC_BINDING_POLICY, context, handler);
-        this.field = field;
-        this.timeout = timeout;
+        this.m_timeout = timeout;
     }
 
-    public void onDependencyReconfiguration(ServiceReference[] arg0, ServiceReference[] arg1) { }
+    /**
+     * The dependency has been reconfigured.
+     * @param arg0 : new service references
+     * @param arg1 : old service references
+     * @see org.apache.felix.ipojo.util.DependencyModel#onDependencyReconfiguration(org.osgi.framework.ServiceReference[], org.osgi.framework.ServiceReference[])
+     */
+    public void onDependencyReconfiguration(ServiceReference[] arg0, ServiceReference[] arg1) { 
+        throw new UnsupportedOperationException("Reconfiguration not yet supported");
+    }
 
+    /**
+     * A provider arrives.
+     * @param arg0 : service reference of the new provider.
+     * @see org.apache.felix.ipojo.util.DependencyModel#onServiceArrival(org.osgi.framework.ServiceReference)
+     */
     public void onServiceArrival(ServiceReference arg0) {
+        // Notify if a thread is waiting.
         synchronized (this) {
             notifyAll();
         }
     }
 
+    /**
+     * A provider leaves.
+     * Nothing to do.
+     * @param arg0 : leaving service references.
+     * @see org.apache.felix.ipojo.util.DependencyModel#onServiceDeparture(org.osgi.framework.ServiceReference)
+     */
     public synchronized void onServiceDeparture(ServiceReference arg0) { }
     
+    /**
+     * The code require a value of the monitored field.
+     * If providers are available, the method return service object(s) immediately. 
+     * Else, the thread is blocked until an arrival. If no provider arrives during 
+     * the among of time specified, the method throws a Runtime Exception.
+     * @param arg0 : POJO instance asking for  the service
+     * @param arg1 : field name
+     * @param arg2 : previous value
+     * @return the object to inject.
+     * @see org.apache.felix.ipojo.FieldInterceptor#onGet(java.lang.Object, java.lang.String, java.lang.Object)
+     */
     public synchronized Object onGet(Object arg0, String arg1, Object arg2) {
         ServiceReference[] refs = getServiceReferences();
         if (refs != null) {
@@ -55,7 +120,7 @@
                         // We was interrupted ....
                     } finally {
                         long end = System.currentTimeMillis(); 
-                        exhausted = (end - enter) > timeout;
+                        exhausted = (end - enter) > m_timeout;
                     }
                 }
             }
@@ -76,6 +141,14 @@
         }
     }
 
+    /**
+     * The monitored field receives a value.
+     * Nothing to do.
+     * @param arg0 : POJO setting the value.
+     * @param arg1 : field name
+     * @param arg2 : received value
+     * @see org.apache.felix.ipojo.FieldInterceptor#onSet(java.lang.Object, java.lang.String, java.lang.Object)
+     */
     public void onSet(Object arg0, String arg1, Object arg2) { }
 
 }

Modified: felix/sandbox/clement/temporal/org.apache.felix.ipojo.handler.temporal/src/main/java/org/apache/felix/ipojo/handler/temporal/TemporalHandler.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/temporal/org.apache.felix.ipojo.handler.temporal/src/main/java/org/apache/felix/ipojo/handler/temporal/TemporalHandler.java?rev=657122&r1=657121&r2=657122&view=diff
==============================================================================
--- felix/sandbox/clement/temporal/org.apache.felix.ipojo.handler.temporal/src/main/java/org/apache/felix/ipojo/handler/temporal/TemporalHandler.java (original)
+++ felix/sandbox/clement/temporal/org.apache.felix.ipojo.handler.temporal/src/main/java/org/apache/felix/ipojo/handler/temporal/TemporalHandler.java Fri May 16 09:12:12 2008
@@ -1,3 +1,21 @@
+/* 
+ * 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;
@@ -14,18 +32,43 @@
 import org.osgi.framework.Filter;
 import org.osgi.framework.InvalidSyntaxException;
 
+/**
+* Temporal dependency handler.
+* A temporal dependency waits (block) for the availability of the service.
+* If no provider arrives in the specified among of time, a runtime exception is thrown.
+* @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+*/
 public class TemporalHandler extends PrimitiveHandler implements DependencyStateListener {
     
+    /**
+     * Default timeout if not specified.
+     */
+    public static final int DEFAULT_TIMEOUT = 3000; 
+    
+    /**
+     * List of managed dependencies.
+     */
     private List/*<deps>*/ m_dependencies = new ArrayList(1);
     
+    /**
+     * Handler namespace.
+     */
     public static final String NAMESPACE = "org.apache.felix.ipojo.handler.temporal";
 
+    /**
+     * Start method. Starts managed dependencies.
+     * @see org.apache.felix.ipojo.Handler#start()
+     */
     public void start() {
         for (int i = 0; i < m_dependencies.size(); i++) {
             ((TemporalDependency) m_dependencies.get(i)).start();
         }
     }
     
+    /**
+     * Stop  method. Stops managed dependencies.
+     * @see org.apache.felix.ipojo.Handler#stop()
+     */
     public void stop() {
         for (int i = 0; i < m_dependencies.size(); i++) {
             ((TemporalDependency) m_dependencies.get(i)).stop();
@@ -33,6 +76,14 @@
         m_dependencies.clear();
     }
 
+    /**
+     * Configure method.
+     * Create managed dependencies.
+     * @param meta : component type metadata.
+     * @param dictionary : instance configuration.
+     * @throws ConfigurationException
+     * @see org.apache.felix.ipojo.Handler#configure(org.apache.felix.ipojo.metadata.Element, java.util.Dictionary)
+     */
     public void configure(Element meta, Dictionary dictionary) throws ConfigurationException {
         PojoMetadata manipulation = getFactory().getPojoMetadata();
         Element[] deps = meta.getElements("requires", NAMESPACE);
@@ -72,7 +123,7 @@
                 spec = spec.substring(0, spec.length() - 2);
             }
             
-            long timeout = 3000; // Default timeout.
+            long timeout = DEFAULT_TIMEOUT;
             if(deps[i].containsAttribute("timeout")) {
                 timeout = new Long(deps[i].getAttribute("timeout")).longValue();
             }
@@ -85,8 +136,20 @@
         }        
     }
 
+    /**
+     * Nothing to do.
+     * A temporal dependency is always valid.
+     * @param dependencymodel : dependency.
+     * @see org.apache.felix.ipojo.util.DependencyStateListener#invalidate(org.apache.felix.ipojo.util.DependencyModel)
+     */
     public void invalidate(DependencyModel dependencymodel) {    }
 
+    /**
+     * Nothing to do.
+     * A temporal dependency is always valid.
+     * @param dependencymodel : dependency.
+     * @see org.apache.felix.ipojo.util.DependencyStateListener#validate(org.apache.felix.ipojo.util.DependencyModel)
+     */
     public void validate(DependencyModel dependencymodel) {    }
     
 

Modified: felix/sandbox/clement/temporal/org.apache.felix.ipojo.handler.temporal/src/main/resources/metadata.xml
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/temporal/org.apache.felix.ipojo.handler.temporal/src/main/resources/metadata.xml?rev=657122&r1=657121&r2=657122&view=diff
==============================================================================
--- felix/sandbox/clement/temporal/org.apache.felix.ipojo.handler.temporal/src/main/resources/metadata.xml (original)
+++ felix/sandbox/clement/temporal/org.apache.felix.ipojo.handler.temporal/src/main/resources/metadata.xml Fri May 16 09:12:12 2008
@@ -1,3 +1,21 @@
+<!--
+	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.
+-->
 <ipojo>
 <handler classname="org.apache.felix.ipojo.handler.temporal.TemporalHandler" name="requires" namespace="org.apache.felix.ipojo.handler.temporal">
 </handler>