public class RegistryImpl extends Object implements Registry, InternalRegistry, ServiceProxyProvider
Constructor and Description |
---|
RegistryImpl(Collection<ModuleDef2> moduleDefs,
PlasticProxyFactory proxyFactory,
LoggerSource loggerSource,
OperationTracker operationTracker)
Constructs the registry from a set of module definitions and other resources.
|
Modifier and Type | Method and Description |
---|---|
void |
addRegistryShutdownListener(RegistryShutdownListener listener)
Adds a listener for eventual notification.
|
void |
addRegistryShutdownListener(Runnable listener)
Adds a listener for eventual notification when the registry shuts down.
|
void |
addRegistryWillShutdownListener(Runnable listener)
Adds a listener for eventual notification.
|
<T> T |
autobuild(Class<T> clazz)
Autobuilds a class by finding the public constructor with the most parameters.
|
<T> T |
autobuild(String description,
Class<T> clazz)
Preferred version of
ObjectLocator.autobuild(Class) that tracks the operation using
OperationTracker.invoke(String, org.apache.tapestry5.ioc.Invokable) . |
void |
cleanupThread()
Invoked at the end of a request to discard any thread-specific information accumulated during the current
request.
|
String |
expandSymbols(String input)
Given an input string that may contain symbols, returns the string with any and all symbols fully
expanded.
|
List<ServiceAdvisor> |
findAdvisorsForService(ServiceDef3 serviceDef)
Searches for advisors for a particular service, returning them in order of application.
|
List<ServiceDecorator> |
findDecoratorsForService(ServiceDef3 serviceDef)
Searches for decorators for a particular service.
|
<K,V> Map<K,V> |
getMappedConfiguration(ServiceDef3 serviceDef,
Class<K> keyType,
Class<V> objectType)
Builds up a map of key/value pairs by invoking service contribution methods that target the service (from any
module, unless the service is private).
|
Set<Class> |
getMarkerAnnotations()
Returns a Set of Annotation classes that are used as service markers.
|
<T> T |
getObject(Class<T> objectType,
AnnotationProvider annotationProvider)
Obtains an object indirectly, using the
MasterObjectProvider service. |
<T> T |
getObject(Class<T> objectType,
AnnotationProvider annotationProvider,
ObjectLocator locator,
Module localModule)
As with
ObjectLocator.getObject(Class, org.apache.tapestry5.ioc.AnnotationProvider) ,
but handles the Local annotation. |
<T> List<T> |
getOrderedConfiguration(ServiceDef3 serviceDef,
Class<T> objectType)
Builds up an ordered collection by invoking service contributor methods that target the service (from any module,
unless the service is private).
|
<T> T |
getService(Class<T> serviceInterface)
Locates a service given a service interface and (optionally) some marker annotation types.
|
<T> T |
getService(Class<T> serviceInterface,
Class<? extends Annotation>... markerTypes)
Locates a service given a service interface and (optionally) some marker annotation types.
|
<T> T |
getService(String serviceId,
Class<T> serviceInterface)
Obtains a service via its unique service id.
|
ServiceLifecycle2 |
getServiceLifecycle(String scope)
Returns a service lifecycle by service scope name.
|
org.slf4j.Logger |
getServiceLogger(String serviceId)
Returns a logger for the service, which consists of the Module's
log name suffixed
with a period and the service id. |
<T> Collection<T> |
getUnorderedConfiguration(ServiceDef3 serviceDef,
Class<T> objectType)
Builds up an unordered collection by invoking service contributor methods that target the service (from any
module, unless the service is private).
|
<T> T |
invoke(String description,
Invokable<T> operation)
As with
OperationTracker.run(String, Runnable) , but the operation may return a value. |
<T> T |
perform(String description,
IOOperation<T> operation)
As with
OperationTracker.invoke(String, Invokable) , but the operation may throw an IOException . |
void |
performRegistryStartup()
It's not unreasonable for an eagerly-loaded service to decide to start a thread, at which
point we raise issues
about improper publishing of the Registry instance from the RegistryImpl constructor.
|
Object |
provideServiceProxy(String serviceId)
Look up the service and return its proxy.
|
<T> T |
proxy(Class<T> interfaceClass,
Class<? extends T> implementationClass)
Creates a proxy.
|
<T> T |
proxy(Class<T> interfaceClass,
Class<? extends T> implementationClass,
ObjectLocator locator)
Creates a just-in-time (and possibly, live reloading) proxy for the indicated class and interface, using the
provided locator to autobuild the implementationClass (when necessary).
|
void |
run(String description,
Runnable operation)
Executes the operation.
|
void |
shutdown()
Shuts down a Registry instance.
|
public RegistryImpl(Collection<ModuleDef2> moduleDefs, PlasticProxyFactory proxyFactory, LoggerSource loggerSource, OperationTracker operationTracker)
moduleDefs
- defines the modules (and builders, decorators, etc., within)proxyFactory
- used to create new proxy objectsloggerSource
- used to obtain Logger instancesoperationTracker
- public void performRegistryStartup()
performRegistryStartup
in interface Registry
public org.slf4j.Logger getServiceLogger(String serviceId)
InternalRegistry
log name
suffixed
with a period and the service id.getServiceLogger
in interface InternalRegistry
public void shutdown()
Registry
shutdown
in interface Registry
RegistryShutdownHub
,
RegistryShutdownListener
public <T> T getService(String serviceId, Class<T> serviceInterface)
ObjectLocator
getService
in interface ObjectLocator
serviceId
- unique Service id used to locate the service object (may contain symbols,
which
will be expanded), case is ignoredserviceInterface
- the interface implemented by the service (or an interface extended by the service
interface)public void cleanupThread()
Registry
cleanupThread
in interface Registry
PerthreadManager
,
ThreadCleanupListener
public <T> Collection<T> getUnorderedConfiguration(ServiceDef3 serviceDef, Class<T> objectType)
InternalRegistry
getUnorderedConfiguration
in interface InternalRegistry
serviceDef
- defines the service for which configuration data is being assembledobjectType
- identifies the type of object allowed into the collectionpublic <T> List<T> getOrderedConfiguration(ServiceDef3 serviceDef, Class<T> objectType)
InternalRegistry
getOrderedConfiguration
in interface InternalRegistry
serviceDef
- defines the service for which configuration data is being assembledobjectType
- identifies the type of object allowed into the collectionpublic <K,V> Map<K,V> getMappedConfiguration(ServiceDef3 serviceDef, Class<K> keyType, Class<V> objectType)
InternalRegistry
getMappedConfiguration
in interface InternalRegistry
serviceDef
- defines the service for which configuration data is being assembledkeyType
- identifies the type of key object allowed into the mapobjectType
- identifies the type of value object allowed into the mappublic <T> T getService(Class<T> serviceInterface)
ObjectLocator
getService
in interface ObjectLocator
serviceInterface
- the interface the service implementsMarker
public <T> T getService(Class<T> serviceInterface, Class<? extends Annotation>... markerTypes)
ObjectLocator
getService
in interface ObjectLocator
serviceInterface
- the interface the service implementsmarkerTypes
- Markers used to select a specific service that implements the interfaceMarker
public ServiceLifecycle2 getServiceLifecycle(String scope)
InternalRegistry
getServiceLifecycle
in interface InternalRegistry
scope
- the name of the service scope (case insensitive)public List<ServiceDecorator> findDecoratorsForService(ServiceDef3 serviceDef)
InternalRegistry
DecoratorDef
s
are ordered, then converted into ServiceDecorator
s.findDecoratorsForService
in interface InternalRegistry
public List<ServiceAdvisor> findAdvisorsForService(ServiceDef3 serviceDef)
InternalRegistry
findAdvisorsForService
in interface InternalRegistry
public <T> T getObject(Class<T> objectType, AnnotationProvider annotationProvider, ObjectLocator locator, Module localModule)
InternalRegistry
ObjectLocator.getObject(Class, org.apache.tapestry5.ioc.AnnotationProvider)
,
but handles the Local
annotation.getObject
in interface InternalRegistry
objectType
- type of object o be injectedannotationProvider
- access to annotations at point of injectionlocator
- used to resolve any subsequent injectionslocalModule
- module to limit services to, if Local annotaton presentpublic <T> T getObject(Class<T> objectType, AnnotationProvider annotationProvider)
ObjectLocator
MasterObjectProvider
service.getObject
in interface ObjectLocator
objectType
- the type of object to be returnedannotationProvider
- provides access to annotations on the field or parameter for which a value is to
be
obtained, which may be utilized in selecting an appropriate object, use
null when annotations are not available (in which case, selection
will
be based only on the object type)ObjectProvider
public void addRegistryShutdownListener(RegistryShutdownListener listener)
RegistryShutdownHub
addRegistryShutdownListener
in interface RegistryShutdownHub
public void addRegistryShutdownListener(Runnable listener)
RegistryShutdownHub
addRegistryShutdownListener
in interface RegistryShutdownHub
public void addRegistryWillShutdownListener(Runnable listener)
RegistryShutdownHub
addRegistryWillShutdownListener
in interface RegistryShutdownHub
public String expandSymbols(String input)
InternalRegistry
expandSymbols
in interface InternalRegistry
public <T> T autobuild(String description, Class<T> clazz)
ObjectLocator
ObjectLocator.autobuild(Class)
that tracks the operation using
OperationTracker.invoke(String, org.apache.tapestry5.ioc.Invokable)
.autobuild
in interface ObjectLocator
description
- description used with OperationTracker
clazz
- the type of object to instantiatepublic <T> T autobuild(Class<T> clazz)
ObjectLocator
Inject
annotation. There are two cases: constructing a service implementation, and constructing
an arbitrary object. In the former case, many service resources are also available for injection, not
just dependencies or objects provided via the MasterObjectProvider service.autobuild
in interface ObjectLocator
clazz
- the type of object to instantiatepublic <T> T proxy(Class<T> interfaceClass, Class<? extends T> implementationClass)
ObjectLocator
ObjectLocator.autobuild(Class)
until
just-in-time (that is, first method invocation). In a limited number of cases, it is necessary to use such a
proxy to prevent service construction cycles, particularly when contributing (directly or indirectly) to the
MasterObjectProvider
(which is itself at the heart
of autobuilding).
If the class file for the class is a file on the file system (not a file packaged in a JAR), then the proxy will
autoreload: changing the class file will result in the new class being reloaded and re-instantiated
(with dependencies).proxy
in interface ObjectLocator
interfaceClass
- the interface implemented by the proxyimplementationClass
- a concrete class that implements the interfaceObjectLocator.autobuild(Class)
public <T> T proxy(Class<T> interfaceClass, Class<? extends T> implementationClass, ObjectLocator locator)
InternalRegistry
proxy
in interface InternalRegistry
public Object provideServiceProxy(String serviceId)
ServiceProxyProvider
provideServiceProxy
in interface ServiceProxyProvider
serviceId
- the id of the service to obtainpublic void run(String description, Runnable operation)
OperationTracker
RuntimeException
it will be logged and rethrown
wrapped as a OperationException
.run
in interface OperationTracker
description
- used if there is an exceptionoperation
- to executepublic <T> T invoke(String description, Invokable<T> operation)
OperationTracker
OperationTracker.run(String, Runnable)
, but the operation may return a value.invoke
in interface OperationTracker
description
- used if there is an exceptionoperation
- to invokepublic <T> T perform(String description, IOOperation<T> operation) throws IOException
OperationTracker
OperationTracker.invoke(String, Invokable)
, but the operation may throw an IOException
.perform
in interface OperationTracker
description
- used if there is an exception (outside of IOException)operation
- to performIOException
public Set<Class> getMarkerAnnotations()
InternalRegistry
getMarkerAnnotations
in interface InternalRegistry
5.6.3 - Copyright © 2003-2021 The Apache Software Foundation.