This service is the most fundamental service in an HK2 system. Every service locator starts with a ServiceLocator as a service, and hence ServiceLocators can be injected into every object managed by HK2.
A service locator can have a single parent. Services are looked up in the current service locator and in all the parents of the service locator. If multiple services exist that match the filter they will all be returned. Two services with the same priority are sorted first by service locator id and second by service id. This implies that services directly installed in a ServiceLocator have higher natural priority than those in the parents of the ServiceLocator. Services can also be marked as having visibility LOCAL, in which case they will only be available to the ServiceLocator performing the lookup, and will not leak out to children of that ServiceLocator.
| Modifier and Type | Method and Description |
|---|---|
| public Object | Returns: The return value of the method (null if the method is void type)The non-null object to inject into injectMe, Method The non-null method to inject into method, MethodParameter... A list of parameter values known by the caller. The indexes
in params may not repeat and must be in the valid range of parameters
for the passed in method params)This will invoke the given method on the given object. |
| public Object | Returns: The return value of the method (null if the method is void type)The non-null object to inject into injectMe, Method The non-null method to inject into method, ServiceHandle<?> A possibly null ServiceHandle that can be used after this call
to destroy any hanging PerLookup instances created root, MethodParameter... A list of parameter values known by the caller. The indexes
in params may not repeat and must be in the valid range of parameters
for the passed in method params)This will invoke the given method on the given object. |
| public <T> T | |
| public <T> T | Returns: An instance of the objectThe class to create, may not be null createMe, String The name of the strategy)ClassAnalyzer that should be used. If
null the default analyzer will be usedThis method will analyze the given class, and create it if can. |
| public <U> U | Returns: An instance of the object that has been created, injected and post constructedThe non-null class to create this object from createMe)This method creates, injects and post-constructs an object with the given class. |
| public <U> U | Returns: An instance of the object that has been created, injected and post constructedThe non-null class to create this object from createMe, String The name of the strategy)ClassAnalyzer that should be used. If
null the default analyzer will be usedThis method creates, injects and post-constructs an object with the given class. |
| public <T> List | Returns: A non-null but possibly empty list of service handles matching the given criteriaMay not be null, and is the contract
or concrete implementation to get the best instance of contractOrImpl, Annotation... The set of qualifiers that must match this service
definition qualifiers)Gets a list of |
| public List | Returns: A non-null but possibly empty list of service handles matching the given criteriaMay not be null, and is the contract
or concrete implementation to get the best instance of contractOrImpl, Annotation... The set of qualifiers that must match this service
definition qualifiers)Gets a list of |
| public List | Returns: A non-null but possibly empty list of service handles matching the given criteriaMay not be null, and is a qualifier that must
match the service definition qualifier, Annotation... The set of qualifiers that must match this service
definition qualifiers)Gets a list of |
| public List | Returns: A non-null but possibly empty list of service handles that match the given filterA filter to use when determining which descriptors should apply searchCriteria)Gets a list of |
| public <T> List | Returns: A list of services implementing this contract or concrete implementation. May not return null, but may return an empty listMay not be null, and is the contract
or concrete implementation to get the best instance of contractOrImpl, Annotation... The set of qualifiers that must match this service
definition qualifiers)Gets all services from this locator that implement this contract or have this implementation and have the provided qualifiers
Use this method only if destroying the service is not important,
otherwise use |
| public <T> List | Returns: A list of services implementing this contract or concrete implementation. May not return null, but may return an empty listMay not be null, and is the contract
or concrete implementation to get the best instance of contractOrImpl, Annotation... The set of qualifiers that must match this service
definition qualifiers)Gets all services from this locator that implement this contract or have this implementation and have the provided qualifiers
Use this method only if destroying the service is not important,
otherwise use |
| public <T> List | Returns: A list of services implementing this contract or concrete implementation. May not return null, but may return an empty listMay not be null, and is a qualifier that must
match the service definition qualifier, Annotation... The set of qualifiers that must match this service
definition qualifiers)Gets all services from this locator that have the provided qualifiers
Use this method only if destroying the services is not important,
otherwise use |
| public List | Returns: A list of services matching this filter. May not return null, but may return an empty listThe returned service will match the Filter
(in other words, searchCriteria.matches returns true). May not
be null searchCriteria)Gets all services from this locator that match the provided
Use this method only if destroying the service is not important,
otherwise use This method should also be used with care to avoid classloading a large number of services |
| public ActiveDescriptor | Returns: The best descriptor matching the filter, or null if there is no descriptor that matches the filterThe non-null filter to use to retrieve the best descriptor filter)Gets the descriptor that best matches this filter, taking ranking and service id into account |
| public String | Returns: The name of the default class analyzer. Will not return nullGets the name of the default class analyzer service |
| public Unqualified | Returns: TheUnqualified annotation that will be (virtually) put
on injection points that have no qualifiers and no other Unqualified
annotation. If null then this ServiceLocator has no default Unqualified
annotation to be appliedThis returns the default |
| public List | Returns: A non-null but possibly empty list of descriptors in ranked order that match the given filterA filter to use when determining which services should apply filter)Gets the list of descriptors that match the given filter |
| public ActiveDescriptor | Returns: The active descriptor for this injection pointthe injection point for whom to find the ActiveDescriptor injectee)This method will first find a descriptor for this injectee, and then reify that descriptor. |
| public long | Returns: The identifier for this service locatorThis returns the unique locator ID for this locator. |
| public String | Returns: The name of this ServiceLocator, will not return nullReturns the name of this ServiceLocator |
| public boolean | Returns: If true hk2 will ensure that the context class loader cannot be changed by user code. If false hk2 will not modify the context class loader of the thread when user code has finishedThis returns the value of neutralContextClassLoader. |
| public ServiceLocator | Returns: The parent service locator for this locator, or null if this service locator does not have a parentGets the parent service locator for this locator |
| public <T> T | Returns: An instance of the contract or impl. May return null if there is no provider that provides the given implementation or contractMay not be null, and is the contract
or concrete implementation to get the best instance of contractOrImpl, Annotation... The set of qualifiers that must match this service
definition qualifiers)Gets the best service from this locator that implements this contract or has this implementation
Use this method only if destroying the service is not important,
otherwise use |
| public <T> T | Returns: An instance of the contract or impl. May return null if there is no provider that provides the given implementation or contractMay not be null, and is the contract
or concrete implementation to get the best instance of contractOrImpl, Annotation... The set of qualifiers that must match this service
definition qualifiers)Gets the best service from this locator that implements this contract or has this implementation
Use this method only if destroying the service is not important,
otherwise use |
| public <T> T | Returns: An instance of the contract or impl. May return null if there is no provider that provides the given implementation or contractMay not be null, and is the contract
or concrete implementation to get the best instance of contractOrImpl, String May be null (to indicate any name is ok), and is the name of the
implementation to be returned name, Annotation... The set of qualifiers that must match this service
definition qualifiers)Gets the best service from this locator that implements this contract or has this implementation and has the given name
Use this method only if destroying the service is not important,
otherwise use |
| public <T> T | Returns: An instance of the contract or impl. May return null if there is no provider that provides the given implementation or contractMay not be null, and is the contract
or concrete implementation to get the best instance of contractOrImpl, String May be null (to indicate any name is ok), and is the name of the
implementation to be returned name, Annotation... The set of qualifiers that must match this service
definition qualifiers)Gets the best service from this locator that implements this contract or has this implementation and has the given name
Use this method only if destroying the service is not important,
otherwise use |
| public <T> T | Returns: The service matching this descriptorThe descriptor whose service to create activeDescriptor, ServiceHandle<?> The ultimate parent of this service creation. May be null root)
This method should be called by code resolving injectee's on behalf of some
root service, usually by an implementation of |
| public <T> T | Returns: The service matching this descriptorThe descriptor whose service to create activeDescriptor, ServiceHandle<?> The ultimate parent of this service creation. May be null root, Injectee The injectee passed into the injectee)InjectionResolver#resolve(Injectee, ServiceHandle) if known,
null otherwiseThis method should be called by code resolving injectee's on behalf of some
root service, usually by an implementation of |
| public <T> ServiceHandle | Returns: Will return the service handle corresponding to the service or null if none were foundMay not be null, and is the contract
or concrete implementation to get the best instance of contractOrImpl, Annotation... The set of qualifiers that must match this service
definition qualifiers)Gets a |
| public <T> ServiceHandle | Returns: Will return the service handle corresponding to the service or null if none were foundMay not be null, and is the contract
or concrete implementation to get the best instance of contractOrImpl, Annotation... The set of qualifiers that must match this service
definition qualifiers)Gets a |
| public <T> ServiceHandle | Returns: Will the service handle for the best service matching the given criteria, or null if no matching service could be foundMay not be null, and is the contract
or concrete implementation to get the best instance of contractOrImpl, String The name to use to further qualify the search (may be null,
indicating that any name will match) name, Annotation... The set of qualifiers that must match this service
definition qualifiers)Gets a |
| public <T> ServiceHandle | Returns: Will the service handle for the best service matching the given criteria, or null if no matching service could be foundMay not be null, and is the contract
or concrete implementation to get the best instance of contractOrImpl, String The name to use to further qualify the search (may be null,
indicating that any name will match) name, Annotation... The set of qualifiers that must match this service
definition qualifiers)Gets a |
| public <T> ServiceHandle | Returns: AServiceHandle that may be used to create or destroy the service
associated with this ActiveDescriptorThe descriptor for which to create a activeDescriptor, Injectee ServiceHandle.
May not be nullThe injectee on behalf of whom this service is being injected. May
be null if the injectee is unknown injectee)Gets a |
| public <T> ServiceHandle | Returns: AServiceHandle that may be used to create or destroy the service
associated with this ActiveDescriptorThe descriptor for which to create a activeDescriptor)ServiceHandle.
May not be nullGets a |
| public ServiceLocatorState | Returns: The current state of the service locatorReturns the current state of this service locator. |
| public void | |
| public void | inject(Object
The object to be analyzed and injected into injectMe, String The name of the strategy)ClassAnalyzer that should be used. If
null the default analyzer will be usedThis will analyze the given object and inject into its fields and methods. |
| public boolean | Returns: If the service locator has been shutdown.Returns whether the state of this service locator is shutdown. |
| public void | postConstruct(Object
The object to postConstruct postConstructMe)This will analyze the given object and call the postConstruct method. |
| public void | postConstruct(Object
The object to postConstruct postConstructMe, String The name of the strategy)ClassAnalyzer that should be used. If
null the default analyzer will be usedThis will analyze the given object and call the postConstruct method. |
| public void | preDestroy(Object
The object to preDestroy preDestroyMe)This will analyze the given object and call the preDestroy method. |
| public void | preDestroy(Object
The object to preDestroy preDestroyMe, String The name of the strategy)ClassAnalyzer that should be used. If
null the default analyzer will be usedThis will analyze the given object and call the preDestroy method. |
| public ActiveDescriptor | Returns: The active descriptor as loaded with the first validHK2LoaderThe descriptor to convert, may not be null descriptor, Injectee The injectee on behalf of whom this descriptor is being injected. May
be null if the injectee is unknown injectee)Converts a descriptor to an ActiveDescriptor. |
| public ActiveDescriptor | Returns: The active descriptor as loaded with the first validHK2LoaderThe descriptor to convert, may not be null descriptor)Converts a descriptor to an ActiveDescriptor. |
| public void | setDefaultClassAnalyzerName(String
The possibly null name of the default class
analyzer (the class analyzer that will be used if a descriptor has not
explicitly set the name of its class analyzer) defaultClassAnalyzer)Sets the name of the default class analyzer that should be used for all
|
| public void | setDefaultUnqualified(Unqualified
The unqualified)Unqualified annotation that will be (virtually) put
on injection points that have no qualifiers and no other Unqualified
annotation. If null then this ServiceLocator has no default Unqualified
annotation to be appliedThis sets the default |
| public void | setNeutralContextClassLoader(boolean
true if hk2 should ensure context class
loader neutrality, false if hk2 should not change the context class loader
on the thread around user code calls neutralContextClassLoader)This sets the value of neutralContextClassLoader. |
| public void |