Class ServiceBindings

java.lang.Object
org.eclipse.sisu.osgi.ServiceBindings
All Implemented Interfaces:
BindingPublisher

public final class ServiceBindings extends Object implements BindingPublisher
On-demand publisher of Bindings from the OSGi service registry.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private final String[]
     
    private final org.osgi.framework.BundleContext
     
    private final String[]
     
    private final int
     
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    ServiceBindings(org.osgi.framework.BundleContext context)
    Creates new publisher of service bindings, using the given OSGi BundleContext to track services.

    Uses default allow/ignore settings and assigns any published services the lowest possible ranking.
    ServiceBindings(org.osgi.framework.BundleContext context, String allow, String ignore, int maxRank)
    Creates new publisher of service bindings, using the given OSGi BundleContext 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

    Modifier and Type
    Method
    Description
    <T> T
    adapt(Class<T> type)
    Attempts to adapt this publisher to the given type.
    static String
    Configured by org.eclipse.sisu.osgi.ServiceBindings.allow system property.
    static String
    Configured by org.eclipse.sisu.osgi.ServiceBindings.ignore system property.
    int
    Estimates the maximum rank this publisher may assign to a Binding.
    private static String[]
     
    private boolean
    shouldTrack(String clazzName)
     
    <T> void
    Subscribes the given BindingSubscriber to receive Bindings.
    <T> void
    Stops the given BindingSubscriber from receiving Bindings.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • trackers

      private final ConcurrentMap<String,BindingTracker<?>> trackers
    • context

      private final org.osgi.framework.BundleContext context
    • allowed

      private final String[] allowed
    • ignored

      private final String[] ignored
    • maxRank

      private final int maxRank
  • Constructor Details

    • ServiceBindings

      public ServiceBindings(org.osgi.framework.BundleContext context, String allow, String ignore, int maxRank)
      Creates new publisher of service bindings, using the given OSGi BundleContext 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 context
      allow - Globbed pattern of packages/types to allow
      ignore - Globbed pattern of packages/types to ignore
      maxRank - Maximum binding rank
    • ServiceBindings

      public ServiceBindings(org.osgi.framework.BundleContext context)
      Creates new publisher of service bindings, using the given OSGi BundleContext to track services.

      Uses default allow/ignore settings and assigns any published services the lowest possible ranking.
      Parameters:
      context - The tracking context
  • Method Details

    • defaultAllow

      public static String defaultAllow()
      Configured by org.eclipse.sisu.osgi.ServiceBindings.allow system property.
      Returns:
      Globbed pattern of types to allow
    • defaultIgnore

      public static String defaultIgnore()
      Configured by org.eclipse.sisu.osgi.ServiceBindings.ignore system property.
      Returns:
      Globbed pattern of types to ignore
    • subscribe

      public <T> void subscribe(BindingSubscriber<T> subscriber)
      Description copied from interface: BindingPublisher
      Subscribes the given BindingSubscriber to receive Bindings.
      Specified by:
      subscribe in interface BindingPublisher
      Parameters:
      subscriber - The subscriber
    • unsubscribe

      public <T> void unsubscribe(BindingSubscriber<T> subscriber)
      Description copied from interface: BindingPublisher
      Stops the given BindingSubscriber from receiving Bindings.
      Specified by:
      unsubscribe in interface BindingPublisher
      Parameters:
      subscriber - The subscriber
    • maxBindingRank

      public int maxBindingRank()
      Description copied from interface: BindingPublisher
      Estimates the maximum rank this publisher may assign to a Binding.
      Specified by:
      maxBindingRank in interface BindingPublisher
      Returns:
      Maximum binding rank
    • adapt

      public <T> T adapt(Class<T> type)
      Description copied from interface: BindingPublisher
      Attempts to adapt this publisher to the given type.
      Specified by:
      adapt in interface BindingPublisher
      Parameters:
      type - The target type
      Returns:
      Adapted instance; null if it couldn't be adapted
    • shouldTrack

      private boolean shouldTrack(String clazzName)
    • parseGlobs

      private static String[] parseGlobs(String globs)