Created
January 18, 2011 09:57
-
-
Save jetztgradnet/784237 to your computer and use it in GitHub Desktop.
Accessing a OSGi service from Java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.ArrayList; | |
import java.util.List | |
import org.osgi.framework.BundleActivator; | |
import org.osgi.framework.BundleContext; | |
import org.osgi.framework.ServiceReference; | |
List<String> results = new ArrayList<String>(); | |
ServiceReference[] references = context.getServiceReferences(MyService.class.getName(), null); | |
for (int r = 0; r < references.length; r++) { | |
ServiceReference reference = references[r]; | |
if (reference == null) { | |
continue; | |
} | |
try { | |
MyService service = (MyService) context.getService(reference); | |
if (service != null) { | |
String result = service.doSomething(); | |
results.add(result); | |
} | |
} | |
finally { | |
context.ungetService(reference); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment