You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aries.apache.org by jb...@apache.org on 2010/10/15 21:14:39 UTC
svn commit: r1023075 - in /incubator/aries/sandbox/jbohn/interceptor-proto:
blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/utils/
transaction/transaction-itests/src/test/java/org/apache/aries/transaction/itests/
Author: jbohn
Date: Fri Oct 15 19:14:39 2010
New Revision: 1023075
URL: http://svn.apache.org/viewvc?rev=1023075&view=rev
Log:
ARIES-420 brute force fix for finding appropriate service references and therefore supporting multiple interceptors per bean
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/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=1023075&r1=1023074&r2=1023075&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 19:14:39 2010
@@ -34,11 +34,7 @@ import org.apache.aries.blueprint.PassTh
import org.apache.aries.blueprint.reflect.ReferenceMetadataImpl;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
-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;
@@ -86,38 +82,35 @@ public class InterceptorManager {
BundleContext bundleContext = bundle.getBundleContext();
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);
+ LOGGER.debug("addInterceptorForBean about to register interceptor service with properties {}", properties);
+ 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);
+ String id = pc.generateId();
+ String filter = FILTER_START +
+ FILTER_AND +
+ FILTER_START +
+ BUNDLE_ID + "=" + bundleId +
+ FILTER_END +
+ FILTER_START +
+ BEAN + "=" + beanId +
+ FILTER_END +
+ 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);
+
+ 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 );
@@ -135,55 +128,25 @@ public class InterceptorManager {
List<Interceptor> interceptorList = null;
- //setup dictionary for Interceptor Filter check
- Dictionary properties = new Hashtable();
- properties.put(BEAN, beanId);
- BundleContext bundleContext = blueprintContainer.getBundleContext();
- Bundle bundle = bundleContext.getBundle();
- if (bundle != null) {
- long bundleId = bundle.getBundleId();
-
- LOGGER.debug("getInterceptorsForBean searching for interceptors for bundle {} bean ", bundleId, beanId);
+ LOGGER.debug("getInterceptorsForBean searching for interceptors for bean {} ", beanId);
- properties.put(BUNDLE_ID, bundleId);
-
- //Look up all interceptors that match the filter for this bundle/bean
- //@JAB TODO: This filter should be sufficient for lookup but at the moment the comparison
- // requires an exact match and so the filter created on the reference is not complete
- String filter = FILTER_START +
- FILTER_AND +
- FILTER_START +
- BUNDLE_ID + "=" + bundleId +
- FILTER_END +
- FILTER_START +
- BEAN + "=" + beanId +
- FILTER_END +
- FILTER_END;
-
- //Get interceptor references from service reference elements and then get the component instance
- for (ReferenceMetadataImpl interceptorRefMetadata : blueprintContainer.getMetadata(ReferenceMetadataImpl.class)) {
- Class interfaceClass = interceptorRefMetadata.getRuntimeInterface();
- if ((interfaceClass!=null) && (interfaceClass.equals(Interceptor.class))) {
- try {
- if (interceptorRefMetadata.getFilter()!=null) {
- Filter filterObj = blueprintContainer.getBundleContext().createFilter(interceptorRefMetadata.getFilter());
- if (filterObj.match(properties)) {
- LOGGER.debug("getInterceptorsForBean matching reference found, about to get instance {}", interceptorRefMetadata);
- Interceptor interceptor = (Interceptor) blueprintContainer.getComponentInstance(interceptorRefMetadata.getId());
- if(interceptorList==null) interceptorList = new ArrayList<Interceptor>();
- //@JAB TODO: Need to order filters by service rank
- interceptorList.add(interceptor);
- }
- }
- } catch (InvalidSyntaxException ise) {
- LOGGER.debug("getInterceptorsForBean InvalidSyntaxException using filter {}", filter, ise);
- }
- }
- }
- }
- else {
- LOGGER.debug("getInterceptorsForBean bundle is null - can not locate interceptors");
- }
+ //Get interceptor references for this bean from service reference elements
+ //use the service reference to get the service component instance
+ for (ReferenceMetadataImpl interceptorRefMetadata : blueprintContainer.getMetadata(ReferenceMetadataImpl.class)) {
+ Class interfaceClass = interceptorRefMetadata.getRuntimeInterface();
+ if ((interfaceClass!=null) && (interfaceClass.equals(Interceptor.class))) {
+ String refFilter = interceptorRefMetadata.getFilter();
+ if (refFilter != null) {
+ if (refFilter.contains(FILTER_START + BEAN + "=" + beanId + FILTER_END)) {
+ LOGGER.debug("getInterceptorsForBean matching reference found, about to get instance {}", interceptorRefMetadata);
+ Interceptor interceptor = (Interceptor) blueprintContainer.getComponentInstance(interceptorRefMetadata.getId());
+ if(interceptorList==null) interceptorList = new ArrayList<Interceptor>();
+ //@JAB TODO: Need to order filters by service rank
+ interceptorList.add(interceptor);
+ }
+ }
+ }
+ }
return interceptorList;
}
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=1023075&r1=1023074&r2=1023075&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 19:14:39 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);