Author: thomas.diesler(a)jboss.com
Date: 2010-03-04 22:46:43 -0500 (Thu, 04 Mar 2010)
New Revision: 101927
Modified:
projects/jboss-osgi/projects/testing/trunk/src/main/java/org/jboss/osgi/testing/internal/RemoteBundle.java
projects/jboss-osgi/projects/testing/trunk/src/main/java/org/jboss/osgi/testing/internal/RemoteRuntime.java
Log:
Prevent getBundles failure due to remote bundle getting uninstalled
Modified:
projects/jboss-osgi/projects/testing/trunk/src/main/java/org/jboss/osgi/testing/internal/RemoteBundle.java
===================================================================
---
projects/jboss-osgi/projects/testing/trunk/src/main/java/org/jboss/osgi/testing/internal/RemoteBundle.java 2010-03-05
03:46:34 UTC (rev 101926)
+++
projects/jboss-osgi/projects/testing/trunk/src/main/java/org/jboss/osgi/testing/internal/RemoteBundle.java 2010-03-05
03:46:43 UTC (rev 101927)
@@ -57,7 +57,7 @@
* @author Thomas.Diesler(a)jboss.org
* @since 25-Sep-2008
*/
-public class RemoteBundle extends OSGiBundleImpl
+class RemoteBundle extends OSGiBundleImpl
{
// Provide logging
private static final Logger log = Logger.getLogger(RemoteBundle.class);
@@ -71,30 +71,24 @@
private Version version;
boolean uninstalled;
- public RemoteBundle(OSGiRuntime runtime, long bundleId)
+ RemoteBundle(OSGiRuntime runtime, long bundleId) throws IOException
{
super(runtime);
this.bundleId = bundleId;
ObjectName objectName = ObjectNameFactory.create(BundleStateMBeanExt.OBJECTNAME);
bundleState = MBeanProxy.get(runtime.getMBeanServer(), objectName,
BundleStateMBeanExt.class);
- try
- {
- symbolicName = bundleState.getSymbolicName(bundleId);
- location = bundleState.getLocation(bundleId);
+
+ symbolicName = bundleState.getSymbolicName(bundleId);
+ location = bundleState.getLocation(bundleId);
- String versionStr = bundleState.getVersion(bundleId);
- version = Version.parseVersion(versionStr);
+ String versionStr = bundleState.getVersion(bundleId);
+ version = Version.parseVersion(versionStr);
- // The getHeaders methods must continue to provide the manifest header
- // information after the bundle enters the UNINSTALLED state.
- defaultHeaders = getHeadersInternal(null);
- rawHeaders = getHeadersInternal("");
- }
- catch (IOException ex)
- {
- throw new IllegalStateException("Cannot initialize remote bundle",
ex);
- }
+ // The getHeaders methods must continue to provide the manifest header
+ // information after the bundle enters the UNINSTALLED state.
+ defaultHeaders = getHeadersInternal(null);
+ rawHeaders = getHeadersInternal("");
}
@SuppressWarnings("unchecked")
@@ -133,15 +127,17 @@
return Bundle.STOPPING;
if ("UNINSTALLED".equals(state))
return Bundle.UNINSTALLED;
-
+ else
+ throw new IllegalStateException("Unsupported state: " + state);
}
catch (Exception rte)
{
Throwable cause = rte.getCause() != null ? rte.getCause() : rte;
if (cause instanceof InstanceNotFoundException == false)
log.warn("Cannot get state for bundle: " + bundleId, cause);
+
+ return Bundle.UNINSTALLED;
}
- return Bundle.UNINSTALLED;
}
@Override
@@ -208,7 +204,7 @@
CompositeData propData = bundleState.getProperty(bundleId, key);
if (propData == null)
return null;
-
+
return (String)propData.get(JmxConstants.VALUE);
}
catch (IOException ex)
Modified:
projects/jboss-osgi/projects/testing/trunk/src/main/java/org/jboss/osgi/testing/internal/RemoteRuntime.java
===================================================================
---
projects/jboss-osgi/projects/testing/trunk/src/main/java/org/jboss/osgi/testing/internal/RemoteRuntime.java 2010-03-05
03:46:34 UTC (rev 101926)
+++
projects/jboss-osgi/projects/testing/trunk/src/main/java/org/jboss/osgi/testing/internal/RemoteRuntime.java 2010-03-05
03:46:43 UTC (rev 101927)
@@ -39,6 +39,7 @@
import javax.naming.InitialContext;
import javax.naming.NamingException;
+import org.jboss.logging.Logger;
import org.jboss.osgi.jmx.MBeanProxy;
import org.jboss.osgi.jmx.ObjectNameFactory;
import org.jboss.osgi.jmx.ServiceStateMBeanExt;
@@ -59,6 +60,9 @@
*/
public class RemoteRuntime extends OSGiRuntimeImpl
{
+ // Provide logging
+ private static final Logger log = Logger.getLogger(RemoteRuntime.class);
+
private MBeanServerConnection mbeanServer;
public RemoteRuntime(OSGiTestHelper helper)
@@ -116,15 +120,25 @@
Iterator<?> iterator = listBundles.values().iterator();
while (iterator.hasNext())
{
- CompositeData next = (CompositeData)iterator.next();
- Object bundleId = next.get(BundleStateMBean.IDENTIFIER);
- bundles.add(new RemoteBundle(this, (Long)bundleId));
+ CompositeData bundleType = (CompositeData)iterator.next();
+ Long bundleId = (Long)bundleType.get(BundleStateMBean.IDENTIFIER);
+ try
+ {
+ bundles.add(new RemoteBundle(this, bundleId));
+ }
+ catch (IOException ex)
+ {
+ log.warn("Cannot initialize remote bundle: [" + bundleId +
"] - " + ex.getMessage());
+ }
}
-
OSGiBundle[] bundleArr = new OSGiBundle[bundles.size()];
bundles.toArray(bundleArr);
return bundleArr;
}
+ catch (RuntimeException rte)
+ {
+ throw rte;
+ }
catch (Exception ex)
{
throw new IllegalStateException("Cannot obtain remote bundles", ex);