[jboss-cvs] JBossAS SVN: r97898 - in projects/jboss-osgi/projects/runtime/framework/trunk/src: main/java/org/jboss/osgi/framework/deployers and 2 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Dec 16 10:56:20 EST 2009
Author: thomas.diesler at jboss.com
Date: 2009-12-16 10:56:20 -0500 (Wed, 16 Dec 2009)
New Revision: 97898
Modified:
projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/AbstractBundleState.java
projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleContextWrapper.java
projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java
projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleState.java
projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/deployers/OSGiBundleActivatorDeployer.java
projects/jboss-osgi/projects/runtime/framework/trunk/src/test/java/org/jboss/test/osgi/bundle/BundleContextUnitTestCase.java
projects/jboss-osgi/projects/runtime/framework/trunk/src/test/resources/bootstrap/jboss-osgi-bootstrap.xml
Log:
Fix exception handling in BundleActivator.stop()
Fix BundleContext reuse issue
Fix SystemBundle storage area location
Modified: projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/AbstractBundleState.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/AbstractBundleState.java 2009-12-16 15:46:19 UTC (rev 97897)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/AbstractBundleState.java 2009-12-16 15:56:20 UTC (rev 97898)
@@ -166,6 +166,8 @@
public synchronized void destroyBundleContext()
{
+ if (bundleContext != null)
+ ((OSGiBundleContextWrapper)bundleContext).destroyBundleContext();
bundleContext = null;
}
@@ -689,16 +691,12 @@
/**
* Check a bundle context is still valid
- *
- * @return the bundle context
- * @throws IllegalArgumentException when the context is no longer valid
+ * @throws IllegalStateException when the context is no longer valid
*/
- protected synchronized BundleContext checkValidBundleContext()
+ protected synchronized void checkValidBundleContext()
{
- BundleContext result = this.bundleContext;
- if (result == null)
- throw new IllegalStateException("Bundle context is no longer valid: " + getCanonicalName());
- return result;
+ if (bundleContext == null)
+ throw new IllegalStateException("Invalid bundle context: " + getCanonicalName());
}
/**
Modified: projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleContextWrapper.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleContextWrapper.java 2009-12-16 15:46:19 UTC (rev 97897)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleContextWrapper.java 2009-12-16 15:56:20 UTC (rev 97898)
@@ -21,6 +21,8 @@
*/
package org.jboss.osgi.framework.bundle;
+// $Id: $
+
import java.io.File;
import java.io.InputStream;
import java.util.Dictionary;
@@ -38,15 +40,18 @@
import org.osgi.framework.ServiceRegistration;
/**
- * OSGiBundleContextImpl.
+ * A wrapper around the bundle state that just exposes the BundleContext API.
*
* @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @author Thomas.Diesler at jboss.com
* @version $Revision: 1.1 $
*/
public class OSGiBundleContextWrapper implements BundleContext
{
/** The bundle state */
private AbstractBundleState bundleState;
+ /** The bundles canonical name */
+ private String canonicalName;
/**
* Create a new OSGiBundleContextWrapper.
@@ -58,129 +63,169 @@
{
if (bundleState == null)
throw new IllegalArgumentException("Null bundle state");
+
this.bundleState = bundleState;
+ this.canonicalName = bundleState.getCanonicalName();
}
+ void destroyBundleContext()
+ {
+ bundleState = null;
+ }
+
public void addBundleListener(BundleListener listener)
{
+ checkValidBundleContext();
bundleState.addBundleListener(listener);
}
public void addFrameworkListener(FrameworkListener listener)
{
+ checkValidBundleContext();
bundleState.addFrameworkListener(listener);
}
public void addServiceListener(ServiceListener listener, String filter) throws InvalidSyntaxException
{
+ checkValidBundleContext();
bundleState.addServiceListener(listener, filter);
}
public void addServiceListener(ServiceListener listener)
{
+ checkValidBundleContext();
bundleState.addServiceListener(listener);
}
public Filter createFilter(String filter) throws InvalidSyntaxException
{
+ checkValidBundleContext();
return bundleState.createFilter(filter);
}
public ServiceReference[] getAllServiceReferences(String clazz, String filter) throws InvalidSyntaxException
{
+ checkValidBundleContext();
return bundleState.getAllServiceReferences(clazz, filter);
}
public Bundle getBundle()
{
+ checkValidBundleContext();
return bundleState.getBundle();
}
public Bundle getBundle(long id)
{
+ checkValidBundleContext();
return bundleState.getBundle(id);
}
public Bundle[] getBundles()
{
+ checkValidBundleContext();
return bundleState.getBundles();
}
public File getDataFile(String filename)
{
+ checkValidBundleContext();
return bundleState.getDataFile(filename);
}
public String getProperty(String key)
{
+ checkValidBundleContext();
return bundleState.getProperty(key);
}
public Object getService(ServiceReference reference)
{
+ checkValidBundleContext();
return bundleState.getService(reference);
}
public ServiceReference getServiceReference(String clazz)
{
+ checkValidBundleContext();
return bundleState.getServiceReference(clazz);
}
public ServiceReference[] getServiceReferences(String clazz, String filter) throws InvalidSyntaxException
{
+ checkValidBundleContext();
return bundleState.getServiceReferences(clazz, filter);
}
public Bundle installBundle(String location, InputStream input) throws BundleException
{
+ checkValidBundleContext();
return bundleState.installBundle(location, input);
}
public Bundle installBundle(String location) throws BundleException
{
+ checkValidBundleContext();
return bundleState.installBundle(location);
}
public Bundle install(VirtualFile root) throws BundleException
{
+ checkValidBundleContext();
return bundleState.installBundle(root);
}
- @SuppressWarnings("unchecked")
+ @SuppressWarnings("rawtypes")
public ServiceRegistration registerService(String clazz, Object service, Dictionary properties)
{
+ checkValidBundleContext();
return bundleState.registerService(clazz, service, properties);
}
- @SuppressWarnings("unchecked")
+ @SuppressWarnings("rawtypes")
public ServiceRegistration registerService(String[] clazzes, Object service, Dictionary properties)
{
+ checkValidBundleContext();
return bundleState.registerService(clazzes, service, properties);
}
public void removeBundleListener(BundleListener listener)
{
+ checkValidBundleContext();
bundleState.removeBundleListener(listener);
}
public void removeFrameworkListener(FrameworkListener listener)
{
+ checkValidBundleContext();
bundleState.removeFrameworkListener(listener);
}
public void removeServiceListener(ServiceListener listener)
{
+ checkValidBundleContext();
bundleState.removeServiceListener(listener);
}
public boolean ungetService(ServiceReference reference)
{
+ checkValidBundleContext();
return bundleState.ungetService(reference);
}
@Override
public String toString()
{
- return bundleState.toString();
+ return canonicalName;
}
+
+ /**
+ * Check a bundle context is still valid
+ * @throws IllegalStateException when the context is no longer valid
+ */
+ protected synchronized void checkValidBundleContext()
+ {
+ if (bundleState == null)
+ throw new IllegalStateException("Invalid bundle context: " + canonicalName);
+ }
}
Modified: projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java 2009-12-16 15:46:19 UTC (rev 97897)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java 2009-12-16 15:56:20 UTC (rev 97898)
@@ -1269,6 +1269,13 @@
DeploymentUnit unit = bundleState.getDeploymentUnit();
deployerClient.change(unit.getName(), DeploymentStages.CLASSLOADER);
deployerClient.checkComplete(unit.getName());
+
+ // The potential BundleException is attached by the OSGiBundleActivatorDeployer
+ BundleException stopEx = unit.removeAttachment(BundleException.class);
+ if (stopEx != null)
+ {
+ throw stopEx;
+ }
}
catch (DeploymentException ex)
{
Modified: projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleState.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleState.java 2009-12-16 15:46:19 UTC (rev 97897)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleState.java 2009-12-16 15:56:20 UTC (rev 97898)
@@ -324,11 +324,11 @@
// Any listeners registered by this bundle must be removed.
stopInternal();
+ // This bundle's state is set to RESOLVED
+ // A bundle event of type BundleEvent.STOPPED is fired
destroyBundleContext();
changeState(RESOLVED);
- // A bundle event of type BundleEvent.STOPPED is fired
-
if (t instanceof BundleException)
throw (BundleException)t;
@@ -400,14 +400,10 @@
throw new BundleException("Bundle uninstalled during activator stop: " + this);
// This bundle's state is set to RESOLVED
+ // A bundle event of type BundleEvent.STOPPED is fired
destroyBundleContext();
changeState(RESOLVED);
- if (priorState != STOPPING)
- throw new BundleException("Bundle has been uninstalled: " + getCanonicalName());
-
- // [TODO] A bundle event of type BundleEvent.STOPPED is fired
-
if (rethrow != null)
throw new BundleException("Error during stop of bundle: " + this, rethrow);
}
Modified: projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/deployers/OSGiBundleActivatorDeployer.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/deployers/OSGiBundleActivatorDeployer.java 2009-12-16 15:46:19 UTC (rev 97897)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/deployers/OSGiBundleActivatorDeployer.java 2009-12-16 15:56:20 UTC (rev 97898)
@@ -52,22 +52,25 @@
catch (BundleException ex)
{
// We do not rethrow this exception to the deployer framework.
- // An exception during Bundle.start() is regarded as a normal deployemtn condition and handeled internally by the OSGi layer.
+ // An exception during Bundle.start() is regarded as a normal deployment condition and handeled internally by the OSGi layer.
// The OSGiBundleManager picks up this BundleException and rethrows it if available.
unit.addAttachment(BundleException.class, ex);
}
}
@Override
- public void undeploy(DeploymentUnit unit, OSGiBundleState deployment)
+ public void undeploy(DeploymentUnit unit, OSGiBundleState bundleState)
{
try
{
- deployment.stopInternal();
+ bundleState.stopInternal();
}
catch (BundleException ex)
{
- log.warn("Error stopping bundle: " + deployment, ex);
+ // We do not rethrow this exception to the deployer framework.
+ // An exception during Bundle.start() is regarded as a normal deployment condition and handeled internally by the OSGi layer.
+ // The OSGiBundleManager picks up this BundleException and rethrows it if available.
+ unit.addAttachment(BundleException.class, ex);
}
}
}
Modified: projects/jboss-osgi/projects/runtime/framework/trunk/src/test/java/org/jboss/test/osgi/bundle/BundleContextUnitTestCase.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/test/java/org/jboss/test/osgi/bundle/BundleContextUnitTestCase.java 2009-12-16 15:46:19 UTC (rev 97897)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/test/java/org/jboss/test/osgi/bundle/BundleContextUnitTestCase.java 2009-12-16 15:56:20 UTC (rev 97898)
@@ -298,49 +298,49 @@
}
bundleContext.addServiceListener(this);
- bundleContext = assertServiceLifecycle(bundle, bundleContext, true);
+ bundleContext = assertServiceLifecycle(bundle, true);
bundleContext.removeServiceListener(this);
bundleContext.addServiceListener(this);
bundleContext.removeServiceListener(this);
- bundleContext = assertServiceLifecycle(bundle, bundleContext, false);
+ bundleContext = assertServiceLifecycle(bundle, false);
bundleContext.addServiceListener(this);
bundleContext.addServiceListener(this);
- bundleContext = assertServiceLifecycle(bundle, bundleContext, true);
+ bundleContext = assertServiceLifecycle(bundle, true);
bundleContext.removeServiceListener(this);
bundleContext.addServiceListener(this, null);
- bundleContext = assertServiceLifecycle(bundle, bundleContext, true);
+ bundleContext = assertServiceLifecycle(bundle, true);
bundleContext.removeServiceListener(this);
bundleContext.addServiceListener(this, null);
bundleContext.removeServiceListener(this);
- bundleContext = assertServiceLifecycle(bundle, bundleContext, false);
+ bundleContext = assertServiceLifecycle(bundle, false);
bundleContext.addServiceListener(this, null);
bundleContext.addServiceListener(this, null);
- bundleContext = assertServiceLifecycle(bundle, bundleContext, true);
+ bundleContext = assertServiceLifecycle(bundle, true);
bundleContext.removeServiceListener(this);
Dictionary<String, Object> properties = new Hashtable<String, Object>();
properties.put("a", "b");
bundleContext.addServiceListener(this, ("(a=b)"));
- bundleContext = assertServiceLifecycle(bundle, bundleContext, properties, true);
+ bundleContext = assertServiceLifecycle(bundle, properties, true);
bundleContext.removeServiceListener(this);
bundleContext.addServiceListener(this, ("(c=d)"));
- bundleContext = assertServiceLifecycle(bundle, bundleContext, properties, false);
+ bundleContext = assertServiceLifecycle(bundle, properties, false);
bundleContext.removeServiceListener(this);
bundleContext.addServiceListener(this, "(a=b)");
bundleContext.removeServiceListener(this);
- bundleContext = assertServiceLifecycle(bundle, bundleContext, properties, false);
+ bundleContext = assertServiceLifecycle(bundle, properties, false);
bundleContext.addServiceListener(this, "(c=d)");
bundleContext.addServiceListener(this, "(a=b)");
- assertServiceLifecycle(bundle, bundleContext, properties, true);
+ bundleContext = assertServiceLifecycle(bundle, properties, true);
bundleContext.removeServiceListener(this);
}
finally
@@ -349,15 +349,16 @@
}
}
- protected BundleContext assertServiceLifecycle(Bundle bundle, BundleContext bundleContext, boolean events) throws Exception
+ protected BundleContext assertServiceLifecycle(Bundle bundle, boolean events) throws Exception
{
- return assertServiceLifecycle(bundle, bundleContext, null, events);
+ return assertServiceLifecycle(bundle, null, events);
}
- protected BundleContext assertServiceLifecycle(Bundle bundle, BundleContext bundleContext, Dictionary<String, Object> properties, boolean events) throws Exception
+ protected BundleContext assertServiceLifecycle(Bundle bundle, Dictionary<String, Object> properties, boolean events) throws Exception
{
assertNoServiceEvent();
+ BundleContext bundleContext = bundle.getBundleContext();
ServiceRegistration registration = bundleContext.registerService(BundleContext.class.getName(), bundleContext, properties);
ServiceReference reference = registration.getReference();
@@ -404,6 +405,7 @@
bundle.start();
bundleContext = bundle.getBundleContext();
assertNotNull(bundleContext);
+
return bundleContext;
}
@@ -438,16 +440,16 @@
}
bundleContext.addBundleListener(this);
- bundleContext = assertBundleLifecycle(bundle, bundleContext, true);
+ bundleContext = assertBundleLifecycle(bundle, true);
bundleContext.removeBundleListener(this);
bundleContext.addBundleListener(this);
bundleContext.removeBundleListener(this);
- bundleContext = assertBundleLifecycle(bundle, bundleContext, false);
+ bundleContext = assertBundleLifecycle(bundle, false);
bundleContext.addBundleListener(this);
bundleContext.addBundleListener(this);
- bundleContext = assertBundleLifecycle(bundle, bundleContext, true);
+ bundleContext = assertBundleLifecycle(bundle, true);
bundleContext.removeBundleListener(this);
bundleContext.addBundleListener(this);
@@ -464,7 +466,7 @@
assertBundleEvent(BundleEvent.UNINSTALLED, bundle);
}
- protected BundleContext assertBundleLifecycle(Bundle bundle, BundleContext bundleContext, boolean events) throws Exception
+ protected BundleContext assertBundleLifecycle(Bundle bundle, boolean events) throws Exception
{
assertNoBundleEvent();
@@ -490,7 +492,7 @@
assertNoBundleEvent();
}
- return bundleContext;
+ return bundle.getBundleContext();
}
public void testFrameworkListener() throws Exception
@@ -549,6 +551,45 @@
}
}
+ public void testStopedBundleContext() throws Exception
+ {
+ Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+ try
+ {
+ bundle.start();
+ BundleContext bundleContext = bundle.getBundleContext();
+ assertNotNull(bundleContext);
+
+ // The context should be illegal to use.
+ bundle.stop();
+ try
+ {
+ bundleContext.getProperty(getClass().getName());
+ fail("Should not be here!");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IllegalStateException.class, t);
+ }
+
+ // The context should not become reusable after we restart the bundle
+ bundle.start();
+ try
+ {
+ bundleContext.getProperty(getClass().getName());
+ fail("Should not be here!");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IllegalStateException.class, t);
+ }
+ }
+ finally
+ {
+ uninstall(bundle);
+ }
+ }
+
protected void assertSystemProperty(BundleContext bundleContext, String property, String osgiProperty)
{
String expected = System.getProperty(property);
Modified: projects/jboss-osgi/projects/runtime/framework/trunk/src/test/resources/bootstrap/jboss-osgi-bootstrap.xml
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/test/resources/bootstrap/jboss-osgi-bootstrap.xml 2009-12-16 15:46:19 UTC (rev 97897)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/test/resources/bootstrap/jboss-osgi-bootstrap.xml 2009-12-16 15:56:20 UTC (rev 97898)
@@ -16,7 +16,7 @@
</constructor>
<property name="properties">
<map keyClass="java.lang.String" valueClass="java.lang.String">
- <entry><key>org.osgi.framework.storage</key><value>${log4j.output.dir}/osgi-store</value></entry>
+ <entry><key>org.osgi.framework.storage</key><value>target/osgi-store</value></entry>
<entry><key>org.osgi.framework.storage.clean</key><value>onFirstInit</value></entry>
<entry><key>org.osgi.framework.system.packages.extra</key><value>
More information about the jboss-cvs-commits
mailing list