com.netflix.eventbus.utils
Class EventBusUtils

java.lang.Object
  extended by com.netflix.eventbus.utils.EventBusUtils

public class EventBusUtils
extends java.lang.Object

General utility methods for EventBus


Constructor Summary
EventBusUtils()
           
 
Method Summary
static boolean applyFilters(java.lang.Object event, java.util.Set<EventFilter> filters, com.netflix.servo.monitor.StatsTimer filterStats, java.lang.String invokerDesc, org.slf4j.Logger logger)
          Utility method to apply filters for an event, this can be used both by publisher & subscriber code.
static java.lang.Class<?> getInterestedEventType(java.lang.Object subscriber, java.lang.reflect.Method subMethod)
          Returns the event class the passed subscriber is interested in.
static int getQueueSize(SubscriberConfigProvider.SubscriberConfig subscribe)
          Returns an appropriate consumer queue size for the passed subscribe annotation.
static SubscriberConfigProvider.SubscriberConfig getSubscriberConfig(java.lang.reflect.Method subMethod, java.lang.Object subscriber)
          Returns configuration for the passed subscriber method.
static SubscriberConfigProvider.SubscriberConfig getSubscriberConfig(SubscriberInfo subscriberInfo)
          Same as calling getSubscriberConfig(java.lang.reflect.Method, Object) with SubscriberInfo.getSubscriberMethod() and SubscriberInfo.getSubscriberInstance()
static boolean isAnEventBatch(java.lang.Object event)
          Deduce whether the passed event is an event batch.
static com.netflix.servo.monitor.StatsTimer newStatsTimer(java.lang.String monitorName, long collectionDurationInMillis)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EventBusUtils

public EventBusUtils()
Method Detail

getQueueSize

public static int getQueueSize(SubscriberConfigProvider.SubscriberConfig subscribe)
Returns an appropriate consumer queue size for the passed subscribe annotation. This method defaults the size to the one specified in the fast property EventBus.CONSUMER_QUEUE_SIZE_DEFAULT_PROP_NAME

Parameters:
subscribe - The annotation for which the queue size is to be retrieved.
Returns:
The queue size.

getSubscriberConfig

public static SubscriberConfigProvider.SubscriberConfig getSubscriberConfig(java.lang.reflect.Method subMethod,
                                                                            java.lang.Object subscriber)
Returns configuration for the passed subscriber method. This configuration can be obtained from the Subscribe annotation on the method or from SubscriberConfigProvider if the subscriber implements that interface.

Parameters:
subscriber - The instance of the subscriber that contains the subscriber method.
subMethod - Method for which the configuration has to be found.
Returns:
Subscriber configuration.

getSubscriberConfig

public static SubscriberConfigProvider.SubscriberConfig getSubscriberConfig(SubscriberInfo subscriberInfo)
Same as calling getSubscriberConfig(java.lang.reflect.Method, Object) with SubscriberInfo.getSubscriberMethod() and SubscriberInfo.getSubscriberInstance()

Parameters:
subscriberInfo - The instance of the subscriber that contains the subscriber method.
Returns:
Subscriber configuration.

isAnEventBatch

public static boolean isAnEventBatch(java.lang.Object event)
Deduce whether the passed event is an event batch.

Parameters:
event - The event to inspect.
Returns:
true if the event is a batch.

getInterestedEventType

public static java.lang.Class<?> getInterestedEventType(java.lang.Object subscriber,
                                                        java.lang.reflect.Method subMethod)
Returns the event class the passed subscriber is interested in. This will generally be the argument of the subscriber method, except when the subscriber is a DynamicSubscriber, in which case the event type will be as returned by DynamicSubscriber.getEventType(). It is important that the subscriber method is valid as evaluated by SubscriberValidator

Parameters:
subscriber - The subscriber instance in question.
subMethod - The subscriber method is question.
Returns:
The event class this subscriber is interested in.

applyFilters

public static boolean applyFilters(java.lang.Object event,
                                   java.util.Set<EventFilter> filters,
                                   com.netflix.servo.monitor.StatsTimer filterStats,
                                   java.lang.String invokerDesc,
                                   org.slf4j.Logger logger)
Utility method to apply filters for an event, this can be used both by publisher & subscriber code.

Parameters:
event - The event to apply filter on.
filters - Filters to apply.
filterStats - Stats timer for applying the filter.
invokerDesc - A string description for the invoker, this is required just for logging.
logger - Logger instance to use for logging.
Returns:
true if the event should be processed, false if the event should not be processed any further i.e. it is filtered out. This will log a debug message when the event is filtered.

newStatsTimer

public static com.netflix.servo.monitor.StatsTimer newStatsTimer(java.lang.String monitorName,
                                                                 long collectionDurationInMillis)