Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.
Gemini/Management/Examples
< Gemini | Management
Contents
Examples
Accessing Gemini Management MBeans from a Groovy Script
Create a server connection:
import groovy.jmx.builder.JmxBuilder import javax.management.MBeanServerConnection def client = new JmxBuilder().connectorClient(port: 1234) print("connecting to JMX server...") client.connect() println("established.") MBeanServerConnection serverConnection = client.getMBeanServerConnection()
Query the list of available bundles
ObjectName objectName = serverConnection.queryNames(new ObjectName("osgi.core:type=bundleState,*"), null).first() TabularData data = serverConnection.invoke(objectName, "listBundles", null, null) println("List of available bundles:") data.values().each { println "[" + it.get("Identifier") + "] - " + it.get("State") + " - " + it.get("SymbolicName")}
Sample output:
List of available bundles: [0] - ACTIVE - org.eclipse.osgi [1] - ACTIVE - org.eclipse.osgi.services [2] - ACTIVE - osgi.enterprise [3] - ACTIVE - org.eclipse.gemini.management
Query the available info per bundle
ObjectName objectName = serverConnection.queryNames(new ObjectName("osgi.core:type=bundleState,*"), null).first() TabularData data = serverConnection.invoke(objectName, "listBundles", null, null) println("List of available info:") println data.values().first().compositeType.keySet().each {println it}
Sample output:
List of available info: ActivationPolicyUsed ExportedPackages Fragment Fragments Headers ...
Introspect a single bundle
The following snippet checks if the bundle with ID 3 is a fragment, then prints all bundle headers.
long bundleId = 3 def args = [bundleId] as Object[] def signature = ["long"] as String[] def isFragment = serverConnection.invoke(objectName, "isFragment", args, signature) println "Is bundle $bundleId a fragment? $isFragment" println "Bundle $bundleId has the following bundle headers:" def headers = serverConnection.invoke(objectName, "getHeaders", args, signature) headers.values().each { println it.get("Key") + " = " + it.get("Value") }
Sample output:
Is bundle 3 a fragment? false Bundle 3 has the following bundle headers: Manifest-Version = 1.0 Archiver-Version = Plexus Archiver Created-By = Apache Maven Built-By = cgfrost Build-Jdk = 1.6.0_45 Export-Package = org.osgi.jmx;uses:="javax.management.openmbean";version="1.1", [...] Bundle-Vendor = Eclipse Gemini Management Bundle-Version = 2.0.0.RELEASE Bundle-Name = Gemini Management ...