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 Registrypublic org.slf4j.Logger getServiceLogger(String serviceId)
InternalRegistrylog name suffixed
with a period and the service id.getServiceLogger in interface InternalRegistrypublic void shutdown()
Registryshutdown in interface RegistryRegistryShutdownHub,
RegistryShutdownListenerpublic <T> T getService(String serviceId, Class<T> serviceInterface)
ObjectLocatorgetService in interface ObjectLocatorserviceId - 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()
RegistrycleanupThread in interface RegistryPerthreadManager,
ThreadCleanupListenerpublic <T> Collection<T> getUnorderedConfiguration(ServiceDef3 serviceDef, Class<T> objectType)
InternalRegistrygetUnorderedConfiguration in interface InternalRegistryserviceDef - 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)
InternalRegistrygetOrderedConfiguration in interface InternalRegistryserviceDef - 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)
InternalRegistrygetMappedConfiguration in interface InternalRegistryserviceDef - 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)
ObjectLocatorgetService in interface ObjectLocatorserviceInterface - the interface the service implementsMarkerpublic <T> T getService(Class<T> serviceInterface, Class<? extends Annotation>... markerTypes)
ObjectLocatorgetService in interface ObjectLocatorserviceInterface - the interface the service implementsmarkerTypes - Markers used to select a specific service that implements the interfaceMarkerpublic ServiceLifecycle2 getServiceLifecycle(String scope)
InternalRegistrygetServiceLifecycle in interface InternalRegistryscope - the name of the service scope (case insensitive)public List<ServiceDecorator> findDecoratorsForService(ServiceDef3 serviceDef)
InternalRegistryDecoratorDef
s
are ordered, then converted into ServiceDecorators.findDecoratorsForService in interface InternalRegistrypublic List<ServiceAdvisor> findAdvisorsForService(ServiceDef3 serviceDef)
InternalRegistryfindAdvisorsForService in interface InternalRegistrypublic <T> T getObject(Class<T> objectType, AnnotationProvider annotationProvider, ObjectLocator locator, Module localModule)
InternalRegistryObjectLocator.getObject(Class, org.apache.tapestry5.ioc.AnnotationProvider),
but handles the Local annotation.getObject in interface InternalRegistryobjectType - 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)
ObjectLocatorMasterObjectProvider service.getObject in interface ObjectLocatorobjectType - 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)ObjectProviderpublic void addRegistryShutdownListener(RegistryShutdownListener listener)
RegistryShutdownHubaddRegistryShutdownListener in interface RegistryShutdownHubpublic void addRegistryShutdownListener(Runnable listener)
RegistryShutdownHubaddRegistryShutdownListener in interface RegistryShutdownHubpublic void addRegistryWillShutdownListener(Runnable listener)
RegistryShutdownHubaddRegistryWillShutdownListener in interface RegistryShutdownHubpublic String expandSymbols(String input)
InternalRegistryexpandSymbols in interface InternalRegistrypublic <T> T autobuild(String description, Class<T> clazz)
ObjectLocatorObjectLocator.autobuild(Class) that tracks the operation using
OperationTracker.invoke(String, org.apache.tapestry5.ioc.Invokable).autobuild in interface ObjectLocatordescription - description used with OperationTrackerclazz - the type of object to instantiatepublic <T> T autobuild(Class<T> clazz)
ObjectLocatorInject 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 ObjectLocatorclazz - the type of object to instantiatepublic <T> T proxy(Class<T> interfaceClass, Class<? extends T> implementationClass)
ObjectLocatorObjectLocator.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 ObjectLocatorinterfaceClass - 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)
InternalRegistryproxy in interface InternalRegistrypublic Object provideServiceProxy(String serviceId)
ServiceProxyProviderprovideServiceProxy in interface ServiceProxyProviderserviceId - the id of the service to obtainpublic void run(String description, Runnable operation)
OperationTrackerRuntimeException it will be logged and rethrown
wrapped as a OperationException.run in interface OperationTrackerdescription - used if there is an exceptionoperation - to executepublic <T> T invoke(String description, Invokable<T> operation)
OperationTrackerOperationTracker.run(String, Runnable), but the operation may return a value.invoke in interface OperationTrackerdescription - used if there is an exceptionoperation - to invokepublic <T> T perform(String description, IOOperation<T> operation) throws IOException
OperationTrackerOperationTracker.invoke(String, Invokable), but the operation may throw an IOException.perform in interface OperationTrackerdescription - used if there is an exception (outside of IOException)operation - to performIOExceptionpublic Set<Class> getMarkerAnnotations()
InternalRegistrygetMarkerAnnotations in interface InternalRegistry5.6.4 - Copyright © 2003-2021 The Apache Software Foundation.