Java Reference
In-Depth Information
you to track services as they're registered and unregistered, and take appropriate
actions. But they also simplify normal service access by eliminating the need to unget
services. For this reason, using service trackers instead of service references is consid-
ered a best practice. The following code gets a service using a ServiceTracker , but with
the error handling code that was missing from the earlier ServiceReference example:
String name = SpecialOffer.class.getName();
ServiceTracker<SpecialOffer, SpecialOffer> tracker;
tracker = new ServiceTracker<SpecialOffer, SpecialOffer>(
ctx, name, null);;
SpecialOffer offer = (SpecialOffer) tracker.getService();
if (offer == null) {
throw new RuntimeException(
"The SpecialOffer service is not available.");
ServiceTracker s also allow you to access services in a way that's slightly insulated
from startup order effects; because bundles may start in any order in an OSG i frame-
work, services may be registered in any order. Code that expects services to always be
present may work most of the time, but then drive you crazy with timing bugs. As with
most things to do with service access, Blueprint eliminates this complexity. If you
aren't using Blueprint, it would be a good idea to wait for a service as follows, rather
than getting it and expecting it to be present:
SpecialOffer offer = (SpecialOffer) tracker.waitForService(TIMEOUT);
Filters are widely used in OSG i. They're sometimes used in bundle manifests, but their
main use is in looking up services. The OSG i filter syntax will be familiar to those who
write LDAP filters. Every filter expression has the following general format:
(There shouldn't be any whitespace between the elements in the filters.) Attribute is
the name of the property to be selected for, Operator is a Boolean operator, and
Value is the value to be matched. The "=" , "~=" , "<=" , ">=" , and "!" operators are
supported. The reserved characters "\" , "*" , "(" , and ")" must be escaped if they're
contained in the value.
For example,
matches something whose aisle is fruit.
Search WWH ::

Custom Search