Search code examples
javamonitoringosgiequinoxapache-felix

com.sun.management.OperatingSystemMXBean use in an OSGi bundle


I have some legacy code that was used to monitor my applications cpu,memory etc that I want to convert to a bundle. Now when i start this bundle its complaining

Missing Constraint: Import-Package: com.sun.management; version="0.0.0"

I had used the OperatingSystemMXBean to get access to stats on the JVM.

My question is can I use this class inside an OSGI container and if so how? Or should I use some other way to monitor my application. I was making an RMI call to the application from a web frontend to get the nodes performance figures pre OSGi.


Solution

  • Could you try to install it in an interactive OSGi session?
    See this article for example.

    osgi> ss
    
    Framework is launched.
    
    id State       Bundle
    0 ACTIVE      org.eclipse.osgi_3.4.0.v20080605-1900
    
    osgi>  install file:bundles/FirstBundle-1.0.0.jar
    Bundle id is 1
    
    //Try starting 
    osgi> start 1
    org.osgi.framework.BundleException: The bundle could not be resolved. 
      Reason: Missing Constraint: Import-Package: com.so.samples.osgi.second; 
                                                  version="0.0.0"
     at org.eclipse.osgi.framework.internal.core.BundleHost.startWorker
        (BundleHost.java:305)
    

    You can diagnostic the issue:

    osgi> diag 1
    file:bundles/FirstBundle-1.0.0.jar [1]
      Direct constraints which are unresolved:
        Missing imported package com.so.samples.osgi.second_0.0.0.
    

    And install the missing dependency, provided you know where to fetch the jar
    (which might very well be the crux of your question, and for which I have no exact answer, except to convert a legacy jar in an OSGi bundle, like a wrap protocol or an extension of an OSGi framework):

    osgi> install file:bundles/SecondBundle-1.0.0.jar
    Bundle id is 2