Java Reference
In-Depth Information
return null;
}
else {
String[] strs = PropertyUtil.toStringArray(ifaces);
if (strs.length == 1 && "*".equals(strs[0])) {
ifaces = ref.getProperty(Constants.OBJECTCLASS);
strs = PropertyUtil.toStringArray(ifaces);
}
return strs;
}
}
You first look for the appropriate service property indicating whether the service is to
be exported. If it is, you use a utility class to return the interfaces. Then you check to
see whether the name of the exported interface is * . If it is, you get the interfaces
from the standard OSG i objectClass service property, which lists all the registered
service interfaces of the service object.
You also need to override the ServiceTracker methods for handling when match-
ing services are modified or removed, but we'll skip describing these in detail because
they're fairly similar to adding services. If you're curious, you can look at the compan-
ion code in chapter15/webservice-impl/org.foo.dosgi.
Let's turn our attention away from exporting local services to a remote registry and
toward importing remote services into the local OSG i service registry. To facilitate this,
the OSG i R4.2 core specification introduced a way to hook into the OSG i service regis-
try using two new service interfaces:
org.osgi.framework.hooks.service.FindHook
org.osgi.framework.hooks.service.ListenerHook
To s a v e o u r s e l v e s f r o m r e p e a t i n g b o i l e r p l a t e c o d e i n t h e f o l l o w i n g e x a m p l e s , y o u
define a RegistryWatcher helper class to handle the lookup of services from the
Framework service registry hooks
The OSGi R4.2 core specification allows third-party code to inject various hooks into
the framework service registry. These hooks let you monitor or even mask service
lookup, service discovery, and service registrations. The new interfaces:
FindHook detects when services are requested from the framework.
ListenerHook detects when service listeners are registered.
EventHook detects service registrations, modifications, or removals, and
enables the masking of these events.
Services implementing these interfaces are registered in the OSGi service registry,
just like any other service, but they're picked up by the framework implementation.
These interfaces can provide some extremely powerful patterns, but you should be
highly wary because they have the capacity to create complex situations that are dif-
ficult to debug. That being said, they're the only practical way to build distributed ser-
vice models on top of the OSGi service registry, so here we are.
 
Search WWH ::




Custom Search