Class AbstractBinder
- All Implemented Interfaces:
DynamicConfiguration
,Binder
- Direct Known Subclasses:
EnableLookupExceptionsModule
,ImmediateScopeModule
,InheritableThreadScopeModule
,PerThreadScopeModule
,RunLevelServiceModule
,TopicDistributionModule
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate DynamicConfiguration
private AbstractBindingBuilder
<?> private HK2Loader
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<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> 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.addActiveFactoryDescriptor
(Class<? extends Factory<T>> rawFactoryClass) This adds two active descriptors to the system based completely on the analysis of the givenFactory
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> 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 theServiceLocatorUtilities.bind(org.glassfish.hk2.api.ServiceLocator, Binder...)
method for each binder given.bind
(FactoryDescriptors factoryDescriptors) This method will bind the descriptors found in theFactoryDescriptors
.bind
(FactoryDescriptors factoryDescriptors, boolean requiresDeepCopy) This method will bind the descriptors found in theFactoryDescriptors
.<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.private void
complete()
private DynamicConfiguration
Get the activebinder factory
instance used for binding configuration.protected abstract void
Implement to provide binding definitions using the exposed binding methods.private HK2Loader
final void
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.private <T> AbstractBindingBuilder
<T> resetBuilder
(AbstractBindingBuilder<T> newBuilder) private void
setLoader
(Descriptor descriptor)
-
Field Details
-
configuration
-
currentBuilder
-
defaultLoader
-
-
Constructor Details
-
AbstractBinder
public AbstractBinder()
-
-
Method Details
-
bind
Start building a new class-based service binding. Does NOT bind the service type itself as a contract type.- Type Parameters:
T
- service type.- Parameters:
serviceType
- service class.- Returns:
- initialized binding builder.
-
bindAsContract
Start building a new class-based service binding. Binds the service type itself as a contract type.- Type Parameters:
T
- service type.- Parameters:
serviceType
- service class.- Returns:
- initialized binding builder.
-
bindAsContract
Start building a new generic type-based service binding. Binds the generic service type itself as a contract type.- Type Parameters:
T
- service type.- Parameters:
serviceType
- generic service type information.- Returns:
- initialized binding builder.
-
bindAsContract
Start building a new generic type-based service binding. Binds the generic service type itself as a contract type.- Type Parameters:
T
- service type.- Parameters:
serviceType
- generic service type information.- Returns:
- initialized binding builder.
-
bind
Start building a new instance-based service binding. The binding is naturally considered to be asingleton-scoped
. Does NOT bind the service type itself as a contract type.- Type Parameters:
T
- service type.- Parameters:
service
- service instance.- Returns:
- initialized binding builder.
-
bindFactory
public <T> ServiceBindingBuilder<T> bindFactory(Class<? extends Factory<T>> factoryType, Class<? extends Annotation> factoryScope) Start building a new factory class-based service binding.- Type Parameters:
T
- service type.- Parameters:
factoryType
- service factory class.factoryScope
- factory scope.- Returns:
- initialized binding builder.
-
bindFactory
Start building a new factory class-based service binding. The factory itself is bound in aper-lookup
scope.- Type Parameters:
T
- service type.- Parameters:
factoryType
- service factory class.- Returns:
- initialized binding builder.
-
bindFactory
Start building a new factory instance-based service binding.- Type Parameters:
T
- service type.- Parameters:
factory
- service instance.- Returns:
- initialized binding builder.
-
bind
Description copied from interface:Binder
This method will be called by theServiceLocatorUtilities.bind(org.glassfish.hk2.api.ServiceLocator, Binder...)
method for each binder given. All of the updates will be committed as one commit operation. -
resetBuilder
-
complete
private void complete() -
configure
protected abstract void configure()Implement to provide binding definitions using the exposed binding methods. -
configuration
Get the activebinder factory
instance used for binding configuration. This method can only be called from within the scope of theconfigure()
method.- Returns:
- dynamic configuration instance used for binding configuration.
- Throws:
IllegalStateException
- in case the method is not called from within an active call toconfigure()
method.
-
bind
This method will bind the given descriptor to this Module. If the descriptor given is not an ActiveDescriptor then a non-reified ActiveDescriptor will be returned with the system provided fields set. If the descriptor given is a reified ActiveDescriptor then the descriptor returned will be a reified ActiveDescriptor that takes all values except for the id from the given descriptor. A deep copy will be made of the incoming descriptorThis method can be called only in the execution context of the
configure()
method.- Specified by:
bind
in interfaceDynamicConfiguration
- Parameters:
descriptor
- May not be null. Will be used to derive the various key fields associated with the given provider- Returns:
- The entry as added to the service registry, with fields of the Descriptor filled in by the system as appropriate
-
bind
Description copied from interface:DynamicConfiguration
This method will bind the given descriptor to this Module. If the descriptor given is not an ActiveDescriptor then a non-reified ActiveDescriptor will be returned with the system provided fields set. If the descriptor given is a reified ActiveDescriptor then the descriptor returned will be a reified ActiveDescriptor that takes all values except for the id from the given descriptor.- Specified by:
bind
in interfaceDynamicConfiguration
- Parameters:
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)- Returns:
- The entry as added to the service registry, with fields of the Descriptor filled in by the system as appropriate
-
bind
This method will bind the descriptors found in theFactoryDescriptors
. This method will first validate the descriptors from theFactoryDescriptors
and then simply bind them into this configuration as two independent descriptors. A deep copy will be made of both descriptorsThis method can be called only in the execution context of the
configure()
method.- Specified by:
bind
in interfaceDynamicConfiguration
- Parameters:
factoryDescriptors
- A description of a factory service and the type the factory service provides. May not be null- Returns:
- The descriptors returned from this object may be cast to ActiveDescriptor and will contain all the fields of the descriptors filled in by the system
-
bind
Description copied from interface:DynamicConfiguration
This method will bind the descriptors found in theFactoryDescriptors
. This method will first validate the descriptors from theFactoryDescriptors
and then simply bind them into this configuration as two independent descriptors. A deep copy will be made of both descriptors- Specified by:
bind
in interfaceDynamicConfiguration
- Parameters:
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)- Returns:
- The descriptors returned from this object may be cast to ActiveDescriptor and will contain all the fields of the descriptors filled in by the system
-
addActiveDescriptor
public <T> ActiveDescriptor<T> addActiveDescriptor(ActiveDescriptor<T> activeDescriptor) throws IllegalArgumentException This allows third party systems to add reified active descriptors to the system. The active descriptor given must be fully reified (isReified must return true) and the create and destroy methods must be implemented. A deep copy will be made of the descriptorThis method can be called only in the execution context of the
configure()
method.- Specified by:
addActiveDescriptor
in interfaceDynamicConfiguration
- Parameters:
activeDescriptor
- The reified active descriptor to be added to the system. The system will not attempt to reify this descriptor itself- Returns:
- The entry as added to the service registry, with fields of the Descriptor filled in by the system as appropriate
- Throws:
IllegalArgumentException
- if the descriptor is not reified
-
addActiveDescriptor
public <T> ActiveDescriptor<T> addActiveDescriptor(ActiveDescriptor<T> activeDescriptor, boolean requiresDeepCopy) throws IllegalArgumentException Description copied from interface:DynamicConfiguration
This allows third party systems to add reified active descriptors to the system. The active descriptor given must be fully reified (isReified must return true) and the create and destroy methods must be implemented. A deep copy will be made of the descriptor- Specified by:
addActiveDescriptor
in interfaceDynamicConfiguration
- Parameters:
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)- Returns:
- The entry as added to the service registry, with fields of the Descriptor filled in by the system as appropriate
- Throws:
IllegalArgumentException
- if the descriptor is not reified
-
addActiveDescriptor
public <T> ActiveDescriptor<T> addActiveDescriptor(Class<T> rawClass) throws MultiException, IllegalArgumentException This adds an active descriptor to the system based completely on the analysis of the given class. The 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.This method can be called only in the execution context of the
configure()
method.- Specified by:
addActiveDescriptor
in interfaceDynamicConfiguration
- Parameters:
rawClass
- The class to analyze, must not be null- Returns:
- The active (reified) descriptor that has been added to the system, with all fields filled in based on the rawClass
- Throws:
MultiException
- If this class cannot be a serviceIllegalArgumentException
- if rawClass is null
-
addActiveFactoryDescriptor
public <T> FactoryDescriptors addActiveFactoryDescriptor(Class<? extends Factory<T>> rawFactoryClass) throws MultiException, IllegalArgumentException This adds two active descriptors to the system based completely on the analysis of the givenFactory
class. TheFactory
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 theFactory.provide()
method will provide the scope and qualifiers of the service produced by theFactory
This method can be called only in the execution context of the
configure()
method.- Specified by:
addActiveFactoryDescriptor
in interfaceDynamicConfiguration
- Parameters:
rawFactoryClass
- The class to analyze, must not be null- Returns:
- The factory descriptors that have been added to the system, with all fields filled in based on the rawFactoryClass
- Throws:
MultiException
- If this class cannot be a serviceIllegalArgumentException
- if rawClass is null
-
addUnbindFilter
This filter will added to the list of filters in this Configuration that will determine which Descriptors will be removed from the system. Only services directly from this Configuration objects' associated ServiceLocator will be given to this Filter (it will not be given descriptors from the ServiceLocators parent). The descriptors passed into this filter may be cast toActiveDescriptor
. 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.- Specified by:
addUnbindFilter
in interfaceDynamicConfiguration
- Parameters:
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 null- Throws:
IllegalArgumentException
- if unbindFilter is null
-
addIdempotentFilter
At commit time all idempotent filters in this dynamic configuration will be run against all validation-visible descriptors. If any of the idempotent filters are a match then the commit will FAIL and none of the descriptors in this DynamicConfiguration will be added or removed. The idempotent filters will be run under the same lock as the commit, and hence can guarantee true idempotency of the transaction.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 serviceThe 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 requiredThis method can be called only in the execution context of the
configure()
method.- Specified by:
addIdempotentFilter
in interfaceDynamicConfiguration
- Parameters:
unbindFilter
- A non-null idempotent filter to use during commit. If any descriptors match the filter, the commit will fail- Throws:
IllegalArgumentException
- If any of the filters are null
-
registerTwoPhaseResources
Description copied from interface:DynamicConfiguration
Registers two-phase resources in the order in which they are to run. Subsequent calls to this method will add resources at the end of the existing list- Specified by:
registerTwoPhaseResources
in interfaceDynamicConfiguration
- Parameters:
resources
- A list of resources to add to this dynamic configuration
-
commit
This causes the configuration to get committed. This method may only be called onceThis method can be called only in the execution context of the
configure()
method.- Specified by:
commit
in interfaceDynamicConfiguration
- Throws:
MultiException
- If errors were found in the commit process
-
install
Adds all binding definitions from the binders to the binding configuration.- Parameters:
binders
- binders whose binding definitions should be configured.
-
setLoader
-
getDefaultBinderLoader
-