com.netflix.eventbus.spi
Class SyncSubscribersGatekeeper

java.lang.Object
  extended by com.netflix.eventbus.spi.SyncSubscribersGatekeeper

public class SyncSubscribersGatekeeper
extends java.lang.Object

A gatekeeper to allow synchronous subscribers in EventBusImpl. This determines whether a particular subscriber annotated with Subscribe.syncIfAllowed() as true is actually allowed to be synchronous.
A subscriber is allowed, iff,

Whitelisting:

One can cherry-pick subscribers which are allowed to be synchronous. This can be done by setting a property SYNC_SUBSCRIBERS_WHITELIST_JSON with a json of the following format:
    {
        "[Fully qualified class name of the subscriber class]": 0 or more fully qualified class name of the events,
    }
 
Example:
 {
     "com.foo.bar.MyAllSubscriber": [], // Signifies all subscriber methods in this class will be sync, if configured so by setting Subscribe.syncIfAllowed() as true.
     "com.foo.bar.MySubscriber": ["com.foo.bar.EventOne", "com.foo.bar.EventTwo"], // Signifies only subscrber of events EventOne & EventTwo in this class will be sync, if configured so by setting Subscribe.syncIfAllowed() as true.
     "com.foo.bar.MyAnotherSubscriber": ["com.foo.bar.Event3", "com.foo.bar.Event4"]
 }

 


Field Summary
static java.lang.String ALLOW_ALL_EVENTS
           
static java.lang.String ALLOW_SYNC_SUBSCRIBERS
           
static com.google.common.collect.SetMultimap<java.lang.String,java.lang.String> EMPTY_WHITELIST
           
static java.lang.String SYNC_SUBSCRIBERS_WHITELIST_JSON
          Property to define a whitelist of subscribers which are allowed to be synchronous.
 
Constructor Summary
SyncSubscribersGatekeeper()
           
 
Method Summary
static boolean isSyncSubscriber(SubscriberConfigProvider.SubscriberConfig subscribe, java.lang.Class eventClass, java.lang.Class subscriberClass)
          Deduce whether the subscriber favors synchronous event consumption.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ALLOW_SYNC_SUBSCRIBERS

public static final java.lang.String ALLOW_SYNC_SUBSCRIBERS
See Also:
Constant Field Values

SYNC_SUBSCRIBERS_WHITELIST_JSON

public static final java.lang.String SYNC_SUBSCRIBERS_WHITELIST_JSON
Property to define a whitelist of subscribers which are allowed to be synchronous.
See SyncSubscribersGatekeeper javadocs for details of the format of this property.

See Also:
Constant Field Values

EMPTY_WHITELIST

public static final com.google.common.collect.SetMultimap<java.lang.String,java.lang.String> EMPTY_WHITELIST

ALLOW_ALL_EVENTS

public static final java.lang.String ALLOW_ALL_EVENTS
See Also:
Constant Field Values
Constructor Detail

SyncSubscribersGatekeeper

public SyncSubscribersGatekeeper()
Method Detail

isSyncSubscriber

public static boolean isSyncSubscriber(SubscriberConfigProvider.SubscriberConfig subscribe,
                                       java.lang.Class eventClass,
                                       java.lang.Class subscriberClass)
Deduce whether the subscriber favors synchronous event consumption. See SyncSubscribersGatekeeper javadoc for details of when will this be allowed.

Parameters:
subscribe - The configuration for the subscriber in question.
eventClass - Class of the event for which this check is to be done.
subscriberClass - Class of the subscriber for which this check is to be done.
Returns:
true if the subscriber should be provided events synchronously.