public abstract class AbstractBinder extends Object implements Binder, DynamicConfiguration
Constructor and Description |
---|
AbstractBinder() |
Modifier and Type | Method and Description |
---|---|
<T> ActiveDescriptor<T> |
addActiveDescriptor(ActiveDescriptor<T> activeDescriptor)
This allows third party systems to add reified active descriptors to the system.
|
<T> ActiveDescriptor<T> |
addActiveDescriptor(ActiveDescriptor<T> activeDescriptor,
boolean requiresDeepCopy)
This allows third party systems to add reified active descriptors to the system.
|
<T> ActiveDescriptor<T> |
addActiveDescriptor(Class<T> rawClass)
This adds an active descriptor to the system based completely on the analysis
of the given class.
|
<T> FactoryDescriptors |
addActiveFactoryDescriptor(Class<? extends Factory<T>> rawFactoryClass)
This adds two active descriptors to the system based completely on the analysis
of the given
Factory class. |
void |
addIdempotentFilter(Filter... unbindFilter)
At commit time all idempotent filters in this dynamic configuration will be run
against all validation-visible descriptors.
|
void |
addUnbindFilter(Filter unbindFilter)
This filter will added to the list of filters in this Configuration that will
determine which Descriptors will be removed from the system.
|
<T> ServiceBindingBuilder<T> |
bind(Class<T> serviceType)
Start building a new class-based service binding.
|
<T> ActiveDescriptor<T> |
bind(Descriptor descriptor)
This method will bind the given descriptor to this Module.
|
<T> ActiveDescriptor<T> |
bind(Descriptor descriptor,
boolean requiresDeepCopy)
This method will bind the given descriptor to this Module.
|
void |
bind(DynamicConfiguration configuration)
This method will be called by the
ServiceLocatorUtilities.bind(org.glassfish.hk2.api.ServiceLocator, Binder...) method for each
binder given. |
FactoryDescriptors |
bind(FactoryDescriptors factoryDescriptors)
This method will bind the descriptors found in the
FactoryDescriptors . |
FactoryDescriptors |
bind(FactoryDescriptors factoryDescriptors,
boolean requiresDeepCopy)
This method will bind the descriptors found in the
FactoryDescriptors . |
<T> ScopedBindingBuilder<T> |
bind(T service)
Start building a new instance-based service binding.
|
<T> ServiceBindingBuilder<T> |
bindAsContract(Class<T> serviceType)
Start building a new class-based service binding.
|
<T> ServiceBindingBuilder<T> |
bindAsContract(Type serviceType)
Start building a new generic type-based service binding.
|
<T> ServiceBindingBuilder<T> |
bindAsContract(TypeLiteral<T> serviceType)
Start building a new generic type-based service binding.
|
<T> ServiceBindingBuilder<T> |
bindFactory(Class<? extends Factory<T>> factoryType)
Start building a new factory class-based service binding.
|
<T> ServiceBindingBuilder<T> |
bindFactory(Class<? extends Factory<T>> factoryType,
Class<? extends Annotation> factoryScope)
Start building a new factory class-based service binding.
|
<T> ServiceBindingBuilder<T> |
bindFactory(Factory<T> factory)
Start building a new factory instance-based service binding.
|
void |
commit()
This causes the configuration to get committed.
|
protected abstract void |
configure()
Implement to provide binding definitions using the exposed binding
methods.
|
void |
install(Binder... binders)
Adds all binding definitions from the binders to the binding configuration.
|
void |
registerTwoPhaseResources(TwoPhaseResource... resources)
Registers two-phase resources in the order in which they are to run.
|
public <T> ServiceBindingBuilder<T> bind(Class<T> serviceType)
T
- service type.serviceType
- service class.public <T> ServiceBindingBuilder<T> bindAsContract(Class<T> serviceType)
T
- service type.serviceType
- service class.public <T> ServiceBindingBuilder<T> bindAsContract(TypeLiteral<T> serviceType)
T
- service type.serviceType
- generic service type information.public <T> ServiceBindingBuilder<T> bindAsContract(Type serviceType)
T
- service type.serviceType
- generic service type information.public <T> ScopedBindingBuilder<T> bind(T service)
singleton-scoped
.
Does NOT bind the service type itself as a contract type.T
- service type.service
- service instance.public <T> ServiceBindingBuilder<T> bindFactory(Class<? extends Factory<T>> factoryType, Class<? extends Annotation> factoryScope)
T
- service type.factoryType
- service factory class.factoryScope
- factory scope.public <T> ServiceBindingBuilder<T> bindFactory(Class<? extends Factory<T>> factoryType)
per-lookup
scope.T
- service type.factoryType
- service factory class.public <T> ServiceBindingBuilder<T> bindFactory(Factory<T> factory)
T
- service type.factory
- service instance.public void bind(DynamicConfiguration configuration)
Binder
ServiceLocatorUtilities.bind(org.glassfish.hk2.api.ServiceLocator, Binder...)
method for each
binder given. All of the updates will be committed as one commit operation.protected abstract void configure()
public <T> ActiveDescriptor<T> bind(Descriptor descriptor)
This method can be called only in the execution context of the configure()
method.
bind
in interface DynamicConfiguration
descriptor
- May not be null. Will be used to derive the various
key fields associated with the given providerpublic <T> ActiveDescriptor<T> bind(Descriptor descriptor, boolean requiresDeepCopy)
DynamicConfiguration
bind
in interface DynamicConfiguration
descriptor
- May not be null. Will be used to derive the various
key fields associated with the given providerrequiresDeepCopy
- If true a deep copy will be made of the
key. If false then the Descriptor will be used as is, and it
is the responsibility of the caller to ensure that the fields
of the Descriptor never change (with the exception of any
writeable fields, such as ranking)public FactoryDescriptors bind(FactoryDescriptors factoryDescriptors)
FactoryDescriptors
. This method will first
validate the descriptors from the FactoryDescriptors
and then simply bind them into this configuration as
two independent descriptors. A deep copy will be made
of both descriptors
This method can be called only in the execution context of the configure()
method.
bind
in interface DynamicConfiguration
factoryDescriptors
- A description of a factory service
and the type the factory service provides. May not be nullpublic FactoryDescriptors bind(FactoryDescriptors factoryDescriptors, boolean requiresDeepCopy)
DynamicConfiguration
FactoryDescriptors
. This method will first
validate the descriptors from the FactoryDescriptors
and then simply bind them into this configuration as
two independent descriptors. A deep copy will be made
of both descriptorsbind
in interface DynamicConfiguration
factoryDescriptors
- A description of a factory service
and the type the factory service provides. May not be nullrequiresDeepCopy
- If true a deep copy will be made of the
key. If false then the Descriptor will be used as is, and it
is the responsibility of the caller to ensure that the fields
of the Descriptor never change (with the exception of any
writeable fields, such as ranking)public <T> ActiveDescriptor<T> addActiveDescriptor(ActiveDescriptor<T> activeDescriptor) throws IllegalArgumentException
This method can be called only in the execution context of the configure()
method.
addActiveDescriptor
in interface DynamicConfiguration
activeDescriptor
- The reified active descriptor to be added to the system. The
system will not attempt to reify this descriptor itselfIllegalArgumentException
- if the descriptor is not reifiedpublic <T> ActiveDescriptor<T> addActiveDescriptor(ActiveDescriptor<T> activeDescriptor, boolean requiresDeepCopy) throws IllegalArgumentException
DynamicConfiguration
addActiveDescriptor
in interface DynamicConfiguration
activeDescriptor
- The reified active descriptor to be added to the system. The
system will not attempt to reify this descriptor itselfrequiresDeepCopy
- If true a deep copy will be made of the
key. If false then the Descriptor will be used as is, and it
is the responsibility of the caller to ensure that the fields
of the Descriptor never change (with the exception of any
writeable fields, such as ranking)IllegalArgumentException
- if the descriptor is not reifiedpublic <T> ActiveDescriptor<T> addActiveDescriptor(Class<T> rawClass) throws MultiException, IllegalArgumentException
This method can be called only in the execution context of the configure()
method.
addActiveDescriptor
in interface DynamicConfiguration
rawClass
- The class to analyze, must not be nullMultiException
- If this class cannot be a serviceIllegalArgumentException
- if rawClass is nullpublic <T> FactoryDescriptors addActiveFactoryDescriptor(Class<? extends Factory<T>> rawFactoryClass) throws MultiException, IllegalArgumentException
Factory
class. The Factory
class itself and all
interfaces marked contract will be in the list of advertised services. The scope
and qualifiers will be taken from the annotations on the class. The annotations
on the Factory.provide()
method will provide the scope and qualifiers of the
service produced by the Factory
This method can be called only in the execution context of the configure()
method.
addActiveFactoryDescriptor
in interface DynamicConfiguration
rawFactoryClass
- The class to analyze, must not be nullMultiException
- If this class cannot be a serviceIllegalArgumentException
- if rawClass is nullpublic void addUnbindFilter(Filter unbindFilter) throws IllegalArgumentException
ActiveDescriptor
. The descriptors passed into this
filter may or may not have been reified. This filter should not reify passed in descriptors.
And descriptor for which this filter returns true will be removed from the
ServiceLocator
prior to any additions that are performed with this
Configuration object. Hence a Configuration can remove and add a descriptor of the
same type in one commit.
In order to unbind a filter the caller of commit must pass the LOOKUP validators and the UNBIND validators.
This method can be called only in the execution context of the configure()
method.
addUnbindFilter
in interface DynamicConfiguration
unbindFilter
- This filter will be added to the list of filters that this
configuration object will use to determine which descriptors to unbind from the system.
May not be nullIllegalArgumentException
- if unbindFilter is nullpublic void addIdempotentFilter(Filter... unbindFilter) throws IllegalArgumentException
The normal use case for the use of this filter is to ensure that a service is only added
once to the ServiceLocator
, even when multiple threads may be attempting to add the
same service
The filter passed in should not do any change to the set of descriptors itself, any attempt
to do so will leave the system in an inconsistent state. IndexedFilter
is supported
and is the normal use of an idempotent filter, though it is not required
This method can be called only in the execution context of the configure()
method.
addIdempotentFilter
in interface DynamicConfiguration
unbindFilter
- A non-null idempotent filter to use during commit. If any descriptors
match the filter, the commit will failIllegalArgumentException
- If any of the filters are nullpublic void registerTwoPhaseResources(TwoPhaseResource... resources)
DynamicConfiguration
registerTwoPhaseResources
in interface DynamicConfiguration
resources
- A list of resources to add to this dynamic configurationpublic void commit() throws MultiException
This method can be called only in the execution context of the configure()
method.
commit
in interface DynamicConfiguration
MultiException
- If errors were found in the commit processpublic final void install(Binder... binders)
binders
- binders whose binding definitions should be configured.Copyright © 2009–2019 Oracle Corporation. All rights reserved.