@Singleton public class ProvidesListener extends Object implements DynamicConfigurationListener
Provides annotation.
Only one ProvidesListener instance may be registered with each
ServiceLocator.
| Constructor and Description |
|---|
ProvidesListener(ServiceLocator locator) |
| Modifier and Type | Method and Description |
|---|---|
void |
configurationChanged() |
protected Filter |
getFilter()
Matches services whose implementation classes are scanned for
Provides annotations. |
protected void |
onInvalidProvidesAnnotation(ActiveDescriptor<?> providerDescriptor,
Provides providesAnnotation,
AnnotatedElement annotatedElement,
String message)
Called when an invalid
Provides annotation is found. |
@Inject public ProvidesListener(ServiceLocator locator)
protected Filter getFilter()
Provides annotations.
The default filter matches all services. Override this method to permit a smaller subset of services. For example:
@Singleton
public class FilteredProvidesListener extends ProvidesListener {
@Inject
public FilteredProvidesListener(ServiceLocator locator) {
super(locator);
}
@Override
protected Filter getFilter() {
return d -> d.getImplementation().startsWith("com.example.");
}
}
protected void onInvalidProvidesAnnotation(ActiveDescriptor<?> providerDescriptor, Provides providesAnnotation, AnnotatedElement annotatedElement, String message)
Provides annotation is found.
The default implementation of this method does nothing. Override this method to consume the reported information. For example:
@Singleton
public class LoggingProvidesListener extends ProvidesListener {
private final Logger logger = LoggerFactory.getLogger(getClass());
@Inject
public LoggingProvidesListener(ServiceLocator locator) {
super(locator);
}
@Override
protected void onInvalidProvidesAnnotation(
ActiveDescriptor<?> providerDescriptor,
Provides providesAnnotation,
AnnotatedElement annotatedElement,
String message) {
logger.error(message);
}
}
If this method does not throw an exception, then after calling this
method, this listener will ignore this Provides annotation —
registering no new ActiveDescriptor on its behalf — and this
listener will continue to scan this provider and other providers for other
Provides annotations.
If this method does throw an exception, then the behavior of this listener from this point forward is undefined.
providerDescriptor - the descriptor of the service that contains this
Provides annotationprovidesAnnotation - the Provides annotation on the method or
fieldannotatedElement - the method or field that is annotated with Providesmessage - a message explaining why this Provides annotation
is invalidpublic void configurationChanged()
configurationChanged in interface DynamicConfigurationListenerCopyright © 2009–2020 Oracle Corporation. All rights reserved.