org.osgi.framework.dto.BundleDTO

Here are the examples of the java api class org.osgi.framework.dto.BundleDTO taken from open source projects.

1. RemoteJMXTest#testJMXBundleDeployer()

Project: bnd
File: RemoteJMXTest.java
public void testJMXBundleDeployer() throws Exception {
    JMXBundleDeployer jmxBundleDeployer = new JMXBundleDeployer();
    long bundleId = jmxBundleDeployer.deploy("biz.aQute.remote.agent", IO.getFile("generated/biz.aQute.remote.agent.jar"));
    assertTrue(bundleId > 0);
    BundleDTO agentBundle = null;
    long state = -1;
    for (BundleDTO bundle : jmxBundleDeployer.listBundles()) {
        if (bundle.symbolicName.equals("biz.aQute.remote.agent")) {
            agentBundle = bundle;
            state = bundle.state;
        }
    }
    assertNotNull(agentBundle);
    assertEquals(Bundle.ACTIVE, state);
}

2. AgentTest#testAgentUpdateBundleFromURL()

Project: bnd
File: AgentTest.java
public void testAgentUpdateBundleFromURL() throws Exception {
    BundleDTO t2Bundle = supervisor.getAgent().getBundles(2).get(0);
    assertEquals("bsn-2", t2Bundle.symbolicName);
    assertEquals("2.0.0", t2Bundle.version);
    long previousModified = t2Bundle.lastModified;
    File t2prime = create("bsn-2", new Version(2, 0, 1));
    assertNull(supervisor.getAgent().updateFromURL(t2Bundle.id, t2prime.toURI().toURL().toExternalForm()));
    t2Bundle = supervisor.getAgent().getBundles(2).get(0);
    assertTrue(previousModified != t2Bundle.lastModified);
}

3. AgentTest#testAgentUpdateBundle()

Project: bnd
File: AgentTest.java
public void testAgentUpdateBundle() throws Exception {
    BundleDTO t2Bundle = supervisor.getAgent().getBundles(2).get(0);
    assertEquals("bsn-2", t2Bundle.symbolicName);
    assertEquals("2.0.0", t2Bundle.version);
    long previousModified = t2Bundle.lastModified;
    File t2prime = create("bsn-2", new Version(2, 0, 1));
    String sha = supervisor.addFile(t2prime);
    assertNull(supervisor.getAgent().update(2, sha));
    t2Bundle = supervisor.getAgent().getBundles(2).get(0);
    assertTrue(previousModified != t2Bundle.lastModified);
}

4. JMXBundleDeployer#newFromData()

Project: bnd
File: JMXBundleDeployer.java
private static BundleDTO newFromData(CompositeData cd) {
    final BundleDTO dto = new BundleDTO();
    dto.id = Long.parseLong(cd.get("Identifier").toString());
    dto.symbolicName = cd.get("SymbolicName").toString();
    String state = cd.get("State").toString();
    if ("UNINSTALLED".equals(state)) {
        dto.state = Bundle.UNINSTALLED;
    } else if ("INSTALLED".equals(state)) {
        dto.state = Bundle.INSTALLED;
    } else if ("RESOLVED".equals(state)) {
        dto.state = Bundle.RESOLVED;
    } else if ("STARTING".equals(state)) {
        dto.state = Bundle.STARTING;
    } else if ("STOPPING".equals(state)) {
        dto.state = Bundle.STOPPING;
    } else if ("ACTIVE".equals(state)) {
        dto.state = Bundle.ACTIVE;
    }
    dto.version = cd.get("Version").toString();
    return dto;
}

5. RemoteTest#testSimple()

Project: bnd
File: RemoteTest.java
public void testSimple() throws Exception {
    LauncherSupervisor supervisor = new LauncherSupervisor();
    supervisor.connect("localhost", Agent.DEFAULT_PORT);
    assertNotNull(supervisor);
    Agent agent = supervisor.getAgent();
    assertNotNull(agent.getFramework());
    // Create stdin/stderr buffers
    // and redirect output
    StringBuffer stderr = new StringBuffer();
    StringBuffer stdout = new StringBuffer();
    supervisor.setStderr(stderr);
    supervisor.setStdout(stdout);
    supervisor.redirect(1);
    //
    // Install the bundle systemio
    //
    File f = IO.getFile("generated/biz.aQute.remote.test.systemio.jar");
    String sha = supervisor.addFile(f);
    BundleDTO bundle = agent.install(f.getAbsolutePath(), sha);
    //
    // Start the bundle and capture the output
    //
    String result = agent.start(bundle.id);
    assertNull(result, result);
    Thread.sleep(1000);
    assertEquals("Hello World", stdout.toString().trim());
    stdout.setLength(0);
    // Send input (will be consumed by the Activator.stop
    ByteArrayInputStream bin = new ByteArrayInputStream(new String("Input\n").getBytes());
    supervisor.setStdin(bin);
    // stop the bundle (will return input as uppercase)
    result = agent.stop(bundle.id);
    assertNull(result, result);
    Thread.sleep(1000);
    assertEquals("INPUT", stdout.toString().trim());
}

6. AgentTest#testAgentInstallBundleFromURL()

Project: bnd
File: AgentTest.java
public void testAgentInstallBundleFromURL() throws Exception {
    BundleDTO bundle = supervisor.getAgent().installFromURL(t3.getAbsolutePath(), t3.toURI().toURL().toExternalForm());
    assertNotNull(bundle);
    assertEquals(4, bundle.id);
    assertEquals("bsn-3", bundle.symbolicName);
    assertEquals("3.0.0", bundle.version);
    assertEquals(5, supervisor.getAgent().getBundles().size());
}

7. AgentTest#testAgentInstallBundle()

Project: bnd
File: AgentTest.java
public void testAgentInstallBundle() throws Exception {
    String sha = supervisor.addFile(t3);
    BundleDTO bundle = supervisor.getAgent().install(t3.getAbsolutePath(), sha);
    assertNotNull(bundle);
    assertEquals(4, bundle.id);
    assertEquals("bsn-3", bundle.symbolicName);
    assertEquals("3.0.0", bundle.version);
}

8. JMXBundleDeployer#uninstall()

Project: bnd
File: JMXBundleDeployer.java
/**
	 * Uninstall a bundle by passing in its Bundle-SymbolicName. If bundle
	 * doesn't exist, this is a NOP.
	 * 
	 * @param bsn bundle symbolic name
	 * @throws Exception
	 */
public void uninstall(String bsn) throws Exception {
    for (BundleDTO osgiBundle : listBundles()) {
        if (osgiBundle.symbolicName.equals(bsn)) {
            uninstall(osgiBundle.id);
            return;
        }
    }
    throw new IllegalStateException("Unable to uninstall " + bsn);
}

9. JMXBundleDeployer#deploy()

Project: bnd
File: JMXBundleDeployer.java
/**
	 * Gets the current list of installed bsns, compares it to the bsn provided.
	 * If bsn doesn't exist, then install it. If it does exist then update it.
	 * 
	 * @param bsn Bundle-SymbolicName of bundle you are wanting to deploy
	 * @param bundle the bundle
	 * @return the id of the updated or installed bundle
	 * @throws Exception
	 */
public long deploy(String bsn, File bundle) throws Exception {
    final ObjectName framework = getFramework(mBeanServerConnection);
    long bundleId = -1;
    for (BundleDTO osgiBundle : listBundles()) {
        if (osgiBundle.symbolicName.equals(bsn)) {
            bundleId = osgiBundle.id;
            break;
        }
    }
    if (bundleId > -1) {
        mBeanServerConnection.invoke(framework, "stopBundle", new Object[] { bundleId }, new String[] { "long" });
        mBeanServerConnection.invoke(framework, "updateBundleFromURL", new Object[] { bundleId, bundle.toURI().toURL().toExternalForm() }, new String[] { "long", String.class.getName() });
        mBeanServerConnection.invoke(framework, "refreshBundle", new Object[] { bundleId }, new String[] { "long" });
    } else {
        Object installed = mBeanServerConnection.invoke(framework, "installBundleFromURL", new Object[] { bundle.getAbsolutePath(), bundle.toURI().toURL().toExternalForm() }, new String[] { String.class.getName(), String.class.getName() });
        bundleId = Long.parseLong(installed.toString());
    }
    mBeanServerConnection.invoke(framework, "startBundle", new Object[] { bundleId }, new String[] { "long" });
    return bundleId;
}

10. AgentServer#toDTO()

Project: bnd
File: AgentServer.java
private BundleDTO toDTO(Bundle b) {
    BundleDTO bd = new BundleDTO();
    bd.id = b.getBundleId();
    bd.lastModified = b.getLastModified();
    bd.state = b.getState();
    bd.symbolicName = b.getSymbolicName();
    bd.version = b.getVersion() == null ? "0" : b.getVersion().toString();
    return bd;
}