DUE TO SPAM, SIGN-UP IS DISABLED. Goto Selfserve wiki signup and request an account.
...
The first example is about registering a service. We extend DependencyActivatorBase and in the init method we use the reference to the DependencyManager to create and add a service. For this service we subsequently set its interface and implementation. In this case the interface is the Store interface, the second parameter, null, allows you to provide properties along with the service registration. For the implementation, we only mention the Class of the implementation, which means the dependency manager will lazily instantiate it. In this case, there is not much point in doing that because the service has no dependencies, but if it had, the instantiation would only happen when those dependencies were resolved.The first example is about registering a service. We extend DependencyActivatorBase and in the init method we use the reference to the DependencyManager to create and add a service. For this service we subsequently set its interface and implementation. In this case the interface is the Store interface, the second parameter, null, allows you to provide properties along with the service registration. For the implementation, we only mention the Class of the implementation, which means the dependency manager will lazily instantiate it. In this case, there is not much point in doing that because the service has no dependencies, but if it had, the instantiation would only happen when those dependencies were resolved.
| Code Block |
|---|
public class Activator extends DependencyActivatorBase {
public void init(BundleContext context, DependencyManager manager) throws Exception {
manager.add(createService()
.setInterface(Store.class.getName(), null)
.setImplementation(MemoryStore.class)
);
}
public void destroy(BundleContext context, DependencyManager manager) throws Exception {}
}
|
| Code Block |
|---|
This is the service interface. Nothing special here. |
This is the service interface. Nothing special here.
| Code Block |
|---|
public interface Store {
public void put(String key, Object value);
public Object get(String key);
}
|
| Code Block |
|---|
And finally the implementation. Again, this is just a POJO, there is no reference here to any OSGi or dependency manager specific class or annotation.
|
And finally the implementation. Again, this is just a POJO, there is no reference here to any OSGi or dependency manager specific class or annotation.
...