protected void awaitBundleActive(long bundleId, long timeout, TimeUnit unit) throws IOException, TimeoutException, InterruptedException { long timeoutMillis = System.currentTimeMillis() + unit.toMillis(timeout); String bundleState = null; while (System.currentTimeMillis() < timeoutMillis) { bundleState = bundleStateMBean.getState(bundleId); if (BundleStateMBean.ACTIVE.equals(bundleState)) { return; } else { Thread.sleep(500); } } throw new TimeoutException("Arquillian bundle [" + bundleId + "] not started: " + bundleState); }
public String getSymbolicName(long bundleId) throws IOException { String result = getBundleStateMBean().getSymbolicName(bundleId); if (log.isTraceEnabled()) log.trace("getSymbolicName [bundleId=" + bundleId + "] => " + result); return result; }
public String getVersion(long bundleId) throws IOException { String result = getBundleStateMBean().getVersion(bundleId); if (log.isTraceEnabled()) log.trace("getVersion [bundleId=" + bundleId + "] => " + result); return result; }
RemoteBundle(OSGiRuntime runtime, long bundleId) throws IOException { super(runtime); this.bundleId = bundleId; bundleState = runtime.getBundleStateMBean(); symbolicName = bundleState.getSymbolicName(bundleId); location = bundleState.getLocation(bundleId); 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); if (bundleState instanceof BundleStateMBeanExt) rawHeaders = getHeadersInternal(""); }
private BundleHandle installBundle(String location, URL streamURL) throws BundleException, IOException { URL serverUrl = streamURL; // Adapt URL to remote system by serving over HTTP SimpleHTTPServer server = null; if (!isLocalHost(config)) { server = new SimpleHTTPServer(); serverUrl = server.serve(streamURL); server.start(); } try { long bundleId = frameworkMBean.installBundleFromURL(location, serverUrl.toExternalForm()); String symbolicName = bundleStateMBean.getSymbolicName(bundleId); String version = bundleStateMBean.getVersion(bundleId); return new BundleHandle(bundleId, symbolicName, version); } finally { if (server != null) { server.shutdown(); } } }
public TabularData listBundles() throws IOException { TabularData result = getBundleStateMBean().listBundles(); if (log.isTraceEnabled()) log.trace("TabularData => " + result); return result; }
public TabularData getHeaders(long bundleId) throws IOException { TabularData result = getBundleStateMBean().getHeaders(bundleId); if (log.isTraceEnabled()) log.trace("getHeaders [bundleId=" + bundleId + "] => " + result); return result; }
public String getLocation(long bundleId) throws IOException { String result = getBundleStateMBean().getLocation(bundleId); if (log.isTraceEnabled()) log.trace("getLocation [bundleId=" + bundleId + "] => " + result); return result; }
public String[] getExportedPackages(long bundleId) throws IOException { String[] result = getBundleStateMBean().getExportedPackages(bundleId); if (log.isTraceEnabled()) log.trace("getExportedPackages [bundleId=" + bundleId + "] => " + result); return result; }
public long[] getFragments(long bundleId) throws IOException { long[] result = getBundleStateMBean().getFragments(bundleId); if (log.isTraceEnabled()) log.trace("getFragments [bundleId=" + bundleId + "] => " + (result != null ? Arrays.asList(result) : null)); return result; }
private void undeploy(String symbolicName) throws DeploymentException { BundleHandle handle = deployedBundles.remove(symbolicName); if (handle != null) { String bundleState = null; try { long bundleId = handle.getBundleId(); CompositeData bundleType = bundleStateMBean.getBundle(bundleId); if (bundleType != null) { bundleState = (String) bundleType.get(BundleStateMBean.STATE); } } catch (IOException e) { // ignore non-existent bundle return; } if (bundleState != null && !bundleState.equals(BundleStateMBean.UNINSTALLED)) { try { long bundleId = handle.getBundleId(); frameworkMBean.uninstallBundle(bundleId); } catch (IOException ex) { logger.error("Cannot undeploy: " + symbolicName, ex); } } } }
protected BundleHandle getBundle(String symbolicName, String version) throws Exception { TabularData listBundles = bundleStateMBean.listBundles(); Iterator<?> iterator = listBundles.values().iterator(); while (iterator.hasNext()) { CompositeData bundleType = (CompositeData) iterator.next(); Long bundleId = (Long) bundleType.get(BundleStateMBean.IDENTIFIER); String auxName = (String) bundleType.get(BundleStateMBean.SYMBOLIC_NAME); String auxVersion = (String) bundleType.get(BundleStateMBean.VERSION); if (symbolicName.equals(auxName) && version.equals(auxVersion)) { return new BundleHandle(bundleId, symbolicName, auxVersion); } } return null; }
@SuppressWarnings("unchecked") private Dictionary<String, String> getHeadersInternal(String locale) throws IOException { Dictionary<String, String> headers = new Hashtable<String, String>(); TabularData headerData; if (locale == null) headerData = bundleState.getHeaders(bundleId); else headerData = assertBundleStateMBeanExt().getHeaders(bundleId, locale); for (CompositeData aux : (Collection<CompositeData>)headerData.values()) { String key = (String)aux.get(JmxConstants.KEY); String value = (String)aux.get(JmxConstants.VALUE); headers.put(key, value); } return new UnmodifiableDictionary(headers); }
try TabularData listBundles = getBundleStateMBean().listBundles(); Iterator<?> iterator = listBundles.values().iterator(); while (iterator.hasNext())
public String getState(long bundleId) throws IOException { String result = getBundleStateMBean().getState(bundleId); if (log.isTraceEnabled()) log.trace("getState [bundleId=" + bundleId + "] => " + result); return result; }
String state = bundleState.getState(bundleId); if ("INSTALLED".equals(state)) return Bundle.INSTALLED;