Top Description Fields Constructors Methods
org.jvnet.hk2.internal

public Class DynamicConfigurationImpl

extends Object
implements DynamicConfiguration
Class Inheritance
All Implemented Interfaces
org.glassfish.hk2.api.DynamicConfiguration
Imports
java.util.Arrays, .LinkedList, java.util.concurrent.locks.ReentrantLock, org.glassfish.hk2.api.ActiveDescriptor, .Descriptor, .DescriptorType, .DynamicConfiguration, .Factory, .FactoryDescriptors, .Filter, .MultiException, .TwoPhaseResource, org.glassfish.hk2.utilities.FactoryDescriptorsImpl, org.glassfish.hk2.utilities.reflection.Pretty

The system implementation of the DynamicConfiguration service
Author
jwells

Field Summary

Modifier and TypeField and Description
private final LinkedList<SystemDescriptor<?>>
private final LinkedList<Filter>
private final LinkedList<TwoPhaseResource>
private final LinkedList<Filter>
private boolean
private final ServiceLocatorImpl
private final ReentrantLock

Constructor Summary

AccessConstructor and Description
public
DynamicConfigurationImpl(ServiceLocatorImpl
The locator for which this will be the configuration service
locator
)

Created by the generator, and hence must be public

Method Summary

Modifier and TypeMethod and Description
public <T> ActiveDescriptor<T>
addActiveDescriptor(ActiveDescriptor<T> activeDescriptor)

Implements org.glassfish.hk2.api.DynamicConfiguration.addActiveDescriptor.

This allows third party systems to add reified active descriptors to the system.

public <T> ActiveDescriptor<T>
addActiveDescriptor(ActiveDescriptor<T> activeDescriptor, boolean requiresDeepCopy)

Implements org.glassfish.hk2.api.DynamicConfiguration.addActiveDescriptor.

This allows third party systems to add reified active descriptors to the system.

public <T> ActiveDescriptor<T>
addActiveDescriptor(Class<T> rawClass)

Implements org.glassfish.hk2.api.DynamicConfiguration.addActiveDescriptor.

This adds an active descriptor to the system based completely on the analysis of the given class.

public <T> FactoryDescriptors
addActiveFactoryDescriptor(Class<? extends Factory<T>> rawFactoryClass)

Implements org.glassfish.hk2.api.DynamicConfiguration.addActiveFactoryDescriptor.

This adds two active descriptors to the system based completely on the analysis of the given Factory class.

public void
addIdempotentFilter(Filter... idempotentFilter)

Implements org.glassfish.hk2.api.DynamicConfiguration.addIdempotentFilter.

At commit time all idempotent filters in this dynamic configuration will be run against all validation-visible descriptors.

public void
addUnbindFilter(Filter unbindFilter)

Implements org.glassfish.hk2.api.DynamicConfiguration.addUnbindFilter.

This filter will added to the list of filters in this Configuration that will determine which Descriptors will be removed from the system.

public <T> ActiveDescriptor<T>
bind(Descriptor key)

Implements org.glassfish.hk2.api.DynamicConfiguration.bind.

This method will bind the given descriptor to this Module.

public <T> ActiveDescriptor<T>
bind(Descriptor key, boolean requiresDeepCopy)

Implements org.glassfish.hk2.api.DynamicConfiguration.bind.

This method will bind the given descriptor to this Module.

public FactoryDescriptors
bind(FactoryDescriptors factoryDescriptors)

Implements org.glassfish.hk2.api.DynamicConfiguration.bind.

This method will bind the descriptors found in the FactoryDescriptors.

public FactoryDescriptors
bind(FactoryDescriptors factoryDescriptors, boolean requiresDeepCopy)

Implements org.glassfish.hk2.api.DynamicConfiguration.bind.

This method will bind the descriptors found in the FactoryDescriptors.

private static void
private static void
private void
public void
commit()

Implements org.glassfish.hk2.api.DynamicConfiguration.commit.

This causes the configuration to get committed.

pack-priv LinkedList<SystemDescriptor<?>>
getAllDescriptors()

Returns: the allDescriptors

pack-priv LinkedList<Filter>
pack-priv LinkedList<TwoPhaseResource>
pack-priv LinkedList<Filter>
public void
registerTwoPhaseResources(TwoPhaseResource... resources)

Implements org.glassfish.hk2.api.DynamicConfiguration.registerTwoPhaseResources.

Registers two-phase resources in the order in which they are to run.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

allDescriptorsback to summary
private final LinkedList<SystemDescriptor<?>> allDescriptors
allIdempotentFiltersback to summary
private final LinkedList<Filter> allIdempotentFilters
allResourcesback to summary
private final LinkedList<TwoPhaseResource> allResources
allUnbindFiltersback to summary
private final LinkedList<Filter> allUnbindFilters
committedback to summary
private boolean committed
locatorback to summary
private final ServiceLocatorImpl locator
lockback to summary
private final ReentrantLock lock

Constructor Detail

DynamicConfigurationImplback to summary
public DynamicConfigurationImpl(ServiceLocatorImpl locator)

Created by the generator, and hence must be public

Parameters
locator:ServiceLocatorImpl

The locator for which this will be the configuration service

Method Detail

addActiveDescriptorback to summary
public <T> ActiveDescriptor<T> addActiveDescriptor(ActiveDescriptor<T> activeDescriptor) throws IllegalArgumentException

Implements org.glassfish.hk2.api.DynamicConfiguration.addActiveDescriptor.

Doc from org.glassfish.hk2.api.DynamicConfiguration.addActiveDescriptor.

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

Annotations
@Override
Exceptions
IllegalArgumentException:
if the descriptor is not reified
addActiveDescriptorback to summary
public <T> ActiveDescriptor<T> addActiveDescriptor(ActiveDescriptor<T> activeDescriptor, boolean requiresDeepCopy) throws IllegalArgumentException

Implements org.glassfish.hk2.api.DynamicConfiguration.addActiveDescriptor.

Doc from org.glassfish.hk2.api.DynamicConfiguration.addActiveDescriptor.

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

Annotations
@Override
Exceptions
IllegalArgumentException:
if the descriptor is not reified
addActiveDescriptorback to summary
public <T> ActiveDescriptor<T> addActiveDescriptor(Class<T> rawClass) throws IllegalArgumentException

Implements org.glassfish.hk2.api.DynamicConfiguration.addActiveDescriptor.

Doc from org.glassfish.hk2.api.DynamicConfiguration.addActiveDescriptor.

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.

Annotations
@Override
Exceptions
IllegalArgumentException:
if rawClass is null
addActiveFactoryDescriptorback to summary
public <T> FactoryDescriptors addActiveFactoryDescriptor(Class<? extends Factory<T>> rawFactoryClass) throws MultiException, IllegalArgumentException

Implements org.glassfish.hk2.api.DynamicConfiguration.addActiveFactoryDescriptor.

Doc from org.glassfish.hk2.api.DynamicConfiguration.addActiveFactoryDescriptor.

This adds two active descriptors to the system based completely on the analysis of the given 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

Annotations
@Override
Exceptions
MultiException:
If this class cannot be a service
IllegalArgumentException:
if rawClass is null
addIdempotentFilterback to summary
public void addIdempotentFilter(Filter... idempotentFilter) throws IllegalArgumentException

Implements org.glassfish.hk2.api.DynamicConfiguration.addIdempotentFilter.

Doc from org.glassfish.hk2.api.DynamicConfiguration.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 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

Annotations
@Override
Exceptions
IllegalArgumentException:
If any of the filters are null
addUnbindFilterback to summary
public void addUnbindFilter(Filter unbindFilter) throws IllegalArgumentException

Implements org.glassfish.hk2.api.DynamicConfiguration.addUnbindFilter.

Doc from org.glassfish.hk2.api.DynamicConfiguration.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 to 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.

Annotations
@Override
Exceptions
IllegalArgumentException:
if unbindFilter is null
bindback to summary
public <T> ActiveDescriptor<T> bind(Descriptor key)

Implements org.glassfish.hk2.api.DynamicConfiguration.bind.

Doc from org.glassfish.hk2.api.DynamicConfiguration.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 descriptor

Annotations
@Override
bindback to summary
public <T> ActiveDescriptor<T> bind(Descriptor key, boolean requiresDeepCopy)

Implements org.glassfish.hk2.api.DynamicConfiguration.bind.

Doc from org.glassfish.hk2.api.DynamicConfiguration.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.

Annotations
@Override
bindback to summary
public FactoryDescriptors bind(FactoryDescriptors factoryDescriptors)

Implements org.glassfish.hk2.api.DynamicConfiguration.bind.

Doc from org.glassfish.hk2.api.DynamicConfiguration.bind.

This method will bind the descriptors found in the 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

Annotations
@Override
bindback to summary
public FactoryDescriptors bind(FactoryDescriptors factoryDescriptors, boolean requiresDeepCopy)

Implements org.glassfish.hk2.api.DynamicConfiguration.bind.

Doc from org.glassfish.hk2.api.DynamicConfiguration.bind.

This method will bind the descriptors found in the 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

Annotations
@Override
checkDescriptorback to summary
private static void checkDescriptor(Descriptor d)
checkReifiedDescriptorback to summary
private static void checkReifiedDescriptor(ActiveDescriptor<?> d)
checkStateback to summary
private void checkState()
commitback to summary
public void commit() throws MultiException

Implements org.glassfish.hk2.api.DynamicConfiguration.commit.

Doc from org.glassfish.hk2.api.DynamicConfiguration.commit.

This causes the configuration to get committed. This method may only be called once

Annotations
@Override
Exceptions
MultiException:
If errors were found in the commit process
getAllDescriptorsback to summary
pack-priv LinkedList<SystemDescriptor<?>> getAllDescriptors()
Returns:LinkedList<SystemDescriptor<?>>

the allDescriptors

getIdempotentFiltersback to summary
pack-priv LinkedList<Filter> getIdempotentFilters()
getResourcesback to summary
pack-priv LinkedList<TwoPhaseResource> getResources()
getUnbindFiltersback to summary
pack-priv LinkedList<Filter> getUnbindFilters()
registerTwoPhaseResourcesback to summary
public void registerTwoPhaseResources(TwoPhaseResource... resources)

Implements org.glassfish.hk2.api.DynamicConfiguration.registerTwoPhaseResources.

Doc from org.glassfish.hk2.api.DynamicConfiguration.registerTwoPhaseResources.

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

Annotations
@Override
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Annotations
@Override