ServiceTracker will automatically track services matching the filter you
supply, once you open() it.
You only need to create a customizer if you want to have callbacks when
the tracker modifies its set of tracked services. For example, you could
do this to proxy the services. If you don't need to do anything to the
tracked services and you just want to use them, then you don't need a
customizer.
-> richard
On 10/5/09 18:20, Vlatko Davidovski wrote:
Currently I am using ServiceTracker already. But if I understand
correctly, I need to have my own ServiceTrackerCustomizer in order to
track the changes, right?
Here is my code as it is at the moment:
public void start(BundleContext context) throws Exception {
// Get the LogService.
logServiceTracker = new ServiceTracker(context,
LogService.class.getName(), null);
logServiceTracker.open();
LogService logService = (LogService)
logServiceTracker.getService();
// Get the ConfigurationAdmin.
configuratorTracker = new ServiceTracker(context,
ConfiguratorService.class.getName(), null);
configuratorTracker.open();
ConfiguratorService configuratorService =
(ConfiguratorService) configuratorTracker.getService();
if(logService != null) {
logService.log(LogService.LOG_INFO, "LogService
succesfully loaded.");
if(configuratorService != null) {
logService.log(LogService.LOG_INFO,
"ConfiguratorService succesfully loaded.");
// Get the properties.
Dictionary<String, Object> properties =
configuratorService.getServiceProperties(DeviceRegistryServiceImpl.getPid());
if(properties != null) {
// Create a new DeviceRegistryService.
DeviceRegistryService service = new
DeviceRegistryServiceImpl(logService, configuratorService, properties);
// Register DeviceRegistryService implementation.
ServiceRegistration
deviceRegistryServiceRegistration =
context.registerService(DeviceRegistryService.class.getName(),
service, properties);
if(deviceRegistryServiceRegistration != null)
logService.log(LogService.LOG_INFO,
"DeviceRegistryService successfully registered.");
else
logService.log(LogService.LOG_ERROR, "Error
while registering DeviceRegistryService. Reference to it is equal to
null.");
}
}
else
logService.log(LogService.LOG_DEBUG, "Mandatory
service ConfiguratorService is not available. Services of bundle
aparat-configurator are not registered.");
}
else
System.out.println("Mandatory service LogService is not
available. Services of bundle aparat-registry are not registered.");
}
On Oct 5, 2009, at 10:51 AM, Richard S. Hall wrote:
On 10/4/09 22:02, Guo Du wrote:
On Sun, Oct 4, 2009 at 8:37 PM, Vlatko
Davidovski<[email protected]> wrote:
Or, should I use ServiceTrackerCustomizer in such a case?
Regards,
Vlatko
You may also register a org.osgi.framework.ServiceListener from
aparat-registry to take action on ServiceEvent.REGISTERED for your
service interface.
If you need to listen for service events, using the ServiceTracker is
probably easier than using the base API...or you could use something
like DS or iPOJO.
The whole point, though, is if one of your components depends on the
other, this dependencies should be realized via a service where it
listens for the service to become available. This eliminates the
startup ordering issue. How you achieve this (i.e., base API,
ServiceTracker, iPOJO, etc.) is just an implementation detail.
-> richard
-Guo
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]