org.axonframework.eventhandling
Class ClassNamePrefixClusterSelector

java.lang.Object
  extended by org.axonframework.eventhandling.AbstractClusterSelector
      extended by org.axonframework.eventhandling.ClassNamePrefixClusterSelector
All Implemented Interfaces:
ClusterSelector

public class ClassNamePrefixClusterSelector
extends AbstractClusterSelector

ClusterSelector implementation that chooses a Cluster based on a mapping of the Listener's Class Name. It maps a prefix to a Cluster. When two prefixes match the same class, the Cluster mapped to the longest prefix is chosen.

For example, consider the following mappings:

 org.axonframework -> cluster1
 com.              -> cluster2
 com.somecompany   -> cluster3
 
A class named com.somecompany.SomeListener will map to cluster3 as it is mapped to a more specific prefix. This implementation uses String.startsWith(String) to evaluate a match.

Note that the name of the class used is the name of the class implementing the EventListener interface. If a listener implements the EventListenerProxy interface, the value of the EventListenerProxy.getTargetType() is used. Annotated Event Listeners will always have the actual annotated class name used.

Since:
2.0
Author:
Allard Buijze

Constructor Summary
ClassNamePrefixClusterSelector(Map<String,Cluster> mappings)
          Initializes the ClassNamePrefixClusterSelector using the given mappings.
ClassNamePrefixClusterSelector(Map<String,Cluster> mappings, Cluster defaultCluster)
          Initializes the ClassNamePrefixClusterSelector using the given mappings.
ClassNamePrefixClusterSelector(String prefix, Cluster cluster)
          Initializes the ClassNamePrefixClusterSelector where classes starting with the given prefix will be mapped to the given cluster.
 
Method Summary
 Cluster doSelectCluster(EventListener eventListener, Class<?> listenerType)
          Select a cluster for the given eventListener, which has the actual class listenerType.
 
Methods inherited from class org.axonframework.eventhandling.AbstractClusterSelector
selectCluster
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ClassNamePrefixClusterSelector

public ClassNamePrefixClusterSelector(String prefix,
                                      Cluster cluster)
Initializes the ClassNamePrefixClusterSelector where classes starting with the given prefix will be mapped to the given cluster.

This method is identical to ClassNamePrefixClusterSelector(java.util.Map) with only a single mapping.

Parameters:
prefix - The prefix of the fully qualified classname to match against
cluster - The cluster to choose if a match is found

ClassNamePrefixClusterSelector

public ClassNamePrefixClusterSelector(Map<String,Cluster> mappings)
Initializes the ClassNamePrefixClusterSelector using the given mappings. If a name does not have a prefix defined, the Cluster Selector returns null.

Parameters:
mappings - the mappings defining a cluster for each Class Name prefix

ClassNamePrefixClusterSelector

public ClassNamePrefixClusterSelector(Map<String,Cluster> mappings,
                                      Cluster defaultCluster)
Initializes the ClassNamePrefixClusterSelector using the given mappings. If a name does not have a prefix defined, the Cluster Selector returns the given defaultCluster.

Parameters:
mappings - the mappings defining a cluster for each Class Name prefix
defaultCluster - The cluster to use when no mapping is present
Method Detail

doSelectCluster

public Cluster doSelectCluster(EventListener eventListener,
                               Class<?> listenerType)
Description copied from class: AbstractClusterSelector
Select a cluster for the given eventListener, which has the actual class listenerType. Note that the given listenerType does not have to be assignable to EventListener, as it is possible that the eventListener acts as a proxy to an instance of listenerType.

Specified by:
doSelectCluster in class AbstractClusterSelector
Parameters:
eventListener - The listener instance handling the events, possibly a proxy
listenerType - The actual type of the Event Listener
Returns:
the cluster to assign the Event Listener to


Copyright © 2010-2016. All Rights Reserved.