Search in sources :

Example 6 with BundleDTO

use of org.osgi.framework.dto.BundleDTO in project bnd by bndtools.

the class AgentServer method getBundles.

private List<BundleDTO> getBundles() {
    Bundle[] bundles = context.getBundles();
    ArrayList<BundleDTO> list = new ArrayList<BundleDTO>(bundles.length);
    for (Bundle b : bundles) {
        list.add(toDTO(b));
    }
    return list;
}
Also used : Bundle(org.osgi.framework.Bundle) ArrayList(java.util.ArrayList) BundleDTO(org.osgi.framework.dto.BundleDTO)

Example 7 with BundleDTO

use of org.osgi.framework.dto.BundleDTO in project bnd by bndtools.

the class JMXBundleDeployer method listBundles.

/**
	 * Calls osgi.core bundleState MBean listBundles operation
	 * 
	 * @return array of bundles in framework
	 */
public BundleDTO[] listBundles() {
    final List<BundleDTO> retval = new ArrayList<BundleDTO>();
    try {
        final ObjectName bundleState = getBundleState();
        final Object[] params = new Object[] { new String[] { "Identifier", "SymbolicName", "State", "Version" } };
        final String[] signature = new String[] { String[].class.getName() };
        final TabularData data = (TabularData) mBeanServerConnection.invoke(bundleState, "listBundles", params, signature);
        for (Object value : data.values()) {
            final CompositeData cd = (CompositeData) value;
            try {
                retval.add(newFromData(cd));
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return retval.toArray(new BundleDTO[0]);
}
Also used : CompositeData(javax.management.openmbean.CompositeData) ArrayList(java.util.ArrayList) BundleDTO(org.osgi.framework.dto.BundleDTO) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) MalformedObjectNameException(javax.management.MalformedObjectNameException) ObjectName(javax.management.ObjectName) TabularData(javax.management.openmbean.TabularData)

Example 8 with BundleDTO

use of org.osgi.framework.dto.BundleDTO in project bnd by bndtools.

the class AgentServer method getBundles.

@Override
public List<BundleDTO> getBundles(long... bundleId) throws Exception {
    Bundle[] bundles;
    if (bundleId.length == 0) {
        bundles = context.getBundles();
    } else {
        bundles = new Bundle[bundleId.length];
        for (int i = 0; i < bundleId.length; i++) {
            bundles[i] = context.getBundle(bundleId[i]);
        }
    }
    List<BundleDTO> bundleDTOs = new ArrayList<BundleDTO>(bundles.length);
    for (Bundle b : bundles) {
        BundleDTO dto = toDTO(b);
        bundleDTOs.add(dto);
    }
    return bundleDTOs;
}
Also used : Bundle(org.osgi.framework.Bundle) ArrayList(java.util.ArrayList) BundleDTO(org.osgi.framework.dto.BundleDTO)

Example 9 with BundleDTO

use of org.osgi.framework.dto.BundleDTO in project bnd by bndtools.

the class AgentServer method toDTO.

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;
}
Also used : BundleDTO(org.osgi.framework.dto.BundleDTO)

Example 10 with BundleDTO

use of org.osgi.framework.dto.BundleDTO in project bnd by bndtools.

the class AgentTest method testAgentUpdateBundle.

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);
}
Also used : Version(aQute.bnd.version.Version) BundleDTO(org.osgi.framework.dto.BundleDTO) File(java.io.File)

Aggregations

BundleDTO (org.osgi.framework.dto.BundleDTO)12 File (java.io.File)3 ArrayList (java.util.ArrayList)3 Version (aQute.bnd.version.Version)2 ObjectName (javax.management.ObjectName)2 Bundle (org.osgi.framework.Bundle)2 Agent (aQute.remote.api.Agent)1 LauncherSupervisor (aQute.remote.plugin.LauncherSupervisor)1 JMXBundleDeployer (aQute.remote.util.JMXBundleDeployer)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 MalformedObjectNameException (javax.management.MalformedObjectNameException)1 CompositeData (javax.management.openmbean.CompositeData)1 TabularData (javax.management.openmbean.TabularData)1