You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aries.apache.org by li...@apache.org on 2010/09/21 14:53:49 UTC
svn commit: r999377 - in /incubator/aries/trunk/blueprint:
blueprint-core/src/main/java/org/apache/aries/blueprint/container/ServiceRecipe.java
blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/QuiesceBlueprintTest.java
pom.xml
Author: linsun
Date: Tue Sep 21 12:53:48 2010
New Revision: 999377
URL: http://svn.apache.org/viewvc?rev=999377&view=rev
Log:
ARIES-412 FinalModifierExceptions as a result of Quiesce changes to add proxies for services. Thanks Hannah. Also moved blueprint annotation itests to run after regular itest
Modified:
incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/ServiceRecipe.java
incubator/aries/trunk/blueprint/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/QuiesceBlueprintTest.java
incubator/aries/trunk/blueprint/pom.xml
Modified: incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/ServiceRecipe.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/ServiceRecipe.java?rev=999377&r1=999376&r2=999377&view=diff
==============================================================================
--- incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/ServiceRecipe.java (original)
+++ incubator/aries/trunk/blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/ServiceRecipe.java Tue Sep 21 12:53:48 2010
@@ -61,6 +61,8 @@ import org.slf4j.LoggerFactory;
public class ServiceRecipe extends AbstractRecipe {
private static final Logger LOGGER = LoggerFactory.getLogger(ServiceRecipe.class);
+ final static String LOG_ENTRY = "Method entry: {}, args {}";
+ final static String LOG_EXIT = "Method exit: {}, returning {}";
private final ExtendedBlueprintContainer blueprintContainer;
private final ServiceMetadata metadata;
@@ -407,84 +409,96 @@ public class ServiceRecipe extends Abstr
private QuiesceInterceptor interceptor;
private ServiceRecipe serviceRecipe;
private ComponentMetadata cm;
- public TriggerServiceFactory(ServiceRecipe serviceRecipe, ComponentMetadata cm)
+ private ServiceMetadata sm;
+ public TriggerServiceFactory(ServiceRecipe serviceRecipe, ServiceMetadata cm)
{
this.serviceRecipe = serviceRecipe;
this.cm = cm;
+ this.sm = cm;
}
- public Object getService(Bundle bundle, ServiceRegistration registration)
- {
- Object original = ServiceRecipe.this.getService(bundle, registration);
- Object intercepted = null;
+ public Object getService(Bundle bundle, ServiceRegistration registration) {
+ Object original = ServiceRecipe.this.getService(bundle,
+ registration);
+ LOGGER.debug(LOG_ENTRY, "getService", original);
+ Object intercepted = null;
boolean asmAvailable = false;
boolean cglibAvailable = false;
-
- if (interceptor == null)
- {
- interceptor = new QuiesceInterceptor(serviceRecipe);
+
+ if (interceptor == null) {
+ interceptor = new QuiesceInterceptor(serviceRecipe);
}
-
+
List<Interceptor> interceptors = new ArrayList<Interceptor>();
interceptors.add(interceptor);
-
- try
- {
+
+ try {
// Try load load an asm class (to make sure it's actually
// available)
getClass().getClassLoader().loadClass(
"org.objectweb.asm.ClassVisitor");
LOGGER.debug("asm available for interceptors");
asmAvailable = true;
- }
- catch (Throwable t)
- {
- try
- {
+ } catch (Throwable t) {
+ try {
// Try load load a cglib class (to make sure it's actually
// available)
getClass().getClassLoader().loadClass(
"net.sf.cglib.proxy.Enhancer");
cglibAvailable = true;
- }
- catch (Throwable u)
- {
- LOGGER.info("No quiesce support is available, so blueprint components will not participate in quiesce operations");
- return original;
+ } catch (Throwable u) {
+ LOGGER
+ .info("A problem occurred trying to create a proxy object. Returning the original object instead.");
+ LOGGER.debug(LOG_EXIT, "getService", original);
+ return original;
}
}
-
- try
- {
- if (asmAvailable)
- {
- // if asm is available we can proxy the original object with the
- // AsmInterceptorWrapper
- intercepted = AsmInterceptorWrapper.createProxyObject(original
- .getClass().getClassLoader(), cm, interceptors,
- original, original.getClass());
- }
- else if (cglibAvailable)
- {
- LOGGER.debug("cglib available for interceptors");
- // otherwise we're using cglib and need to use the interfaces
- // with the CgLibInterceptorWrapper
- intercepted = CgLibInterceptorWrapper.createProxyObject(
- original.getClass().getClassLoader(), cm,
- interceptors, original, original.getClass()
- .getInterfaces());
- }
- else
- {
- return original;
- }
- }
- catch (Throwable u)
- {
- LOGGER.info("No quiesce support is available, so blueprint components will not participate in quiesce operations");
- return original;
+
+ try {
+ if (asmAvailable) {
+ List<String> interfaces = sm.getInterfaces();
+
+ // check for the case where interfaces is null or empty
+ if (interfaces == null || interfaces.isEmpty()) {
+ intercepted = AsmInterceptorWrapper.createProxyObject(
+ original.getClass().getClassLoader(), cm,
+ interceptors, original, original.getClass());
+ LOGGER.debug(LOG_EXIT, "getService", intercepted);
+ return intercepted;
+ }
+ Class[] classesToProxy = new Class[interfaces.size()];
+ for (int i = 0; i < interfaces.size(); i++) {
+ classesToProxy[i] = Class.forName(interfaces.get(i),
+ true, original.getClass().getClassLoader());
+ }
+
+ // if asm is available we can proxy the original object with
+ // the
+ // AsmInterceptorWrapper
+ intercepted = AsmInterceptorWrapper.createProxyObject(
+ original.getClass().getClassLoader(), cm,
+ interceptors, original, classesToProxy);
+ } else if (cglibAvailable) {
+ LOGGER.debug("cglib available for interceptors");
+ // otherwise we're using cglib and need to use the
+ // interfaces
+ // with the CgLibInterceptorWrapper
+ intercepted = CgLibInterceptorWrapper.createProxyObject(
+ original.getClass().getClassLoader(), cm,
+ interceptors, original, original.getClass()
+ .getInterfaces());
+ } else {
+ LOGGER.debug(LOG_EXIT, "getService", original);
+ return original;
+ }
+ } catch (Throwable u) {
+ LOGGER
+ .info("A problem occurred trying to create a proxy object. Returning the original object instead.");
+ LOGGER.debug(LOG_EXIT, "getService", original);
+ return original;
}
-
+
+ LOGGER.debug(LOG_EXIT, "getService", intercepted);
return intercepted;
}
Modified: incubator/aries/trunk/blueprint/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/QuiesceBlueprintTest.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/blueprint/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/QuiesceBlueprintTest.java?rev=999377&r1=999376&r2=999377&view=diff
==============================================================================
--- incubator/aries/trunk/blueprint/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/QuiesceBlueprintTest.java (original)
+++ incubator/aries/trunk/blueprint/blueprint-itests/src/test/java/org/apache/aries/blueprint/itests/QuiesceBlueprintTest.java Tue Sep 21 12:53:48 2010
@@ -118,7 +118,7 @@ public class QuiesceBlueprintTest extend
mavenBundle("org.apache.aries.blueprint", "org.apache.aries.blueprint.testbundlea").noStart(),
mavenBundle("org.apache.aries.blueprint", "org.apache.aries.blueprint.testbundleb").noStart(),
mavenBundle("org.apache.aries.blueprint", "org.apache.aries.blueprint.testquiescebundle"),
- mavenBundle("org.apache.aries.blueprint", "org.apache.aries.blueprint.cm"),
+ //mavenBundle("org.apache.aries.blueprint", "org.apache.aries.blueprint.cm"),
mavenBundle("org.osgi", "org.osgi.compendium"),
//new VMOption( "-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000" ),
@@ -157,65 +157,6 @@ public class QuiesceBlueprintTest extend
.versionAsInProject();
}
- protected static Option[] updateOptions(Option[] options) {
- // We need to add pax-exam-junit here when running with the ibm
- // jdk to avoid the following exception during the test run:
- // ClassNotFoundException: org.ops4j.pax.exam.junit.Configuration
- if ("IBM Corporation".equals(System.getProperty("java.vendor"))) {
- Option[] ibmOptions = options(wrappedBundle(mavenBundle(
- "org.ops4j.pax.exam", "pax-exam-junit")));
- options = combine(ibmOptions, options);
- }
-
- return options;
- }
-
- protected <T> T getOsgiService(Class<T> type, long timeout) {
- return getOsgiService(type, null, timeout);
- }
-
- protected <T> T getOsgiService(Class<T> type) {
- return getOsgiService(type, null, DEFAULT_TIMEOUT);
- }
-
- protected <T> T getOsgiService(Class<T> type, String filter, long timeout) {
- return getOsgiService(null, type, filter, timeout);
- }
-
- protected <T> T getOsgiService(BundleContext bc, Class<T> type,
- String filter, long timeout) {
- ServiceTracker tracker = null;
- try {
- String flt;
- if (filter != null) {
- if (filter.startsWith("(")) {
- flt = "(&(" + Constants.OBJECTCLASS + "=" + type.getName() + ")"
- + filter + ")";
- } else {
- flt = "(&(" + Constants.OBJECTCLASS + "=" + type.getName() + ")("
- + filter + "))";
- }
- } else {
- flt = "(" + Constants.OBJECTCLASS + "=" + type.getName() + ")";
- }
- Filter osgiFilter = FrameworkUtil.createFilter(flt);
- tracker = new ServiceTracker(bc == null ? bundleContext : bc, osgiFilter,
- null);
- tracker.open();
- // Note that the tracker is not closed to keep the reference
- // This is buggy, has the service reference may change i think
- Object svc = type.cast(tracker.waitForService(timeout));
- if (svc == null) {
- throw new RuntimeException("Gave up waiting for service " + flt);
- }
- return type.cast(svc);
- } catch (InvalidSyntaxException e) {
- throw new IllegalArgumentException("Invalid filter", e);
- } catch (InterruptedException e) {
- throw new RuntimeException(e);
- }
- }
-
@Test
public void testBasicQuieseEmptyCounter() throws Exception
{
@@ -366,6 +307,7 @@ public class QuiesceBlueprintTest extend
Thread t = new Thread(new TestBeanClient((TestBean)obj, 1500));
t.start();
+ Thread.sleep(200);
participant.quiesce(callback, bundles);
Modified: incubator/aries/trunk/blueprint/pom.xml
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/blueprint/pom.xml?rev=999377&r1=999376&r2=999377&view=diff
==============================================================================
--- incubator/aries/trunk/blueprint/pom.xml (original)
+++ incubator/aries/trunk/blueprint/pom.xml Tue Sep 21 12:53:48 2010
@@ -194,11 +194,11 @@
<module>blueprint-annotation-api</module>
<module>blueprint-annotation-impl</module>
<module>blueprint-sample-annotation</module>
- <module>blueprint-annotation-itest</module>
<module>blueprint-testbundlea</module>
<module>blueprint-testbundleb</module>
<module>blueprint-testquiescebundle</module>
<module>blueprint-itests</module>
+ <module>blueprint-annotation-itest</module>
</modules>
</project>