|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.ops4j.peaberry.Peaberry
public final class Peaberry
Guice extension that supports injection and outjection of dynamic services.
For example, injecting a stock quote service:
@Inject StockQuote quote; ... bind(StockQuote.class).toProvider(service(StockQuote.class).single());Injecting many stock quote services:
@Inject Iterable<StockQuote> quotes; ... bind(iterable(StockQuote.class)).toProvider(service(StockQuote.class).multiple());Exporting an implementation as a stock quote service:
@Inject // the service can be controlled by the Export handle Export<StockQuote> exportedQuote; ... // the service is exported at injection time bind(export(StockQuote.class)).toProvider(service(myQuoteImpl).export());Applying a custom filter to find a specific service:
service(StockQuote.class).filter(ldap("(Currency=GBP)")).single()
Applying custom attributes to an exported service:
service(myQuoteImpl).attributes(names("Currency=GBP")).export()
(the ldap and names utility methods are from org.ops4j.peaberry.util)
You can also decorate services with additional behaviour:
service(StockQuote.class).decoratedWith(someDecoratorImpl).single()or ask for them to be injected directly, instead of using a dynamic proxy:
service(StockQuote.class).single().direct()similarly, if you don't want to bother with an Export handle when exporting:
service(myQuoteImpl).export().direct()Outjection is a way of actively monitoring for services instead of polling:
service(StockQuote.class).out(myWatcherImpl).multiple()the given watcher is notified when matching services appear and disappear.
org.ops4j.peaberry.util has abstract watcher and decorator classes)
See the online User Guide for the latest examples and suggested best practice.
| Field Summary | |
|---|---|
static String |
CACHE_GENERATIONS_HINT
Name of system property ( "org.ops4j.peaberry.cache.generations")
suggests the number of flushes before an unused service is released. |
static String |
CACHE_INTERVAL_HINT
Name of system property ( "org.ops4j.peaberry.cache.interval")
suggests the time in milliseconds between flushes of the service cache. |
static String |
NATIVE_FILTER_HINT
Name of system property ( "org.ops4j.peaberry.filter.native")
suggests using AttributeFilter.toString() as native filter. |
| Method Summary | ||
|---|---|---|
static com.google.inject.Module |
osgiModule(org.osgi.framework.BundleContext bundleContext)
Create a new Guice binding Module for the given bundle context. |
|
static com.google.inject.Module |
osgiModule(org.osgi.framework.BundleContext bundleContext,
ServiceRegistry... registries)
Create a new Guice binding Module for the given bundle context
along with a list of additional ServiceRegistrys to query when
injecting or watching for services. |
|
static com.google.inject.Module |
osgiModule(ServiceRegistry... registries)
Create a new Guice binding Module that uses an externally bound
bundle context along with a list of additional ServiceRegistrys
to query when injecting or watching for services. |
|
static
|
service(Class<T> clazz)
Start building a dynamic service provider for the given class. |
|
static
|
service(com.google.inject.Key<T> key)
Start building a dynamic service provider for the given key. |
|
static
|
service(T instance)
Start building a dynamic service provider for the given instance. |
|
static
|
service(com.google.inject.TypeLiteral<T> type)
Start building a dynamic service provider for the given type. |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final String CACHE_INTERVAL_HINT
"org.ops4j.peaberry.cache.interval")
suggests the time in milliseconds between flushes of the service cache.
public static final String CACHE_GENERATIONS_HINT
"org.ops4j.peaberry.cache.generations")
suggests the number of flushes before an unused service is released.
public static final String NATIVE_FILTER_HINT
"org.ops4j.peaberry.filter.native")
suggests using AttributeFilter.toString() as native filter.
| Method Detail |
|---|
public static <T> DecoratedServiceBuilder<T> service(com.google.inject.Key<T> key)
key - binding key
public static <T> DecoratedServiceBuilder<T> service(com.google.inject.TypeLiteral<T> type)
type - binding type
public static <T> DecoratedServiceBuilder<T> service(Class<T> clazz)
clazz - binding class
public static <T> DecoratedServiceBuilder<T> service(T instance)
instance - service instance
public static com.google.inject.Module osgiModule(org.osgi.framework.BundleContext bundleContext)
Module for the given bundle context.
bundleContext - current bundle context
public static com.google.inject.Module osgiModule(org.osgi.framework.BundleContext bundleContext,
ServiceRegistry... registries)
Module for the given bundle context
along with a list of additional ServiceRegistrys to query when
injecting or watching for services.
bundleContext - current bundle contextregistries - extra service registries
public static com.google.inject.Module osgiModule(ServiceRegistry... registries)
Module that uses an externally bound
bundle context along with a list of additional ServiceRegistrys
to query when injecting or watching for services.
registries - extra service registries
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||