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/12/13 19:26:35 UTC
svn commit: r1045274 [7/7] - in
/incubator/aries/sandbox/jbohn/interceptor-proto: ./ application/
application/application-api/src/main/java/org/apache/aries/application/
application/application-api/src/main/java/org/apache/aries/application/management/...
Modified: incubator/aries/sandbox/jbohn/interceptor-proto/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/SubsystemAdmin2Test.java
URL: http://svn.apache.org/viewvc/incubator/aries/sandbox/jbohn/interceptor-proto/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/SubsystemAdmin2Test.java?rev=1045274&r1=1045273&r2=1045274&view=diff
==============================================================================
--- incubator/aries/sandbox/jbohn/interceptor-proto/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/SubsystemAdmin2Test.java (original)
+++ incubator/aries/sandbox/jbohn/interceptor-proto/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/SubsystemAdmin2Test.java Mon Dec 13 18:26:19 2010
@@ -20,7 +20,6 @@ package org.apache.aries.subsystem.itest
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
@@ -30,7 +29,6 @@ import static org.ops4j.pax.exam.CoreOpt
import static org.ops4j.pax.exam.CoreOptions.systemProperty;
import java.io.File;
-import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.net.URL;
import java.text.SimpleDateFormat;
@@ -39,8 +37,6 @@ import java.util.Currency;
import java.util.Hashtable;
import java.util.HashMap;
import java.util.Map;
-import java.util.concurrent.Future;
-import java.util.concurrent.TimeUnit;
import org.junit.Before;
@@ -49,8 +45,8 @@ import org.junit.runner.RunWith;
import org.apache.aries.subsystem.Subsystem;
import org.apache.aries.subsystem.SubsystemAdmin;
+import org.apache.aries.subsystem.scope.ScopeAdmin;
import org.apache.aries.unittest.fixture.ArchiveFixture;
-import org.apache.aries.unittest.fixture.ArchiveFixture.JarFixture;
import org.apache.aries.unittest.fixture.ArchiveFixture.ZipFixture;
import org.ops4j.pax.exam.Option;
@@ -60,8 +56,6 @@ import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.Constants;
import org.osgi.framework.ServiceReference;
-import org.osgi.framework.Version;
-import org.osgi.service.composite.CompositeAdmin;
@RunWith(JUnit4TestRunner.class)
@@ -70,171 +64,47 @@ public class SubsystemAdmin2Test extends
/* Use @Before not @BeforeClass so as to ensure that these resources
* are created in the paxweb temp directory, and not in the svn tree
*/
- static boolean createdSubsystems = false;
- static boolean createdBundles = false;
- static CompositeAdmin ca = null;
- static SubsystemAdmin sa = null;
-
+ static boolean createdApplications = false;
@Before
- public void createSubsystems() throws Exception {
- if (createdSubsystems) {
+ public static void createApplications() throws Exception {
+ if (createdApplications) {
return;
}
- createSubsystem("subsystem2/META-INF/MANIFEST.MF", "subsystem2.eba");
- createSubsystem("subsystem3/META-INF/MANIFEST.MF", "subsystem3.eba");
+ ZipFixture testEba = ArchiveFixture.newZip();
- createdSubsystems = true;
- }
-
- private Future<Subsystem> installSubsystem(String filename) throws Exception {
-
- // make sure we are using a framework that provides composite admin service
- ca = getOsgiService(CompositeAdmin.class);
- assertNotNull("Unable to get CompositeAdmin Service", ca);
- System.out.println("Able to get composite admin service");
-
- // obtain subsystem admin service
- sa = getOsgiService(SubsystemAdmin.class);
- assertNotNull("Unable to get SubsystemAdmin Service", sa);
- System.out.println("Able to get subsytem admin service");
-
- File f = new File(filename);
- return sa.install(f.toURI().toURL().toExternalForm());
- }
-
- private Future<Subsystem> updateSubsystem(Subsystem subsystem, String filename) throws Exception {
-
- // make sure we are using a framework that provides composite admin service
- ca = getOsgiService(CompositeAdmin.class);
- assertNotNull("Unable to get CompositeAdmin Service", ca);
- System.out.println("Able to get composite admin service");
-
- // obtain subsystem admin service
- sa = getOsgiService(SubsystemAdmin.class);
- assertNotNull("Unable to get SubsystemAdmin Service", sa);
- System.out.println("Able to get subsytem admin service");
-
- File f = new File(filename);
- return sa.update(subsystem, new FileInputStream(f));
- }
-
- private void createSubsystem(String manifest, String filename) throws Exception {
- ZipFixture testEba = ArchiveFixture.newZip();
-
- testEba = testEba.binary("META-INF/MANIFEST.MF",
- SubsystemAdminTest.class.getClassLoader().getResourceAsStream(manifest))
- .end();
- FileOutputStream fout = new FileOutputStream(filename);
- testEba.writeOut(fout);
- fout.close();
+ testEba = testEba.binary("META-INF/MANIFEST.MF",
+ SubsystemAdminTest.class.getClassLoader().getResourceAsStream("subsystem2/META-INF/MANIFEST.MF"))
+ .end();
+ FileOutputStream fout = new FileOutputStream("test.eba");
+ testEba.writeOut(fout);
+ fout.close();
+ createdApplications = true;
}
@Test
- public void testInstall() throws Exception {
-
- Future<Subsystem> subsystemFuture = installSubsystem("subsystem2.eba");
-
-
- // TODO: when based on ScopeAdmin we can remove this sleep. Currently
- // install of the contents is async wrt Subsystem creation so the
- // contents are note installed when we test for them unless we wait.
- Thread.sleep(10000);
-
- // Give the Future up to 10 seconds to do its thing.
- Subsystem subsystem = subsystemFuture.get(10, TimeUnit.SECONDS);
-
- assertNotNull("Subsystem should not be null", subsystem);
+ public void test() throws Exception {
+ // make sure we are using a framework that provides scope admin service
+ ScopeAdmin scopeA = getOsgiService(ScopeAdmin.class);
+ assertNotNull("scope admin should not be null", scopeA);
+ System.out.println("able to get scope admin service");
- assertTrue("Subsystem should have a unique id", subsystem.getSubsystemId() > 0);
- assertTrue(subsystem.getLocation().indexOf("subsystem2.eba") != -1);
- assertEquals("felix-file-install2", subsystem.getSymbolicName());
+ // obtain subsystem admin service
+ SubsystemAdmin sa = getOsgiService(SubsystemAdmin.class);
+ assertNotNull("subsystem admin should not be null", sa);
+ System.out.println("able to get subsytem admin service");
+
+ File f = new File("test.eba");
+ Subsystem subsystem = sa.install(f.toURI().toURL().toExternalForm());
+ assertNotNull("subsystem should not be null", subsystem);
+
+ assertTrue("subsystem should have a unique id", subsystem.getSubsystemId() > 0);
+ assertTrue(subsystem.getLocation().indexOf("test.eba") != -1);
+ assertTrue(subsystem.getSymbolicName().indexOf("felix-file-install2") != -1);
assertEquals("2.0.8", subsystem.getVersion().toString());
- Collection<Bundle> constituents = subsystem.getConstituents();
- assertEquals("check constituents' size", 1, constituents.size());
+ Collection<Bundle> bundles = subsystem.getBundles();
+ assertEquals("check bundles' size", 1, bundles.size());
-
- }
-
- @Test
- public void testUninstall() throws Exception {
-
- // Note, if the subsystem is already installed, then this is a no-op
- Future<Subsystem> subsystemFuture = installSubsystem("subsystem2.eba");
-
- // TODO: when based on ScopeAdmin we can remove this sleep. Currently
- // install of the contents is async wrt Subsystem creation so the
- // contents are note installed when we test for them unless we wait.
- Thread.sleep(10000);
-
- // Give the Future up to 10 seconds to do its thing.
- Subsystem subsystem = subsystemFuture.get(10, TimeUnit.SECONDS);
-
- assertNotNull("Subsystem should not be null", subsystem);
-
- String name = subsystem.getSymbolicName();
- Version version = subsystem.getVersion();
-
- sa.uninstall(subsystem);
-
- assertEquals("Check state is UNINSTALLED", Subsystem.State.UNINSTALLED, subsystem.getState());
-
- subsystem = sa.getSubsystem(name, version);
-
- assertNull("Returned Subsystem should be null", subsystem);
- }
-
- @Test
- public void testUpdate() throws Exception {
-
- // Note, if the subsystem is already installed, then this is a no-op
- Future<Subsystem> installFuture = installSubsystem("subsystem2.eba");
-
- // TODO: when based on ScopeAdmin we can remove this sleep. Currently
- // install of the contents is async wrt Subsystem creation so the
- // contents are note installed when we test for them unless we wait.
- Thread.sleep(10000);
-
- // Give the Future up to 10 seconds to do its thing.
- Subsystem subsystem = installFuture.get(10, TimeUnit.SECONDS);
-
- assertNotNull("Subsystem should not be null", subsystem);
-
- /*
- * Test an update that adds another bundle to the content
- */
-
- // Update the subsystem
- Future<Subsystem> updateFuture = updateSubsystem(subsystem, "subsystem3.eba");
-
- // TODO: when based on ScopeAdmin we can remove this sleep. Currently
- // install of the contents is async wrt Subsystem creation so the
- // contents are note installed when we test for them unless we wait.
- Thread.sleep(10000);
-
- // Give the Future up to 10 seconds to do its thing.
- subsystem = updateFuture.get(10, TimeUnit.SECONDS);
-
- Collection<Bundle> constituents = subsystem.getConstituents();
- assertEquals("Check constituents' size", 2, constituents.size());
-
- /*
- * Test an update that removes a bundle to the content
- */
-
- // Update the subsystem
- updateFuture = updateSubsystem(subsystem, "subsystem2.eba");
-
- // TODO: when based on ScopeAdmin we can remove this sleep. Currently
- // install of the contents is async wrt Subsystem creation so the
- // contents are note installed when we test for them unless we wait.
- Thread.sleep(10000);
-
- // Give the Future up to 10 seconds to do its thing.
- subsystem = updateFuture.get(10, TimeUnit.SECONDS);
-
- constituents = subsystem.getConstituents();
- assertEquals("Check constituents' size", 1, constituents.size());
}
@org.ops4j.pax.exam.junit.Configuration
@@ -253,20 +123,22 @@ public class SubsystemAdmin2Test extends
systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level").value("DEBUG"),
// Bundles
- mavenBundle("org.apache.aries.subsystem", "org.apache.aries.subsystem.executor"),
+ mavenBundle("org.apache.aries.subsystem", "org.apache.aries.subsystem.scope.api"),
+ mavenBundle("org.apache.aries.subsystem", "org.apache.aries.subsystem.scope.impl"),
mavenBundle("org.apache.aries.testsupport", "org.apache.aries.testsupport.unit"),
mavenBundle("org.apache.aries.application", "org.apache.aries.application.api"),
mavenBundle("org.apache.aries", "org.apache.aries.util"),
mavenBundle("org.apache.aries.application", "org.apache.aries.application.utils"),
mavenBundle("org.apache.felix", "org.apache.felix.bundlerepository"),
mavenBundle("org.apache.aries.subsystem", "org.apache.aries.subsystem.api"),
+
mavenBundle("org.apache.aries.subsystem", "org.apache.aries.subsystem.core"),
//org.ops4j.pax.exam.container.def.PaxRunnerOptions.vmOption("-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005"),
PaxRunnerOptions.rawPaxRunnerOption("config", "classpath:ss-runner.properties"),
- equinox().version("v43prototype-3.6.0.201003231329")
+ equinox().version("3.7.0.v20100910")
);
options = updateOptions(options);
return options;
Modified: incubator/aries/sandbox/jbohn/interceptor-proto/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/SubsystemAdminTest.java
URL: http://svn.apache.org/viewvc/incubator/aries/sandbox/jbohn/interceptor-proto/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/SubsystemAdminTest.java?rev=1045274&r1=1045273&r2=1045274&view=diff
==============================================================================
--- incubator/aries/sandbox/jbohn/interceptor-proto/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/SubsystemAdminTest.java (original)
+++ incubator/aries/sandbox/jbohn/interceptor-proto/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/SubsystemAdminTest.java Mon Dec 13 18:26:19 2010
@@ -47,6 +47,7 @@ import org.junit.runner.RunWith;
import org.apache.aries.subsystem.Subsystem;
import org.apache.aries.subsystem.SubsystemAdmin;
+import org.apache.aries.subsystem.scope.ScopeAdmin;
import org.apache.aries.unittest.fixture.ArchiveFixture;
import org.apache.aries.unittest.fixture.ArchiveFixture.ZipFixture;
@@ -57,7 +58,6 @@ import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.Constants;
import org.osgi.framework.ServiceReference;
-import org.osgi.service.composite.CompositeAdmin;
@RunWith(JUnit4TestRunner.class)
@@ -90,8 +90,8 @@ public class SubsystemAdminTest extends
//@Test
public void test() throws Exception {
// make sure we are using a framework that provides composite admin service
- CompositeAdmin ca = getOsgiService(CompositeAdmin.class);
- assertNotNull("composite admin should not be null", ca);
+ ScopeAdmin scopeA = getOsgiService(ScopeAdmin.class);
+ assertNotNull("composite admin should not be null", scopeA);
System.out.println("able to get composite admin service");
// obtain subsystem admin service
@@ -102,16 +102,15 @@ public class SubsystemAdminTest extends
File f = new File("test.eba");
// capture initial bundle size
int init = bundleContext.getBundles().length;
- Future<Subsystem> subsystemFuture = sa.install(f.toURI().toURL().toExternalForm());
- Subsystem subsystem = subsystemFuture.get(5, TimeUnit.SECONDS);
+ Subsystem subsystem = sa.install(f.toURI().toURL().toExternalForm());
assertNotNull("subsystem should not be null", subsystem);
assertTrue("subsystem should have a unique id", subsystem.getSubsystemId() > 0);
assertTrue(subsystem.getLocation().indexOf("test.eba") != -1);
assertEquals("felix-file-install", subsystem.getSymbolicName());
assertEquals("2.0.8", subsystem.getVersion().toString());
- Collection<Bundle> constituents = subsystem.getConstituents();
- assertEquals("check constituents' size", 1, constituents.size());
+ Collection<Bundle> bundles = subsystem.getBundles();
+ assertEquals("check constituents' size", 1, bundles.size());
// recapture bundle size
int later = bundleContext.getBundles().length;
// we expect the number would increase 4, one is composite bundle, three are the required resources of the subsystem content
@@ -141,13 +140,15 @@ public class SubsystemAdminTest extends
mavenBundle("org.apache.aries.application", "org.apache.aries.application.utils"),
mavenBundle("org.apache.felix", "org.apache.felix.bundlerepository"),
mavenBundle("org.apache.aries.subsystem", "org.apache.aries.subsystem.api"),
+ mavenBundle("org.apache.aries.subsystem", "org.apache.aries.subsystem.scope.api"),
mavenBundle("org.apache.aries.subsystem", "org.apache.aries.subsystem.core"),
+ mavenBundle("org.apache.aries.subsystem", "org.apache.aries.subsystem.scope.impl"),
//org.ops4j.pax.exam.container.def.PaxRunnerOptions.vmOption("-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005"),
PaxRunnerOptions.rawPaxRunnerOption("config", "classpath:ss-runner.properties"),
- equinox().version("v43prototype-3.6.0.201003231329")
+ equinox().version("3.7.0.v20100910")
);
options = updateOptions(options);
return options;
Modified: incubator/aries/sandbox/jbohn/interceptor-proto/subsystem/subsystem-itests/src/test/java/org/ops4j/pax/runner/platform/equinox/internal/SsActivator.java
URL: http://svn.apache.org/viewvc/incubator/aries/sandbox/jbohn/interceptor-proto/subsystem/subsystem-itests/src/test/java/org/ops4j/pax/runner/platform/equinox/internal/SsActivator.java?rev=1045274&r1=1045273&r2=1045274&view=diff
==============================================================================
--- incubator/aries/sandbox/jbohn/interceptor-proto/subsystem/subsystem-itests/src/test/java/org/ops4j/pax/runner/platform/equinox/internal/SsActivator.java (original)
+++ incubator/aries/sandbox/jbohn/interceptor-proto/subsystem/subsystem-itests/src/test/java/org/ops4j/pax/runner/platform/equinox/internal/SsActivator.java Mon Dec 13 18:26:19 2010
@@ -25,6 +25,7 @@ public class SsActivator extends Abstrac
new EquinoxPlatformBuilder( bundleContext, "3.5.1" ),
new EquinoxPlatformBuilder( bundleContext, "3.6.0" ),
new EquinoxPlatformBuilder( bundleContext, "V43PROTOTYPE-3.6.0.201003231329" ),
+ new EquinoxPlatformBuilder( bundleContext, "3.7.0.V20100910" ),
new EquinoxPlatformBuilderSnapshot( bundleContext )
};
}
Modified: incubator/aries/sandbox/jbohn/interceptor-proto/subsystem/subsystem-itests/src/test/resources/ss-runner.properties
URL: http://svn.apache.org/viewvc/incubator/aries/sandbox/jbohn/interceptor-proto/subsystem/subsystem-itests/src/test/resources/ss-runner.properties?rev=1045274&r1=1045273&r2=1045274&view=diff
==============================================================================
--- incubator/aries/sandbox/jbohn/interceptor-proto/subsystem/subsystem-itests/src/test/resources/ss-runner.properties (original)
+++ incubator/aries/sandbox/jbohn/interceptor-proto/subsystem/subsystem-itests/src/test/resources/ss-runner.properties Mon Dec 13 18:26:19 2010
@@ -64,6 +64,7 @@ platform.equinox.3.5.1=org.ops4j.pax.run
platform.equinox.3.6.0=org.ops4j.pax.runner.platform.equinox.internal.SsActivator
platform.equinox.SNAPSHOT=org.ops4j.pax.runner.platform.equinox.internal.SsActivator
platform.equinox.V43PROTOTYPE-3.6.0.201003231329=org.ops4j.pax.runner.platform.equinox.internal.SsActivator
+platform.equinox.3.7.0.V20100910=org.ops4j.pax.runner.platform.equinox.internal.SsActivator
# Felix
platform.felix.1.0.0=org.ops4j.pax.runner.platform.felix.internal.Activator
platform.felix.1.0.1=org.ops4j.pax.runner.platform.felix.internal.Activator
Modified: incubator/aries/sandbox/jbohn/interceptor-proto/subsystem/subsystem-scope-impl/pom.xml
URL: http://svn.apache.org/viewvc/incubator/aries/sandbox/jbohn/interceptor-proto/subsystem/subsystem-scope-impl/pom.xml?rev=1045274&r1=1045273&r2=1045274&view=diff
==============================================================================
--- incubator/aries/sandbox/jbohn/interceptor-proto/subsystem/subsystem-scope-impl/pom.xml (original)
+++ incubator/aries/sandbox/jbohn/interceptor-proto/subsystem/subsystem-scope-impl/pom.xml Mon Dec 13 18:26:19 2010
@@ -49,7 +49,6 @@
<dependency>
<groupId>org.apache.aries.subsystem</groupId>
<artifactId>org.apache.aries.subsystem.scope.api</artifactId>
- <version>${version}</version>
</dependency>
<dependency>
<groupId>org.apache.aries.application</groupId>
Modified: incubator/aries/sandbox/jbohn/interceptor-proto/subsystem/subsystem-scope-impl/src/main/java/org/apache/aries/subsystem/scope/impl/ScopeAdminServiceFactory.java
URL: http://svn.apache.org/viewvc/incubator/aries/sandbox/jbohn/interceptor-proto/subsystem/subsystem-scope-impl/src/main/java/org/apache/aries/subsystem/scope/impl/ScopeAdminServiceFactory.java?rev=1045274&r1=1045273&r2=1045274&view=diff
==============================================================================
--- incubator/aries/sandbox/jbohn/interceptor-proto/subsystem/subsystem-scope-impl/src/main/java/org/apache/aries/subsystem/scope/impl/ScopeAdminServiceFactory.java (original)
+++ incubator/aries/sandbox/jbohn/interceptor-proto/subsystem/subsystem-scope-impl/src/main/java/org/apache/aries/subsystem/scope/impl/ScopeAdminServiceFactory.java Mon Dec 13 18:26:19 2010
@@ -64,6 +64,7 @@ public class ScopeAdminServiceFactory im
private ServiceTracker serviceTracker;
private List<ServiceRegistration> srs = new ArrayList<ServiceRegistration>();
public static final String SERVICE_CAPABILITY = "osgi.service";
+ private ServiceRegistration rootScopeAdminserviceReg;
public void init() throws InvalidSyntaxException {
context = Activator.getBundleContext();
@@ -96,6 +97,9 @@ public class ScopeAdminServiceFactory im
});
defaultScopeAdmin = new ScopeAdminImpl(null, new ScopeImpl("root",
context));
+ rootScopeAdminserviceReg = context.registerService(ScopeAdmin.class.getName(),
+ defaultScopeAdmin,
+ DictionaryBuilder.build("ScopeName", defaultScopeAdmin.getScope().getName(), "ScopeId", defaultScopeAdmin.getScope().getId()));
admins.add(defaultScopeAdmin);
references.put(defaultScopeAdmin, new Long(0));
serviceTracker.open();
@@ -116,6 +120,10 @@ public class ScopeAdminServiceFactory im
for (ServiceRegistration sr : srs) {
sr.unregister();
}
+
+ if (rootScopeAdminserviceReg != null) {
+ rootScopeAdminserviceReg.unregister();
+ }
}
public synchronized Object getService(Bundle bundle, ServiceRegistration registration) {
Modified: incubator/aries/sandbox/jbohn/interceptor-proto/subsystem/subsystem-scope-impl/src/main/java/org/apache/aries/subsystem/scope/impl/ScopeImpl.java
URL: http://svn.apache.org/viewvc/incubator/aries/sandbox/jbohn/interceptor-proto/subsystem/subsystem-scope-impl/src/main/java/org/apache/aries/subsystem/scope/impl/ScopeImpl.java?rev=1045274&r1=1045273&r2=1045274&view=diff
==============================================================================
--- incubator/aries/sandbox/jbohn/interceptor-proto/subsystem/subsystem-scope-impl/src/main/java/org/apache/aries/subsystem/scope/impl/ScopeImpl.java (original)
+++ incubator/aries/sandbox/jbohn/interceptor-proto/subsystem/subsystem-scope-impl/src/main/java/org/apache/aries/subsystem/scope/impl/ScopeImpl.java Mon Dec 13 18:26:19 2010
@@ -182,4 +182,5 @@ public class ScopeImpl implements Scope
public String getLocation() {
return this.location;
}
+
}
Modified: incubator/aries/sandbox/jbohn/interceptor-proto/subsystem/subsystem-scope-impl/src/main/java/org/apache/aries/subsystem/scope/impl/ScopeUpdateImpl.java
URL: http://svn.apache.org/viewvc/incubator/aries/sandbox/jbohn/interceptor-proto/subsystem/subsystem-scope-impl/src/main/java/org/apache/aries/subsystem/scope/impl/ScopeUpdateImpl.java?rev=1045274&r1=1045273&r2=1045274&view=diff
==============================================================================
--- incubator/aries/sandbox/jbohn/interceptor-proto/subsystem/subsystem-scope-impl/src/main/java/org/apache/aries/subsystem/scope/impl/ScopeUpdateImpl.java (original)
+++ incubator/aries/sandbox/jbohn/interceptor-proto/subsystem/subsystem-scope-impl/src/main/java/org/apache/aries/subsystem/scope/impl/ScopeUpdateImpl.java Mon Dec 13 18:26:19 2010
@@ -18,6 +18,10 @@
*/
package org.apache.aries.subsystem.scope.impl;
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
@@ -25,6 +29,8 @@ import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
import org.apache.aries.subsystem.scope.InstallInfo;
import org.apache.aries.subsystem.scope.Scope;
@@ -34,7 +40,13 @@ import org.apache.aries.subsystem.scope.
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleException;
+import org.osgi.framework.ServiceReference;
import org.osgi.framework.ServiceRegistration;
+import org.osgi.service.condpermadmin.ConditionInfo;
+import org.osgi.service.condpermadmin.ConditionalPermissionAdmin;
+import org.osgi.service.condpermadmin.ConditionalPermissionInfo;
+import org.osgi.service.condpermadmin.ConditionalPermissionUpdate;
+import org.osgi.service.permissionadmin.PermissionInfo;
public class ScopeUpdateImpl implements ScopeUpdate {
@@ -44,6 +56,27 @@ public class ScopeUpdateImpl implements
private List<Scope> tbrChildren = new ArrayList<Scope>();
private BundleContext bc;
private static ConcurrentHashMap<Long, ServiceRegistration> srs = new ConcurrentHashMap<Long, ServiceRegistration>();
+ private final static PermissionInfo[] denyInfo =
+ {
+ new PermissionInfo("org.osgi.framework.ServicePermission", "org.osgi.service.condpermadmin.ConditionalPermissionAdmin", "*"),
+ new PermissionInfo("org.osgi.framework.ServicePermission", "org.osgi.service.permissionadmin.PermissionAdmin", "*"),
+ new PermissionInfo("org.osgi.framework.ServicePermission", "org.osgi.framework.hooks.service.*", "*"),
+ new PermissionInfo("org.osgi.framework.ServicePermission", "org.osgi.service.packageadmin.PackageAdmin", "*")
+ };
+
+ private final static PermissionInfo[] allowInfo = {
+ new PermissionInfo("org.osgi.framework.PackagePermission", "*", "import"),
+ new PermissionInfo("org.osgi.framework.BundlePermission", "*", "host,provide,fragment"),
+ };
+
+ private final static PermissionInfo[] defaultAllowInfo = {
+ new PermissionInfo("java.lang.RuntimePermission", "loadLibrary.*", "*"),
+ new PermissionInfo("java.lang.RuntimePermission", "queuePrintJob", "*"),
+ new PermissionInfo("java.net.SocketPermission", "*", "connect"),
+ new PermissionInfo("java.util.PropertyPermission", "*", "read"),
+ new PermissionInfo("org.osgi.framework.PackagePermission", "*", "exportonly,import"),
+ new PermissionInfo("org.osgi.framework.ServicePermission", "*", "get,register"),
+ };
public ScopeUpdateImpl(ScopeImpl scope, BundleContext bc) {
this.scope = scope;
@@ -69,6 +102,8 @@ public class ScopeUpdateImpl implements
public boolean commit() throws BundleException {
// process installedBundle
boolean success = false;
+ int numException = 0;
+
List<Bundle> installedBundle = new ArrayList<Bundle>();
for (InstallInfo info : this.installInfo) {
URL url = info.getContent();
@@ -83,12 +118,15 @@ public class ScopeUpdateImpl implements
}
try {
+ // prefix location with scope-scopeId:
+ loc = "scope-" + this.getScope().getId() + ": " + loc;
scope.getToBeInstalledBundleLocation().add(loc);
b = bc.installBundle(loc, url.openStream());
installedBundle.add(b);
} catch (IOException e) {
// clear bundle location off the list.
scope.getToBeInstalledBundleLocation().remove(loc);
+ numException++;
throw new BundleException("problem when opening url " + e.getCause());
}
scope.getToBeInstalledBundleLocation().remove(loc);
@@ -101,6 +139,17 @@ public class ScopeUpdateImpl implements
getBundles().addAll(installedBundle);
+ // Sets up Java 2 security permissions for the application
+ try {
+ boolean suc = setupJava2Security(scope.getLocation());
+ if (!suc) {
+ numException++;
+ }
+ } catch (BundleException ex) {
+ numException++;
+ throw ex;
+ }
+
// process child scopes
Collection<ScopeUpdate> children = getChildren();
for (ScopeUpdate child : children) {
@@ -122,6 +171,7 @@ public class ScopeUpdateImpl implements
sr.unregister();
srs.remove(scopeUpdateImpl.getScope().getId());
}
+ numException++;
throw new BundleException("problem when commiting child scope: " + child.getName() + " " + e.getCause());
}
@@ -136,10 +186,54 @@ public class ScopeUpdateImpl implements
removeChildScope(scope);
}
+ return numException == 0 ? true : false;
+ }
+
+ private boolean setupJava2Security(String location) throws BundleException {
+ // obtain security manager
+ SecurityManager secMan = System.getSecurityManager();
+
+ if (secMan == null) {
+ return true;
+ }
+
+ ServiceReference permRef = bc.getServiceReference(ConditionalPermissionAdmin.class.getName());
+
+ ConditionalPermissionAdmin permAdmin = (ConditionalPermissionAdmin) bc.getService(permRef);
+ ConditionalPermissionUpdate update = permAdmin.newConditionalPermissionUpdate();
+
+ List<ConditionalPermissionInfo> infos = update.getConditionalPermissionInfos();
+ //infos.clear();
+
+ // set up the conditionInfo
+ String scopePrefix = "scope-" + this.scope.getId() + "-*";
+ ConditionInfo[] conditionInfo = new ConditionInfo[] {new ConditionInfo("org.osgi.service.condpermadmin.BundleLocationCondition", new String[]{scopePrefix})};
+ // Set up permissions which are common to all applications
+ infos.add(permAdmin.newConditionalPermissionInfo(null, conditionInfo, denyInfo, "deny"));
+ infos.add(permAdmin.newConditionalPermissionInfo(null, conditionInfo, allowInfo, "allow"));
+
+ // exact scope permission from scope installation loc
+ // TODO: need to figure out the permFile from the scope/subsystem, META-INF/permissions.perm
+ // Also add code to handle the permission file
+ File permFile = new File("META-INF/permissions.perm");
+ if (!permFile.exists()) {
+ /*
+ * If there is no specific permissions file provided, the following
+ * default permissions are provided.
+ */
+ infos.add(permAdmin.newConditionalPermissionInfo(null, conditionInfo, defaultAllowInfo, "allow"));
+
+ }
+
+ if (!update.commit()) {
+ return false;
+ }
return true;
+
+
}
-
+
// check if the install info is already installed in the scope
private Bundle alreadyInstalled(InstallInfo info) {
String loc = info.getLocation();
Modified: incubator/aries/sandbox/jbohn/interceptor-proto/subsystem/subsystem-scope-itests/pom.xml
URL: http://svn.apache.org/viewvc/incubator/aries/sandbox/jbohn/interceptor-proto/subsystem/subsystem-scope-itests/pom.xml?rev=1045274&r1=1045273&r2=1045274&view=diff
==============================================================================
--- incubator/aries/sandbox/jbohn/interceptor-proto/subsystem/subsystem-scope-itests/pom.xml (original)
+++ incubator/aries/sandbox/jbohn/interceptor-proto/subsystem/subsystem-scope-itests/pom.xml Mon Dec 13 18:26:19 2010
@@ -51,13 +51,11 @@
<dependency>
<groupId>org.apache.aries.subsystem</groupId>
<artifactId>org.apache.aries.subsystem.scope.api</artifactId>
- <version>${version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.aries.subsystem</groupId>
<artifactId>org.apache.aries.subsystem.scope.impl</artifactId>
- <version>${version}</version>
<scope>test</scope>
</dependency>
<dependency>
@@ -137,7 +135,6 @@
<dependency>
<groupId>org.apache.aries.subsystem.example</groupId>
<artifactId>org.apache.aries.subsystem.example.helloIsolation</artifactId>
- <version>${version}</version>
<scope>test</scope>
</dependency>
</dependencies>
Modified: incubator/aries/sandbox/jbohn/interceptor-proto/testsupport/pom.xml
URL: http://svn.apache.org/viewvc/incubator/aries/sandbox/jbohn/interceptor-proto/testsupport/pom.xml?rev=1045274&r1=1045273&r2=1045274&view=diff
==============================================================================
--- incubator/aries/sandbox/jbohn/interceptor-proto/testsupport/pom.xml (original)
+++ incubator/aries/sandbox/jbohn/interceptor-proto/testsupport/pom.xml Mon Dec 13 18:26:19 2010
@@ -22,6 +22,7 @@
<groupId>org.apache.aries</groupId>
<artifactId>java5-parent</artifactId>
<version>0.3-incubating-SNAPSHOT</version>
+ <relativePath>../parent/default-parent/java5-parent/pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Modified: incubator/aries/sandbox/jbohn/interceptor-proto/testsupport/testsupport-unit/src/main/java/org/apache/aries/mocks/BundleMock.java
URL: http://svn.apache.org/viewvc/incubator/aries/sandbox/jbohn/interceptor-proto/testsupport/testsupport-unit/src/main/java/org/apache/aries/mocks/BundleMock.java?rev=1045274&r1=1045273&r2=1045274&view=diff
==============================================================================
--- incubator/aries/sandbox/jbohn/interceptor-proto/testsupport/testsupport-unit/src/main/java/org/apache/aries/mocks/BundleMock.java (original)
+++ incubator/aries/sandbox/jbohn/interceptor-proto/testsupport/testsupport-unit/src/main/java/org/apache/aries/mocks/BundleMock.java Mon Dec 13 18:26:19 2010
@@ -36,17 +36,18 @@ import java.util.regex.Pattern;
import junit.framework.AssertionFailedError;
+import org.apache.aries.unittest.mocks.MethodCall;
+import org.apache.aries.unittest.mocks.MethodCallHandler;
+import org.apache.aries.unittest.mocks.Skeleton;
+import org.apache.aries.unittest.mocks.annotations.Singleton;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleReference;
import org.osgi.framework.Constants;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceReference;
import org.osgi.framework.Version;
-import org.apache.aries.unittest.mocks.MethodCall;
-import org.apache.aries.unittest.mocks.MethodCallHandler;
-import org.apache.aries.unittest.mocks.Skeleton;
-import org.apache.aries.unittest.mocks.annotations.Singleton;
-
@Singleton
public class BundleMock
{
@@ -388,4 +389,16 @@ public class BundleMock
{
return cl;
}
+
+ // This is good enough for Mocks' needs in unit test, but isn't how it works in the real world!
+ public ServiceReference[] getRegisteredServices()
+ {
+ ServiceReference[] result = null;
+ try {
+ result = bc.getServiceReferences(null, null);
+ } catch (InvalidSyntaxException isx) {
+ // no-op: Swallow exception
+ }
+ return result;
+ }
}
\ No newline at end of file
Modified: incubator/aries/sandbox/jbohn/interceptor-proto/transaction/pom.xml
URL: http://svn.apache.org/viewvc/incubator/aries/sandbox/jbohn/interceptor-proto/transaction/pom.xml?rev=1045274&r1=1045273&r2=1045274&view=diff
==============================================================================
--- incubator/aries/sandbox/jbohn/interceptor-proto/transaction/pom.xml (original)
+++ incubator/aries/sandbox/jbohn/interceptor-proto/transaction/pom.xml Mon Dec 13 18:26:19 2010
@@ -23,10 +23,11 @@
<groupId>org.apache.aries</groupId>
<artifactId>java5-parent</artifactId>
<version>0.3-incubating-SNAPSHOT</version>
+ <relativePath>../parent/default-parent/java5-parent/pom.xml</relativePath>
</parent>
<properties>
- <geronimo-transaction-version>2.1.3</geronimo-transaction-version>
+ <geronimo-transaction-version>2.2.1</geronimo-transaction-version>
</properties>
<modelVersion>4.0.0</modelVersion>
Modified: incubator/aries/sandbox/jbohn/interceptor-proto/transaction/transaction-wrappers/src/main/java/org/apache/aries/transaction/jdbc/ConnectionWrapper.java
URL: http://svn.apache.org/viewvc/incubator/aries/sandbox/jbohn/interceptor-proto/transaction/transaction-wrappers/src/main/java/org/apache/aries/transaction/jdbc/ConnectionWrapper.java?rev=1045274&r1=1045273&r2=1045274&view=diff
==============================================================================
--- incubator/aries/sandbox/jbohn/interceptor-proto/transaction/transaction-wrappers/src/main/java/org/apache/aries/transaction/jdbc/ConnectionWrapper.java (original)
+++ incubator/aries/sandbox/jbohn/interceptor-proto/transaction/transaction-wrappers/src/main/java/org/apache/aries/transaction/jdbc/ConnectionWrapper.java Mon Dec 13 18:26:19 2010
@@ -36,11 +36,6 @@ import java.sql.Struct;
import java.util.Map;
import java.util.Properties;
-import javax.sql.XAConnection;
-import javax.transaction.Status;
-import javax.transaction.SystemException;
-import javax.transaction.Transaction;
-import javax.transaction.TransactionManager;
import javax.transaction.xa.XAResource;
/**
@@ -50,62 +45,75 @@ import javax.transaction.xa.XAResource;
* @see XADatasourceEnlistingWrapper
*/
public class ConnectionWrapper implements Connection {
+
private Connection connection;
- private XAConnection xaConnection;
+ private boolean closed;
- private TransactionManager tm;
+ private boolean enlisted;
- public ConnectionWrapper(XAConnection xaConnection, TransactionManager tm) {
- try {
- this.xaConnection = xaConnection;
- this.tm = tm;
- this.connection = xaConnection.getConnection();
+ public ConnectionWrapper(Connection connection, boolean enlisted) {
+ this.enlisted = enlisted;
+ this.connection = connection;
+ }
- if (tm.getStatus() == Status.STATUS_ACTIVE) {
- Transaction tx = tm.getTransaction();
- tx.enlistResource(xaConnection.getXAResource());
- }
- } catch (Exception e) {
- try {
- if (tm != null)
- tm.setRollbackOnly();
- } catch (IllegalStateException e1) {
- e1.printStackTrace();
- } catch (SystemException e1) {
- e1.printStackTrace();
- }
+ public void close() throws SQLException {
+ if (!closed) {
+ try {
+ // don't close connection if enlisted in a transaction
+ // the connection will be closed in once the transaction completes
+ if (!enlisted) {
+ connection.close();
+ }
+ } finally {
+ closed = true;
+ }
}
}
- public void clearWarnings() throws SQLException {
- connection.clearWarnings();
+ // cannot be used while enrolled in a transaction
+
+ public void commit() throws SQLException {
+ if (enlisted) {
+ throw new SQLException("Cannot commit while enrolled in a transaction");
+ }
+ connection.commit();
}
- public void close() throws SQLException {
- try {
- if (tm.getStatus() == Status.STATUS_ACTIVE) {
- Transaction tx = tm.getTransaction();
- tx.delistResource(xaConnection.getXAResource(), XAResource.TMSUCCESS);
- }
- } catch (Exception e) {
- try {
- if (tm != null)
- tm.setRollbackOnly();
- } catch (IllegalStateException e1) {
- e1.printStackTrace();
- } catch (SystemException e1) {
- e1.printStackTrace();
- }
+ public void rollback() throws SQLException {
+ if (enlisted) {
+ throw new SQLException("Cannot rollback while enrolled in a transaction");
}
-
- connection.close();
+ connection.rollback();
}
- public void commit() throws SQLException {
- connection.commit();
+ public void rollback(Savepoint savepoint) throws SQLException {
+ if (enlisted) {
+ throw new SQLException("Cannot rollback while enrolled in a transaction");
+ }
+ connection.rollback(savepoint);
+ }
+
+ public Savepoint setSavepoint() throws SQLException {
+ if (enlisted) {
+ throw new SQLException("Cannot set savepoint while enrolled in a transaction");
+ }
+ return connection.setSavepoint();
}
+ public Savepoint setSavepoint(String name) throws SQLException {
+ if (enlisted) {
+ throw new SQLException("Cannot set savepoint while enrolled in a transaction");
+ }
+ return connection.setSavepoint(name);
+ }
+
+ // rest of the methods
+
+ public void clearWarnings() throws SQLException {
+ connection.clearWarnings();
+ }
+
public Array createArrayOf(String typeName, Object[] elements)
throws SQLException {
return connection.createArrayOf(typeName, elements);
@@ -256,14 +264,6 @@ public class ConnectionWrapper implement
connection.releaseSavepoint(savepoint);
}
- public void rollback() throws SQLException {
- connection.rollback();
- }
-
- public void rollback(Savepoint savepoint) throws SQLException {
- connection.rollback(savepoint);
- }
-
public void setAutoCommit(boolean autoCommit) throws SQLException {
connection.setAutoCommit(autoCommit);
}
@@ -290,14 +290,6 @@ public class ConnectionWrapper implement
connection.setReadOnly(readOnly);
}
- public Savepoint setSavepoint() throws SQLException {
- return connection.setSavepoint();
- }
-
- public Savepoint setSavepoint(String name) throws SQLException {
- return connection.setSavepoint(name);
- }
-
public void setTransactionIsolation(int level) throws SQLException {
connection.setTransactionIsolation(level);
}
Modified: incubator/aries/sandbox/jbohn/interceptor-proto/transaction/transaction-wrappers/src/main/java/org/apache/aries/transaction/jdbc/XADatasourceEnlistingWrapper.java
URL: http://svn.apache.org/viewvc/incubator/aries/sandbox/jbohn/interceptor-proto/transaction/transaction-wrappers/src/main/java/org/apache/aries/transaction/jdbc/XADatasourceEnlistingWrapper.java?rev=1045274&r1=1045273&r2=1045274&view=diff
==============================================================================
--- incubator/aries/sandbox/jbohn/interceptor-proto/transaction/transaction-wrappers/src/main/java/org/apache/aries/transaction/jdbc/XADatasourceEnlistingWrapper.java (original)
+++ incubator/aries/sandbox/jbohn/interceptor-proto/transaction/transaction-wrappers/src/main/java/org/apache/aries/transaction/jdbc/XADatasourceEnlistingWrapper.java Mon Dec 13 18:26:19 2010
@@ -22,11 +22,18 @@ import java.io.PrintWriter;
import java.io.Serializable;
import java.sql.Connection;
import java.sql.SQLException;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
import javax.sql.DataSource;
import javax.sql.XAConnection;
import javax.sql.XADataSource;
+import javax.transaction.Status;
+import javax.transaction.Synchronization;
+import javax.transaction.SystemException;
+import javax.transaction.Transaction;
import javax.transaction.TransactionManager;
+import javax.transaction.xa.XAResource;
/**
* This class allows JDBC XA data sources to participate in global transactions,
@@ -44,22 +51,90 @@ public class XADatasourceEnlistingWrappe
private transient TransactionManager tm;
- public Connection getConnection() throws SQLException
- {
- XAConnection xaConn = wrappedDS.getXAConnection();
- Connection conn = getEnlistedConnection(xaConn);
-
- return conn;
+ private transient Map<Object, Connection> connectionMap =
+ new ConcurrentHashMap<Object, Connection>();
+
+ public Connection getConnection() throws SQLException {
+ Transaction transaction = getTransaction();
+ if (transaction != null) {
+ Object key = transaction;
+ Connection connection = connectionMap.get(key);
+ if (connection == null) {
+ XAConnection xaConnection = wrappedDS.getXAConnection();
+ connection = xaConnection.getConnection();
+ enlist(transaction, xaConnection.getXAResource(), key);
+ connectionMap.put(key, connection);
+ }
+ return getEnlistedConnection(connection, true);
+ } else {
+ return getEnlistedConnection(wrappedDS.getXAConnection().getConnection(), false);
+ }
+ }
+
+ public Connection getConnection(String username, String password) throws SQLException {
+ Transaction transaction = getTransaction();
+ if (transaction != null) {
+ Object key = new ConnectionKey(username, password, transaction);
+ Connection connection = connectionMap.get(key);
+ if (connection == null) {
+ XAConnection xaConnection = wrappedDS.getXAConnection(username, password);
+ connection = xaConnection.getConnection();
+ enlist(transaction, xaConnection.getXAResource(), key);
+ connectionMap.put(key, connection);
+ }
+ return getEnlistedConnection(connection, true);
+ } else {
+ return getEnlistedConnection(wrappedDS.getXAConnection(username, password).getConnection(), false);
+ }
+ }
+
+ private Transaction getTransaction() throws SQLException {
+ try {
+ return (tm.getStatus() == Status.STATUS_ACTIVE) ? tm.getTransaction() : null;
+ } catch (SystemException e) {
+ throw new SQLException("Error getting transaction");
+ }
}
-
- public Connection getConnection(String username, String password) throws SQLException
- {
- XAConnection xaConn = wrappedDS.getXAConnection(username, password);
- Connection conn = getEnlistedConnection(xaConn);
-
- return conn;
+
+ private void enlist(Transaction transaction, XAResource xaResource, Object key) throws SQLException {
+ try {
+ transaction.enlistResource(xaResource);
+ transaction.registerSynchronization(new TransactionListener(key));
+ } catch (Exception e) {
+ try {
+ tm.setRollbackOnly();
+ } catch (IllegalStateException e1) {
+ e1.printStackTrace();
+ } catch (SystemException e1) {
+ e1.printStackTrace();
+ }
+ }
}
+
+ private class TransactionListener implements Synchronization {
+ private final Object key;
+
+ public TransactionListener(Object key) {
+ this.key = key;
+ }
+
+ public void afterCompletion(int status) {
+ Connection connection = connectionMap.remove(key);
+ if (connection != null) {
+ try {
+ connection.close();
+ } catch (SQLException e) {
+ // ignore
+ }
+ }
+ }
+
+ public void beforeCompletion() {
+ }
+
+ }
+
public PrintWriter getLogWriter() throws SQLException
{
return wrappedDS.getLogWriter();
@@ -80,9 +155,9 @@ public class XADatasourceEnlistingWrappe
wrappedDS.setLoginTimeout(seconds);
}
- private Connection getEnlistedConnection(XAConnection xaConn) throws SQLException
+ private Connection getEnlistedConnection(Connection connection, boolean enlisted) throws SQLException
{
- return new ConnectionWrapper(xaConn, tm);
+ return new ConnectionWrapper(connection, enlisted);
}
public void setDataSource(XADataSource dsToWrap)
Modified: incubator/aries/sandbox/jbohn/interceptor-proto/util/pom.xml
URL: http://svn.apache.org/viewvc/incubator/aries/sandbox/jbohn/interceptor-proto/util/pom.xml?rev=1045274&r1=1045273&r2=1045274&view=diff
==============================================================================
--- incubator/aries/sandbox/jbohn/interceptor-proto/util/pom.xml (original)
+++ incubator/aries/sandbox/jbohn/interceptor-proto/util/pom.xml Mon Dec 13 18:26:19 2010
@@ -22,6 +22,7 @@
<groupId>org.apache.aries</groupId>
<artifactId>java5-parent</artifactId>
<version>0.3-incubating-SNAPSHOT</version>
+ <relativePath>../parent/default-parent/java5-parent/pom.xml</relativePath>
</parent>
<artifactId>org.apache.aries.util</artifactId>
Modified: incubator/aries/sandbox/jbohn/interceptor-proto/util/src/main/java/org/apache/aries/util/SingleServiceTracker.java
URL: http://svn.apache.org/viewvc/incubator/aries/sandbox/jbohn/interceptor-proto/util/src/main/java/org/apache/aries/util/SingleServiceTracker.java?rev=1045274&r1=1045273&r2=1045274&view=diff
==============================================================================
--- incubator/aries/sandbox/jbohn/interceptor-proto/util/src/main/java/org/apache/aries/util/SingleServiceTracker.java (original)
+++ incubator/aries/sandbox/jbohn/interceptor-proto/util/src/main/java/org/apache/aries/util/SingleServiceTracker.java Mon Dec 13 18:26:19 2010
@@ -48,10 +48,14 @@ public final class SingleServiceTracker<
{
public void serviceChanged(ServiceEvent event)
{
- if (open.get() && event.getType() == ServiceEvent.UNREGISTERING) {
- ServiceReference deadRef = event.getServiceReference();
- if (deadRef.equals(ref.get())) {
- findMatchingReference(deadRef);
+ if (open.get()) {
+ if (event.getType() == ServiceEvent.UNREGISTERING) {
+ ServiceReference deadRef = event.getServiceReference();
+ if (deadRef.equals(ref.get())) {
+ findMatchingReference(deadRef);
+ }
+ } else if (event.getType() == ServiceEvent.REGISTERED && ref.get() == null) {
+ findMatchingReference(null);
}
}
}
@@ -112,7 +116,17 @@ public final class SingleServiceTracker<
boolean result = false;
int foundLostReplaced = -1;
- synchronized (newRef) {
+ // Make sure we don't try to get a lock on null
+ Object lock;
+
+ // we have to choose our lock.
+ if (newRef != null) lock = newRef;
+ else if (deadRef != null) lock = deadRef;
+ else lock = this;
+
+ // This lock is here to ensure that no two threads can set the ref and service
+ // at the same time.
+ synchronized (lock) {
if (open.get()) {
result = this.ref.compareAndSet(deadRef, newRef);
if (result) {
Modified: incubator/aries/sandbox/jbohn/interceptor-proto/web/pom.xml
URL: http://svn.apache.org/viewvc/incubator/aries/sandbox/jbohn/interceptor-proto/web/pom.xml?rev=1045274&r1=1045273&r2=1045274&view=diff
==============================================================================
--- incubator/aries/sandbox/jbohn/interceptor-proto/web/pom.xml (original)
+++ incubator/aries/sandbox/jbohn/interceptor-proto/web/pom.xml Mon Dec 13 18:26:19 2010
@@ -21,6 +21,7 @@
<artifactId>java5-parent</artifactId>
<groupId>org.apache.aries</groupId>
<version>0.3-incubating-SNAPSHOT</version>
+ <relativePath>../parent/default-parent/java5-parent/pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>