Java Code Examples for javax.cache.configuration.CacheEntryListenerConfiguration#getCacheEntryEventFilterFactory()

The following examples show how to use javax.cache.configuration.CacheEntryListenerConfiguration#getCacheEntryEventFilterFactory() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EventDispatcher.java    From caffeine with Apache License 2.0 6 votes vote down vote up
/**
 * Registers a cache entry listener based on the supplied configuration.
 *
 * @param configuration the listener's configuration.
 */
@SuppressWarnings("PMD.CloseResource")
public void register(CacheEntryListenerConfiguration<K, V> configuration) {
  if (configuration.getCacheEntryListenerFactory() == null) {
    return;
  }
  EventTypeAwareListener<K, V> listener = new EventTypeAwareListener<>(
      configuration.getCacheEntryListenerFactory().create());

  CacheEntryEventFilter<K, V> filter = event -> true;
  if (configuration.getCacheEntryEventFilterFactory() != null) {
    filter = new EventTypeFilter<>(listener,
        configuration.getCacheEntryEventFilterFactory().create());
  }

  Registration<K, V> registration = new Registration<>(configuration, filter, listener);
  dispatchQueues.putIfAbsent(registration, CompletableFuture.completedFuture(null));
}
 
Example 2
Source File: JCSListener.java    From commons-jcs with Apache License 2.0 6 votes vote down vote up
public JCSListener(final CacheEntryListenerConfiguration<K, V> cacheEntryListenerConfiguration)
{
    oldValue = cacheEntryListenerConfiguration.isOldValueRequired();
    synchronous = cacheEntryListenerConfiguration.isSynchronous();

    final Factory<CacheEntryEventFilter<? super K, ? super V>> filterFactory = cacheEntryListenerConfiguration
            .getCacheEntryEventFilterFactory();
    if (filterFactory == null)
    {
        filter = NoFilter.INSTANCE;
    }
    else
    {
        filter = filterFactory.create();
    }

    delegate = cacheEntryListenerConfiguration.getCacheEntryListenerFactory().create();
    remove = CacheEntryRemovedListener.class.isInstance(delegate);
    expire = CacheEntryExpiredListener.class.isInstance(delegate);
    update = CacheEntryUpdatedListener.class.isInstance(delegate);
    create = CacheEntryCreatedListener.class.isInstance(delegate);
}
 
Example 3
Source File: BlazingCacheCache.java    From blazingcache with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private void configureListener(CacheEntryListenerConfiguration<K, V> listenerConfig) {
    BlazingCacheCacheEntryListenerWrapper wrapper = new BlazingCacheCacheEntryListenerWrapper(
            listenerConfig.isSynchronous(),
            listenerConfig.isOldValueRequired(),
            listenerConfig.getCacheEntryListenerFactory().create(),
            listenerConfig.getCacheEntryEventFilterFactory() != null ? listenerConfig.getCacheEntryEventFilterFactory().create() : null,
            listenerConfig,
            this
    );
    listeners.add(wrapper);
    needPreviuosValueForListeners = needPreviuosValueForListeners | wrapper.needPreviousValue || policy != null;
}
 
Example 4
Source File: ListenerEntry.java    From triava with Apache License 2.0 4 votes vote down vote up
/**
 * Creates a ListenerEntry from the factories in CacheEntryListenerConfiguration.
 * Both CacheEntryEventFilter and CacheEntryListener are created.
 * The {@link #dispatchMode} regulates how events get dispatched, for example synchronous, asynchronous batched or timed
 * 
 * @param config The CacheEntryListenerConfiguration
 * @param tcache The cache which events should be listened to 
 * @param dispatchMode How events are dispatched to listeners
 */
ListenerEntry(CacheEntryListenerConfiguration<K, V> config, Cache<K,V> tcache, DispatchMode dispatchMode)
{
	this.config = config;
	this.tcache = tcache;
	this.dispatchMode = dispatchMode;

	CacheEventManager<K,V> em = null;
	Factory<CacheEntryListener<? super K, ? super V>> listenerFactory = config.getCacheEntryListenerFactory();
	if (listenerFactory != null)
	{
		listener = listenerFactory.create();
		if (listener != null)
		{
			Factory<CacheEntryEventFilter<? super K, ? super V>> filterFactory = config
					.getCacheEntryEventFilterFactory();
			if (filterFactory != null)
				filter = filterFactory.create();
			
			em = new ListenerCacheEventManager<K,V>();
		}
	}

	eventManager = em;


       /**
        * Initialize dispatchQueue and corresponding Thread. This has to be done even for the synchronous
        * DispatchMode#SYNC, as it can be forced to operate asynchronously for internal operations like
        * expiration and eviction.
        */
       this.dispatchQueue = new ArrayBlockingQueue<TCacheEntryEventCollection<K, V>>(1024);
       /**
        * Future directions: Starting the listener in the constructor is problematic. If this class would be
        * subclassed, the Thread would start too early. Right now it cannot happen, as this class is final.
        * Second, we possibly want a Thread restart mechanism anyhow, like we have with the expiration and
        * eviction threads. For the latter, there should be a dedicated "BackgroundThreadController<T>" class
        * that controls/restarts background threads.
        */
       dispatchThread = ensureListenerThreadIsRunning();
   }