Author: gawor
Date: Tue Jun 7 14:43:37 2011
New Revision: 1133030
URL: http://svn.apache.org/viewvc?rev=1133030&view=rev
Log:
GERONIMO-5861: Updated updateApplicationContent() logic to resolve the bundle after updating
it - it prevents a potential deadlock with packageadmin on equinox
Modified:
geronimo/server/trunk/plugins/aries/geronimo-aries/src/main/java/org/apache/geronimo/aries/ApplicationGBean.java
Modified: geronimo/server/trunk/plugins/aries/geronimo-aries/src/main/java/org/apache/geronimo/aries/ApplicationGBean.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/aries/geronimo-aries/src/main/java/org/apache/geronimo/aries/ApplicationGBean.java?rev=1133030&r1=1133029&r2=1133030&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/aries/geronimo-aries/src/main/java/org/apache/geronimo/aries/ApplicationGBean.java
(original)
+++ geronimo/server/trunk/plugins/aries/geronimo-aries/src/main/java/org/apache/geronimo/aries/ApplicationGBean.java
Tue Jun 7 14:43:37 2011
@@ -146,7 +146,7 @@ public class ApplicationGBean implements
return null;
}
- public void updateApplicationContent(long bundleId, File bundleFile) throws IOException,
BundleException {
+ public synchronized void updateApplicationContent(long bundleId, File bundleFile) throws
Exception {
Bundle targetBundle = null;
for (Bundle content : applicationBundles) {
if (content.getBundleId() == bundleId) {
@@ -161,6 +161,7 @@ public class ApplicationGBean implements
BundleContext context = bundle.getBundleContext();
+ ServiceReference reference = null;
RefreshListener refreshListener = null;
try {
// stop the bundle
@@ -175,12 +176,21 @@ public class ApplicationGBean implements
IOUtils.close(fi);
}
+ reference = context.getServiceReference(PackageAdmin.class.getName());
+ PackageAdmin packageAdmin = (PackageAdmin) context.getService(reference);
+
+ Bundle[] bundles = new Bundle [] { targetBundle };
+ // resolve the bundle
+ if (!packageAdmin.resolveBundles(bundles)) {
+ throw new BundleException("Updated bundle cannot be resolved");
+ }
+
// install listener for package refresh
refreshListener = new RefreshListener();
context.addFrameworkListener(refreshListener);
// refresh the bundle - this happens asynchronously
- refreshPackages(context, new Bundle[] { targetBundle });
+ packageAdmin.refreshPackages(bundles);
// update application archive
try {
@@ -197,20 +207,19 @@ public class ApplicationGBean implements
if (BundleUtils.canStart(targetBundle)) {
targetBundle.start(Bundle.START_TRANSIENT);
}
+ } catch (Exception e) {
+ LOG.debug("Error updating application", e);
+ throw new Exception("Error updating application: " + e.getMessage());
} finally {
if (refreshListener != null) {
context.removeFrameworkListener(refreshListener);
}
+ if (reference != null) {
+ context.ungetService(reference);
+ }
}
}
- private void refreshPackages(BundleContext context, Bundle[] bundles) {
- ServiceReference reference = context.getServiceReference(PackageAdmin.class.getName());
- PackageAdmin packageAdmin = (PackageAdmin) context.getService(reference);
- packageAdmin.refreshPackages(bundles);
- context.ungetService(reference);
- }
-
private class RefreshListener implements FrameworkListener {
public CountDownLatch latch = new CountDownLatch(1);
|