Import-Package: edu.emmerson.osgi.holamundo1_bundle,
junit.framework,
org.osgi.framework
El siguiente código consulta al contenedor OSGi sobre los servicios exportados para la interfaz HolaMundoService (ver post anterior), lo recupera e invoca su método saluda.
package edu.emmerson.osgi.holamundo.consumer_bundle;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
import edu.emmerson.osgi.holamundo1_bundle.HolaMundoService;
public class ConsumerActivator implements BundleActivator {
ServiceReference helloServiceReference;
public ConsumerActivator() {
System.out.println("HolaMundoConsumer - instanciandose");
}
public void start(BundleContext context) throws Exception {
System.out.println("HolaMundoConsumer - activandose");
helloServiceReference= context.getServiceReference(HolaMundoService.class.getName());
HolaMundoService helloService =(HolaMundoService)context.getService(helloServiceReference);
System.out.println(helloService.saluda("Emmerson"));
}
public void stop(BundleContext context) throws Exception {
System.out.println("HolaMundoConsumer - activandose");
context.ungetService(helloServiceReference);
}
}
- FIN -
No comments:
Post a Comment