Class DefaultTopicDistributionService
- java.lang.Object
-
- org.glassfish.hk2.extras.events.internal.DefaultTopicDistributionService
-
- All Implemented Interfaces:
DynamicConfigurationListener
,InstanceLifecycleListener
,TopicDistributionService
@Singleton @Named("HK2TopicDistributionService") @ContractsProvided({TopicDistributionService.class,InstanceLifecycleListener.class,DynamicConfigurationListener.class}) public class DefaultTopicDistributionService extends java.lang.Object implements TopicDistributionService, InstanceLifecycleListener, DynamicConfigurationListener
This is the default implementation of the TopicDistributionService.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
DefaultTopicDistributionService.ActivatorClassKey
This is here to handle the case where a PerLookup Factory (or the like) could possibly return different classes every time it is looked up.private static class
DefaultTopicDistributionService.FireResults
private static class
DefaultTopicDistributionService.SubscriberInfo
-
Field Summary
Fields Modifier and Type Field Description private java.util.HashMap<DefaultTopicDistributionService.ActivatorClassKey,java.util.List<DefaultTopicDistributionService.SubscriberInfo>>
class2Subscribers
private java.util.HashMap<ActiveDescriptor<?>,java.util.Set<java.lang.Class<?>>>
descriptor2Classes
private IterableProvider<DefaultTopicDistributionErrorService>
errorHandlers
private ServiceLocator
locator
private java.util.concurrent.locks.ReentrantReadWriteLock
readWriteLock
private ClassReflectionHelper
reflectionHelper
private java.util.concurrent.locks.ReentrantReadWriteLock.ReadLock
rLock
private ActiveDescriptor<TopicDistributionService>
selfDescriptor
private static Filter
SUBSCRIBER_FILTER
private java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock
wLock
-
Fields inherited from interface org.glassfish.hk2.api.messaging.TopicDistributionService
HK2_DEFAULT_TOPIC_DISTRIBUTOR
-
-
Constructor Summary
Constructors Constructor Description DefaultTopicDistributionService()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
configurationChanged()
This method is called when the set of descriptors in this service locator has been changed.void
distributeMessage(Topic<?> topic, java.lang.Object message)
Must distribute the message to all of the matching topic subscribers.private java.lang.reflect.Method
findMethodOnDifferentClass(java.lang.Class<?> findOnMe, java.lang.reflect.Method method)
private void
fire(java.lang.Object message, java.lang.reflect.Method subscription, DefaultTopicDistributionService.SubscriberInfo subscriptionInfo, java.lang.Object target, ServiceLocator locator)
private static DefaultTopicDistributionService.SubscriberInfo
generateSubscriberInfo(ActiveDescriptor<?> injecteeDescriptor, java.lang.reflect.Method subscriber, java.lang.reflect.Method useSubscriber, int subscribeToPosition, java.lang.annotation.Annotation[][] paramAnnotations)
Filter
getFilter()
This returns a filter that tells the system whether a particular descriptor should be handled by this lifecycle listener.private java.util.List<DefaultTopicDistributionService.FireResults>
handleDescriptorToClass(ActiveDescriptor<?> descriptor, java.lang.Class<?> clazz, java.lang.reflect.Type eventType, Topic<?> topic)
void
lifecycleEvent(InstanceLifecycleEvent lifecycleEvent)
This method will be called when any lifecycle event occurs.private void
postProduction(InstanceLifecycleEvent lifecycleEvent)
private void
preDestruction(InstanceLifecycleEvent lifecycleEvent)
-
-
-
Field Detail
-
SUBSCRIBER_FILTER
private static final Filter SUBSCRIBER_FILTER
-
locator
@Inject private ServiceLocator locator
-
errorHandlers
@Inject private IterableProvider<DefaultTopicDistributionErrorService> errorHandlers
-
selfDescriptor
@Inject @Self private ActiveDescriptor<TopicDistributionService> selfDescriptor
-
reflectionHelper
private final ClassReflectionHelper reflectionHelper
-
descriptor2Classes
private final java.util.HashMap<ActiveDescriptor<?>,java.util.Set<java.lang.Class<?>>> descriptor2Classes
-
class2Subscribers
private final java.util.HashMap<DefaultTopicDistributionService.ActivatorClassKey,java.util.List<DefaultTopicDistributionService.SubscriberInfo>> class2Subscribers
-
readWriteLock
private final java.util.concurrent.locks.ReentrantReadWriteLock readWriteLock
-
wLock
private final java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock wLock
-
rLock
private final java.util.concurrent.locks.ReentrantReadWriteLock.ReadLock rLock
-
-
Method Detail
-
fire
private void fire(java.lang.Object message, java.lang.reflect.Method subscription, DefaultTopicDistributionService.SubscriberInfo subscriptionInfo, java.lang.Object target, ServiceLocator locator) throws java.lang.Throwable
- Throws:
java.lang.Throwable
-
handleDescriptorToClass
private java.util.List<DefaultTopicDistributionService.FireResults> handleDescriptorToClass(ActiveDescriptor<?> descriptor, java.lang.Class<?> clazz, java.lang.reflect.Type eventType, Topic<?> topic)
-
distributeMessage
public void distributeMessage(Topic<?> topic, java.lang.Object message)
Description copied from interface:TopicDistributionService
Must distribute the message to all of the matching topic subscribers. Any exception thrown from this method will be ignored. Instead error handling should be performed by the implementation of this message- Specified by:
distributeMessage
in interfaceTopicDistributionService
- Parameters:
topic
- The topic to which to distribute the message. Must not be nullmessage
- The message to send to the topic. Must not be null
-
getFilter
public Filter getFilter()
Description copied from interface:InstanceLifecycleListener
This returns a filter that tells the system whether a particular descriptor should be handled by this lifecycle listener. The filter can be called at any time- Specified by:
getFilter
in interfaceInstanceLifecycleListener
- Returns:
- The filter that tells the system if this listener applies to this descriptor. If this returns null then this Listener will apply to ALL descriptors.
-
postProduction
private void postProduction(InstanceLifecycleEvent lifecycleEvent)
-
findMethodOnDifferentClass
private java.lang.reflect.Method findMethodOnDifferentClass(java.lang.Class<?> findOnMe, java.lang.reflect.Method method)
-
generateSubscriberInfo
private static DefaultTopicDistributionService.SubscriberInfo generateSubscriberInfo(ActiveDescriptor<?> injecteeDescriptor, java.lang.reflect.Method subscriber, java.lang.reflect.Method useSubscriber, int subscribeToPosition, java.lang.annotation.Annotation[][] paramAnnotations)
-
preDestruction
private void preDestruction(InstanceLifecycleEvent lifecycleEvent)
-
lifecycleEvent
public void lifecycleEvent(InstanceLifecycleEvent lifecycleEvent)
Description copied from interface:InstanceLifecycleListener
This method will be called when any lifecycle event occurs. The currently supported lifecycle events are PRE_PRODUCTION, POST_PRODUCTION and PRE_DESTRUCTION. Code should be written to allow for future events to be generated. This method should not throw exceptions- Specified by:
lifecycleEvent
in interfaceInstanceLifecycleListener
- Parameters:
lifecycleEvent
- The event that has occurred, will not be null
-
configurationChanged
public void configurationChanged()
Description copied from interface:DynamicConfigurationListener
This method is called when the set of descriptors in this service locator has been changed. Changes to parent service locators descriptors will not be reported. These services are called back on the thread doing theDynamicConfiguration.commit()
so care should be taken to do any work quickly. Any exception thrown from this method will be ignored. A commit that failed will not be reported to this method- Specified by:
configurationChanged
in interfaceDynamicConfigurationListener
-
-