Package org.eclipse.sisu.osgi
Class ServiceBindings
- java.lang.Object
-
- org.eclipse.sisu.osgi.ServiceBindings
-
- All Implemented Interfaces:
BindingPublisher
public final class ServiceBindings extends java.lang.Object implements BindingPublisher
On-demand publisher ofBinding
s from the OSGi service registry.
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.regex.Pattern[]
allowed
private org.osgi.framework.BundleContext
context
private static java.util.regex.Pattern
GLOB_SYNTAX
private java.util.regex.Pattern[]
ignored
private int
maxRank
private java.util.concurrent.ConcurrentMap<java.lang.String,BindingTracker<?>>
trackers
-
Constructor Summary
Constructors Constructor Description ServiceBindings(org.osgi.framework.BundleContext context)
Creates new publisher of service bindings, using the given OSGiBundleContext
to track services.
Uses default allow/ignore settings and assigns any published services the lowest possible ranking.ServiceBindings(org.osgi.framework.BundleContext context, java.lang.String allow, java.lang.String ignore, int maxRank)
Creates new publisher of service bindings, using the given OSGiBundleContext
to track services.
The globbed patterns control whether tracking requests for particular types are allowed or ignored.
Any published bindings are ranked according to their service ranking (up to the given maximum).
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static java.lang.String
defaultAllow()
static java.lang.String
defaultIgnore()
int
maxBindingRank()
Estimates the maximum rank this publisher may assign to aBinding
.private static java.util.regex.Pattern[]
parseGlobs(java.lang.String globs)
private boolean
shouldTrack(java.lang.String clazzName)
<T> void
subscribe(BindingSubscriber<T> subscriber)
Subscribes the givenBindingSubscriber
to receiveBinding
s.<T> void
unsubscribe(BindingSubscriber<T> subscriber)
Stops the givenBindingSubscriber
from receivingBinding
s.
-
-
-
Field Detail
-
GLOB_SYNTAX
private static final java.util.regex.Pattern GLOB_SYNTAX
-
trackers
private final java.util.concurrent.ConcurrentMap<java.lang.String,BindingTracker<?>> trackers
-
context
private final org.osgi.framework.BundleContext context
-
allowed
private final java.util.regex.Pattern[] allowed
-
ignored
private final java.util.regex.Pattern[] ignored
-
maxRank
private final int maxRank
-
-
Constructor Detail
-
ServiceBindings
public ServiceBindings(org.osgi.framework.BundleContext context, java.lang.String allow, java.lang.String ignore, int maxRank)
Creates new publisher of service bindings, using the given OSGiBundleContext
to track services.
The globbed patterns control whether tracking requests for particular types are allowed or ignored.
Any published bindings are ranked according to their service ranking (up to the given maximum).- Parameters:
context
- The tracking contextallow
- Globbed pattern of packages/types to allowignore
- Globbed pattern of packages/types to ignoremaxRank
- Maximum binding rank
-
ServiceBindings
public ServiceBindings(org.osgi.framework.BundleContext context)
Creates new publisher of service bindings, using the given OSGiBundleContext
to track services.
Uses default allow/ignore settings and assigns any published services the lowest possible ranking.- Parameters:
context
- The tracking context
-
-
Method Detail
-
defaultAllow
public static java.lang.String defaultAllow()
- Returns:
- Globbed pattern of types to allow
-
defaultIgnore
public static java.lang.String defaultIgnore()
- Returns:
- Globbed pattern of types to ignore
-
subscribe
public <T> void subscribe(BindingSubscriber<T> subscriber)
Description copied from interface:BindingPublisher
Subscribes the givenBindingSubscriber
to receiveBinding
s.- Specified by:
subscribe
in interfaceBindingPublisher
- Parameters:
subscriber
- The subscriber
-
unsubscribe
public <T> void unsubscribe(BindingSubscriber<T> subscriber)
Description copied from interface:BindingPublisher
Stops the givenBindingSubscriber
from receivingBinding
s.- Specified by:
unsubscribe
in interfaceBindingPublisher
- Parameters:
subscriber
- The subscriber
-
maxBindingRank
public int maxBindingRank()
Description copied from interface:BindingPublisher
Estimates the maximum rank this publisher may assign to aBinding
.- Specified by:
maxBindingRank
in interfaceBindingPublisher
- Returns:
- Maximum binding rank
-
shouldTrack
private boolean shouldTrack(java.lang.String clazzName)
-
parseGlobs
private static java.util.regex.Pattern[] parseGlobs(java.lang.String globs)
-
-