Skip to content

Instantly share code, notes, and snippets.

@roberto-filho
Created May 22, 2015 15:01
Show Gist options
  • Save roberto-filho/a4b95244d22b591e18ff to your computer and use it in GitHub Desktop.
Save roberto-filho/a4b95244d22b591e18ff to your computer and use it in GitHub Desktop.
Service creation with eclipse plugins
/*
* Para cadastrar um serviço, chame esse método no "start" da classe plugin
*/
plugin.getBundle().getBundleContext().registerService(ExternalAPI.class, new ConcreteExternalAPI(), null);
/*
* Para obter o serviço registrado por outro plugin
*/
BundleContext bundleContext = PluginActivator.getDefault().getBundle().getBundleContext();
// Busca a referencia do service
ServiceReference<ExternalAPI> sr = bundleContext.getServiceReference(ExternalAPI.class);
// Busca o serviço concreto
ExternalAPI service = bundleContext.getService(sr);
// Roda o método do serviço
service.doSomething();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment