@SuppressWarnings("deprecation")
  private void tryJMXDeploy(String jmx, String bsn) {
    JMXBundleDeployer jmxBundleDeployer = null;
    int port = -1;

    try {
      port = Integer.parseInt(jmx);
    } catch (Exception e) {
      // not an integer
    }

    try {
      if (port > -1) {
        jmxBundleDeployer = new JMXBundleDeployer(port);
      } else {
        jmxBundleDeployer = new JMXBundleDeployer();
      }
    } catch (Exception e) {
      // ignore if we can't create bundle deployer (no remote osgi.core
      // jmx avail)
    }

    if (jmxBundleDeployer != null) {
      for (String path : this.getRunpath()) {
        File file = new File(path);
        try {
          Jar jar = new Jar(file);
          try {
            if (bsn.equals(jar.getBsn())) {
              long bundleId = jmxBundleDeployer.deploy(bsn, file);

              trace("agent installed with bundleId=%s", bundleId);
              break;
            }
          } finally {
            jar.close();
          }
        } catch (Exception e) {
          //
        }
      }
    }
  }
Example #2
0
  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);
  }