Skip to content

Instantly share code, notes, and snippets.

@dileeph
Created May 1, 2017 18:40
Show Gist options
  • Save dileeph/8c199c24546b62eafcbd1cc592ce1df2 to your computer and use it in GitHub Desktop.
Save dileeph/8c199c24546b62eafcbd1cc592ce1df2 to your computer and use it in GitHub Desktop.
osgi hello 1 based on felix tutorial
public void serviceChanged(ServiceEvent event) {
String[] objectClass = (String[])
event.getServiceReference().getProperty("objectClass");
if (event.getType() == ServiceEvent.REGISTERED)
{
System.out.println(
"Ex1: Service of type " + objectClass[0] + " registered.");
}
else if (event.getType() == ServiceEvent.UNREGISTERING)
{
System.out.println(
"Ex1: Service of type " + objectClass[0] + " unregistered.");
}
else if (event.getType() == ServiceEvent.MODIFIED)
{
System.out.println(
"Ex1: Service of type " + objectClass[0] + " modified.");
}
}
public void start(BundleContext context) throws Exception {
System.out.println("Starting to listen for service events.");
context.addServiceListener(this);
}
public void stop(BundleContext context) throws Exception {
context.removeServiceListener(this);
System.out.println("Stopped listening for service events.");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment