Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.
Corona management simple object
Enabling a Java class for management is a relatively easy process. Consider the following class, which contains a property prop
and an operation doOperation()
, which comprise the management interface for the class SimpleJavaObject
.
package org.eclipse.corona.wsdm.example;
import org.osgi.framework.ServiceReference;
import org.osgi.service.component.ComponentContext;
import org.eclipse.corona.management.common.ContributionManager;
public class SimpleJavaObject {
private String prop;
public void doOperation() {
System.out.println("invoked operation");
}
public String getProp() {
return "Property";
}
ContributionManager manager;
//Declarative Services methods
protected void activate(ComponentContext ctx)
{
ServiceReference ref = ctx.getBundleContext().getServiceReference(ContributionManager.class.getName());
manager = (ContributionManager)ctx.getBundleContext().getService(ref);
manager.manage(this);
}
protected void deactivate(ComponentContext ctxt)
{
manager.remove(this);
}
//Other non-management oprations and properties
}
Instances of the class can be made manageable by adding the following annotations:
package org.eclipse.corona.wsdm.example;
import org.osgi.framework.ServiceReference;
import org.osgi.service.component.ComponentContext;
import org.eclipse.corona.management.common.ContributionManager;
import org.eclipse.corona.management.annotations.ManagedOperation;
import org.eclipse.corona.management.annotations.ManagedProperty;
import org.eclipse.corona.management.annotations.ManagedResource;
@ManagedResource(namespace="http://org.eclipse.corona.wsdm.example")
public class SimpleJavaObject {
@ManagedProperty
private String prop;
@ManagedOperation
public void doOperation() {
System.out.println("invoked operation");
}
public String getProp() {
return "Property";
}
ContributionManager manager;
//Declarative Services methods
protected void activate(ComponentContext ctx)
{
ServiceReference ref = ctx.getBundleContext().getServiceReference(ContributionManager.class.getName());
manager = (ContributionManager)ctx.getBundleContext().getService(ref);
manager.manage(this);
}
protected void deactivate(ComponentContext ctxt)
{
manager.remove(this);
}
//Other non-management oprations and properties
}
Instances of the class are then registered with the Management Runtime using the ContributionManager<Link to Obtaining the Management Enabling environment> as follows:
SimpleJavaObject objInstance = new SimpleJavaObject();
manager.manage(objInstance );