incubator-aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jb...@apache.org
Subject svn commit: r1022810 - in /incubator/aries/sandbox/jbohn/interceptor-proto: blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/utils/ blueprint/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/ transaction/transaction-ite...
Date Fri, 15 Oct 2010 02:16:35 GMT
Author: jbohn
Date: Fri Oct 15 02:16:35 2010
New Revision: 1022810

URL: http://svn.apache.org/viewvc?rev=1022810&view=rev
Log:
ARIES-420 only register a single interceptor service and create a service reference for each
interceptor/bundle/bean combination

Modified:
    incubator/aries/sandbox/jbohn/interceptor-proto/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/utils/InterceptorManager.java
    incubator/aries/sandbox/jbohn/interceptor-proto/blueprint/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/TestConfigAdmin.java
    incubator/aries/sandbox/jbohn/interceptor-proto/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/AbstractIntegrationTest.java

Modified: incubator/aries/sandbox/jbohn/interceptor-proto/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/utils/InterceptorManager.java
URL: http://svn.apache.org/viewvc/incubator/aries/sandbox/jbohn/interceptor-proto/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/utils/InterceptorManager.java?rev=1022810&r1=1022809&r2=1022810&view=diff
==============================================================================
--- incubator/aries/sandbox/jbohn/interceptor-proto/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/utils/InterceptorManager.java
(original)
+++ incubator/aries/sandbox/jbohn/interceptor-proto/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/utils/InterceptorManager.java
Fri Oct 15 02:16:35 2010
@@ -19,9 +19,12 @@
 package org.apache.aries.blueprint.utils;
 
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.Dictionary;
+import java.util.HashMap;
 import java.util.Hashtable;
 import java.util.List;
+import java.util.Map;
 
 import org.apache.aries.blueprint.ComponentDefinitionRegistry;
 import org.apache.aries.blueprint.ExtendedBlueprintContainer;
@@ -35,6 +38,7 @@ import org.osgi.framework.Filter;
 import org.osgi.framework.FrameworkUtil;
 import org.osgi.framework.InvalidSyntaxException;
 import org.osgi.framework.ServiceRegistration;
+import org.osgi.service.blueprint.reflect.ComponentMetadata;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -54,9 +58,12 @@ public class InterceptorManager {
     private static final String FILTER_START = "(";
     private static final String FILTER_END = ")";
     private static final String FILTER_AND = "&";
+    private static final String DELIM = ":";
+    
+    private static final Map<String, Interceptor> interceptorCollection = Collections.synchronizedMap(new
HashMap<String, Interceptor>());
 
 //@JAB TODO:  Need to pass desired interceptor rank to use as service rank (or continue use
the the existing interceptor rank when regsitering service)    
-    public static void addInterceptorForBean(Interceptor interceptor, String beanId, ParserContext
pc) 
+    public static synchronized void addInterceptorForBean(Interceptor interceptor, String
beanId, ParserContext pc) 
     {
         LOGGER.debug("addInterceptorForBean interceptor {} bean {}", interceptor, beanId);
 
@@ -71,44 +78,50 @@ public class InterceptorManager {
         }
         
         if (bundle!=null && bundleId!=0) {
+        	String interceptorKey = interceptor.getIdentity() + DELIM + bundleId + DELIM + beanId;
             Dictionary properties = new Hashtable();
             properties.put(BUNDLE_ID, bundleId);
             properties.put(BEAN, beanId);
             properties.put(URI, interceptor.getIdentity());                    
             BundleContext bundleContext = bundle.getBundleContext();
 
-            //@JAB TODO:  Need to ensure that we only register service once per bean/bundle/interceptor
-            LOGGER.debug("addInterceptorForBean about to register interceptor service with
properties {}", properties);
-            ServiceRegistration registration = bundleContext.registerService(Interceptor.class.getName(),
interceptor, properties);
-
-            String id = pc.generateId();
-            String filter = FILTER_START + 
-                              FILTER_AND + 
-                                FILTER_START + 
-                                  BUNDLE_ID + "=" + bundleId + 
-                                FILTER_END + 
-                                FILTER_START + 
-                                  BEAN + "=" + beanId + 
-                                FILTER_END + 
-//@JAB TODO:  Need to create a filter that will resolve to correct, single match but 1st
need 
-//            to resolve filter comparison on get so that it does not need to be exact  
                            
-//                                FILTER_START +                                        

-//                                   URI + "=" + interceptor.getIdentity() +
-//                                FILTER_END +        
-                            FILTER_END;
-
-            ReferenceMetadataImpl referenceMetadata = new ReferenceMetadataImpl();
-            referenceMetadata.setId(id);
-//@JAB TODO:  Need to allow the reference to be either mandatory or optional as required
by the caller            
-            referenceMetadata.setAvailability(ReferenceMetadataImpl.AVAILABILITY_MANDATORY);
-            referenceMetadata.setRuntimeInterface(Interceptor.class);
-            referenceMetadata.setInterface(Interceptor.class.getName());
-            referenceMetadata.setFilter(filter);
-
-            //@JAB TODO:  Should only need to create one reference per bean/bundle/interceptor
-            LOGGER.debug("addInterceptorForBean about to register interceptor service reference
{}", properties);
-            cdr.registerComponentDefinition(referenceMetadata);  
-
+            if (interceptorCollection.get(interceptorKey) == null) {
+	            LOGGER.debug("addInterceptorForBean about to register interceptor service with
properties {}", properties);
+	            ServiceRegistration registration = bundleContext.registerService(Interceptor.class.getName(),
interceptor, properties);
+	
+	            String id = pc.generateId();
+	            String filter = FILTER_START + 
+	                              FILTER_AND + 
+	                                FILTER_START + 
+	                                  BUNDLE_ID + "=" + bundleId + 
+	                                FILTER_END + 
+	                                FILTER_START + 
+	                                  BEAN + "=" + beanId + 
+	                                FILTER_END + 
+	//@JAB TODO:  Need to create a filter that will resolve to correct, single match but 1st
need 
+	//            to resolve filter comparison on get so that it does not need to be exact 
                             
+	//                                FILTER_START +                                       
 
+	//                                   URI + "=" + interceptor.getIdentity() +
+	//                                FILTER_END +        
+	                            FILTER_END;
+	
+	            ReferenceMetadataImpl referenceMetadata = new ReferenceMetadataImpl();
+	            referenceMetadata.setId(id);
+	//@JAB TODO:  Need to allow the reference to be either mandatory or optional as required
by the caller            
+	            referenceMetadata.setAvailability(ReferenceMetadataImpl.AVAILABILITY_MANDATORY);
+	            referenceMetadata.setRuntimeInterface(Interceptor.class);
+	            referenceMetadata.setInterface(Interceptor.class.getName());
+	            referenceMetadata.setFilter(filter);
+	
+	            //@JAB TODO:  Should only need to create one reference per bean/bundle/interceptor
+	            LOGGER.debug("addInterceptorForBean about to register interceptor service reference
{}", properties);
+	            cdr.registerComponentDefinition(referenceMetadata); 
+	            
+	            interceptorCollection.put(interceptorKey, interceptor);
+            }
+            else {
+            	LOGGER.debug("addInterceptorForBean interceptor already registered for bundle
& bean " + interceptorKey );	
+            }
         }
         else {
             LOGGER.debug("addInterceptorForBean bundle is null - can not register interceptor
service");

Modified: incubator/aries/sandbox/jbohn/interceptor-proto/blueprint/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/TestConfigAdmin.java
URL: http://svn.apache.org/viewvc/incubator/aries/sandbox/jbohn/interceptor-proto/blueprint/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/TestConfigAdmin.java?rev=1022810&r1=1022809&r2=1022810&view=diff
==============================================================================
--- incubator/aries/sandbox/jbohn/interceptor-proto/blueprint/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/TestConfigAdmin.java
(original)
+++ incubator/aries/sandbox/jbohn/interceptor-proto/blueprint/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/TestConfigAdmin.java
Fri Oct 15 02:16:35 2010
@@ -182,7 +182,7 @@ public class TestConfigAdmin extends Abs
             mavenBundle("org.apache.aries.blueprint", "org.apache.aries.blueprint"),
             mavenBundle("org.apache.aries.blueprint", "org.apache.aries.blueprint.sample").noStart(),
             mavenBundle("org.osgi","org.osgi.compendium"),
-//            org.ops4j.pax.exam.container.def.PaxRunnerOptions.vmOption("-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005"),
+            //org.ops4j.pax.exam.container.def.PaxRunnerOptions.vmOption("-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000"),
 
             equinox().version("3.5.0")
         );

Modified: incubator/aries/sandbox/jbohn/interceptor-proto/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/AbstractIntegrationTest.java
URL: http://svn.apache.org/viewvc/incubator/aries/sandbox/jbohn/interceptor-proto/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/AbstractIntegrationTest.java?rev=1022810&r1=1022809&r2=1022810&view=diff
==============================================================================
--- incubator/aries/sandbox/jbohn/interceptor-proto/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/AbstractIntegrationTest.java
(original)
+++ incubator/aries/sandbox/jbohn/interceptor-proto/transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/AbstractIntegrationTest.java
Fri Oct 15 02:16:35 2010
@@ -52,8 +52,8 @@ import org.osgi.util.tracker.ServiceTrac
 @RunWith(JUnit4TestRunner.class)
 public abstract class AbstractIntegrationTest {
 
-    public static final long DEFAULT_TIMEOUT = 60000;
-//    public static final long DEFAULT_TIMEOUT = 0;
+//    public static final long DEFAULT_TIMEOUT = 60000;
+    public static final long DEFAULT_TIMEOUT = 0;
     
     private List<ServiceTracker> srs;
 
@@ -104,8 +104,8 @@ public abstract class AbstractIntegratio
                 mavenBundle("org.apache.aries.transaction", "org.apache.aries.transaction.testbundle"),
                 mavenBundle("org.apache.aries.transaction", "org.apache.aries.transaction.testds"),
 
-                //new VMOption( "-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000"
),
-                //new TimeoutOption( 0 ),
+                new VMOption( "-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000"
),
+                new TimeoutOption( 0 ),
 
                 equinox().version("3.5.0"));
         options = updateOptions(options);



Mime
View raw message