javax.cache.event.CacheEntryExpiredListener Java Examples

The following examples show how to use javax.cache.event.CacheEntryExpiredListener. 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: ListenerEntry.java    From triava with Apache License 2.0 6 votes vote down vote up
/**
 * Returns whether this {@link ListenerEntry} is listening to the given eventType
 * @param eventType The event Type
 * @return true, if the listener is listening to the given eventType
 */
boolean isListeningFor(EventType eventType)
{
	switch (eventType)
	{
		case CREATED:
			return listener instanceof CacheEntryCreatedListener;
		case EXPIRED:
			return listener instanceof CacheEntryExpiredListener;
		case REMOVED:
			return listener instanceof CacheEntryRemovedListener;
		case UPDATED:
			return listener instanceof CacheEntryUpdatedListener;
	}

	return false;
}
 
Example #2
Source File: EventListenerAdaptors.java    From ehcache3 with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
static <K, V> List<EventListenerAdaptor<K, V>> ehListenersFor(CacheEntryListener<? super K, ? super V> listener,
    CacheEntryEventFilter<? super K, ? super V> filter, Cache<K, V> source, boolean requestsOld) {
  List<EventListenerAdaptor<K, V>> rv = new ArrayList<>();

  if (listener instanceof CacheEntryUpdatedListener) {
    rv.add(new UpdatedAdaptor<>(source, (CacheEntryUpdatedListener<K, V>) listener,
      (CacheEntryEventFilter<K, V>) filter, requestsOld));
  }
  if (listener instanceof CacheEntryCreatedListener) {
    rv.add(new CreatedAdaptor<>(source, (CacheEntryCreatedListener<K, V>) listener,
      (CacheEntryEventFilter<K, V>) filter, requestsOld));
  }
  if (listener instanceof CacheEntryRemovedListener) {
    rv.add(new RemovedAdaptor<>(source, (CacheEntryRemovedListener<K, V>) listener,
      (CacheEntryEventFilter<K, V>) filter, requestsOld));
  }
  if (listener instanceof CacheEntryExpiredListener) {
    rv.add(new ExpiredAdaptor<>(source, (CacheEntryExpiredListener<K, V>) listener,
      (CacheEntryEventFilter<K, V>) filter, requestsOld));
  }

  return rv;
}
 
Example #3
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 #4
Source File: CacheEntryListenerClient.java    From cache2k with Apache License 2.0 6 votes vote down vote up
@Override
public void onExpired(Iterable<CacheEntryEvent<? extends K, ? extends V>> cacheEntryEvents) throws CacheEntryListenerException {
  if (isDirectCallable()) {
    for (CacheEntryListener<K,V> l : listenerServer.getListeners()) {
      if (l instanceof CacheEntryExpiredListener) {
        ((CacheEntryExpiredListener<K,V>) l).onExpired(cacheEntryEvents);
      }
    }
    return;
  }
  // since ExpiryEvents are processed asynchronously, this may cause issues.
  // the test do not currently delay waiting for asynchronous expiry events to complete processing.
  // not breaking anything now, so leaving in for time being.
  for (CacheEntryEvent<? extends K, ? extends V> event : cacheEntryEvents) {
    getClient().invoke(new OnCacheEntryEventHandler<K, V>(event));
  }
}
 
Example #5
Source File: ListenerEntry.java    From triava with Apache License 2.0 5 votes vote down vote up
private void sendEvents(TCacheEntryEventCollection<K, V> eventColl, CacheEntryListener<K, V> listener)
	{
		EventType eventType = eventColl.eventType();
//		System.out.println("sendEvents to listener " + listener + ", eventType=" + eventColl.eventType());
		switch (eventType)
        {
            case CREATED:
                if (listener instanceof CacheEntryCreatedListener)
                    eventManager.created((CacheEntryCreatedListener<K, V>)listener, eventColl);
                break;

            case EXPIRED:
                if (listener instanceof CacheEntryExpiredListener)
                    eventManager.expired((CacheEntryExpiredListener<K, V>)listener,  eventColl);
                break;

            case UPDATED:
                if (listener instanceof CacheEntryUpdatedListener)
                    eventManager.updated((CacheEntryUpdatedListener<K,V>)listener,  eventColl);
                break;

            case REMOVED:
                if (listener instanceof CacheEntryRemovedListener)
                    eventManager.removed((CacheEntryRemovedListener<K,V>)listener,  eventColl);
                break;

            default:
                // By default do nothing. If new event types are added to the Spec, they will be ignored.
        }
	}
 
Example #6
Source File: EventTypeAwareListener.java    From caffeine with Apache License 2.0 5 votes vote down vote up
/** Returns if the backing listener consumes this type of event. */
@SuppressWarnings("PMD.SwitchStmtsShouldHaveDefault")
public boolean isCompatible(@NonNull EventType eventType) {
  switch (eventType) {
    case CREATED:
      return (listener instanceof CacheEntryCreatedListener<?, ?>);
    case UPDATED:
      return (listener instanceof CacheEntryUpdatedListener<?, ?>);
    case REMOVED:
      return (listener instanceof CacheEntryRemovedListener<?, ?>);
    case EXPIRED:
      return (listener instanceof CacheEntryExpiredListener<?, ?>);
  }
  throw new IllegalStateException("Unknown event type: " + eventType);
}
 
Example #7
Source File: EventTypeAwareListener.java    From caffeine with Apache License 2.0 5 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public void onExpired(Iterable<CacheEntryEvent<? extends K, ? extends V>> events) {
  if (listener instanceof CacheEntryExpiredListener<?, ?>) {
    ((CacheEntryExpiredListener<K, V>) listener).onExpired(events);
  }
}
 
Example #8
Source File: EventTypeFilter.java    From caffeine with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("PMD.SwitchStmtsShouldHaveDefault")
private boolean isCompatible(CacheEntryEvent<? extends K, ? extends V> event) {
  switch (event.getEventType()) {
    case CREATED:
      return (listener instanceof CacheEntryCreatedListener<?, ?>);
    case UPDATED:
      return (listener instanceof CacheEntryUpdatedListener<?, ?>);
    case REMOVED:
      return (listener instanceof CacheEntryRemovedListener<?, ?>);
    case EXPIRED:
      return (listener instanceof CacheEntryExpiredListener<?, ?>);
  }
  throw new CacheEntryListenerException("Unknown event type: " + event.getEventType());
}
 
Example #9
Source File: JCSListener.java    From commons-jcs with Apache License 2.0 5 votes vote down vote up
public void onExpired(final List<CacheEntryEvent<? extends K, ? extends V>> events) throws CacheEntryListenerException
{
    if (expire)
    {
        CacheEntryExpiredListener.class.cast(delegate).onExpired(filter(events));
    }
}
 
Example #10
Source File: CacheEntryListenerServer.java    From cache2k with Apache License 2.0 5 votes vote down vote up
private void runHandlers(EventType eventType, TestCacheEntryEvent event) {
  ArrayList events = new ArrayList(1);
  events.add(event);

  for (CacheEntryListener listener : listeners) {
    switch (eventType) {
      case CREATED :
        if (listener instanceof CacheEntryCreatedListener) {
          ((CacheEntryCreatedListener) listener).onCreated(events);
        }
        break;

      case UPDATED:
        if (listener instanceof CacheEntryUpdatedListener) {
          ((CacheEntryUpdatedListener) listener).onUpdated(events);
        }
        break;

      case REMOVED:
        if (listener instanceof CacheEntryRemovedListener) {
          ((CacheEntryRemovedListener) listener).onRemoved(events);
        }
        break;

      case EXPIRED:
        if (listener instanceof CacheEntryExpiredListener) {
          ((CacheEntryExpiredListener) listener).onExpired(events);
        }
        break;

      default:
        break;
    }
  }
}
 
Example #11
Source File: ListenerCacheEventManager.java    From triava with Apache License 2.0 4 votes vote down vote up
@Override
public void expired(CacheEntryExpiredListener<K, V> listener, TCacheEntryEventCollection<K, V> eventColl)
{
	listener.onExpired(eventColl.events());
}
 
Example #12
Source File: CacheContinuousQueryManager.java    From ignite with Apache License 2.0 4 votes vote down vote up
/**
 * @throws IgniteCheckedException In case of error.
 */
@SuppressWarnings("unchecked")
void execute() throws IgniteCheckedException {
    if (!onStart)
        cctx.config().addCacheEntryListenerConfiguration(cfg);

    CacheEntryListener locLsnrImpl = (CacheEntryListener)cfg.getCacheEntryListenerFactory().create();

    if (locLsnrImpl == null)
        throw new IgniteCheckedException("Local CacheEntryListener is mandatory and can't be null.");

    byte types = 0;

    types |= locLsnrImpl instanceof CacheEntryCreatedListener ? CREATED_FLAG : 0;
    types |= locLsnrImpl instanceof CacheEntryUpdatedListener ? UPDATED_FLAG : 0;
    types |= locLsnrImpl instanceof CacheEntryRemovedListener ? REMOVED_FLAG : 0;
    types |= locLsnrImpl instanceof CacheEntryExpiredListener ? EXPIRED_FLAG : 0;

    if (types == 0)
        throw new IgniteCheckedException("Listener must implement one of CacheEntryListener sub-interfaces.");

    final byte types0 = types;

    locLsnr = new JCacheQueryLocalListener(
        locLsnrImpl,
        log);

    routineId = executeQuery0(
        locLsnr,
        new IgniteOutClosure<CacheContinuousQueryHandler>() {
            @Override public CacheContinuousQueryHandler apply() {
                CacheContinuousQueryHandler hnd;
                Factory<CacheEntryEventFilter<K, V>> rmtFilterFactory = cfg.getCacheEntryEventFilterFactory();

                if (rmtFilterFactory != null)
                    hnd = new CacheContinuousQueryHandlerV2(
                        cctx.name(),
                        TOPIC_CACHE.topic(topicPrefix, cctx.localNodeId(), seq.getAndIncrement()),
                        locLsnr,
                        securityAwareFilterFactory(rmtFilterFactory),
                        cfg.isOldValueRequired(),
                        cfg.isSynchronous(),
                        false,
                        false,
                        types0);
                else {
                    JCacheQueryRemoteFilter jCacheFilter;

                    CacheEntryEventFilter filter = null;

                    if (rmtFilterFactory != null) {
                        filter = rmtFilterFactory.create();

                        if (!(filter instanceof Serializable))
                            throw new IgniteException("Topology has nodes of the old versions. " +
                                "In this case EntryEventFilter must implement java.io.Serializable " +
                                "interface. Filter: " + filter);
                    }

                    jCacheFilter = new JCacheQueryRemoteFilter(filter, types0);

                    hnd = new CacheContinuousQueryHandler(
                        cctx.name(),
                        TOPIC_CACHE.topic(topicPrefix, cctx.localNodeId(), seq.getAndIncrement()),
                        locLsnr,
                        securityAwareFilter(jCacheFilter),
                        cfg.isOldValueRequired(),
                        cfg.isSynchronous(),
                        false,
                        false);
                }

                return hnd;
            }
        },
        ContinuousQuery.DFLT_PAGE_SIZE,
        ContinuousQuery.DFLT_TIME_INTERVAL,
        ContinuousQuery.DFLT_AUTO_UNSUBSCRIBE,
        false,
        false,
        false,
        keepBinary,
        onStart
    );
}
 
Example #13
Source File: EventListenerAdaptors.java    From ehcache3 with Apache License 2.0 4 votes vote down vote up
ExpiredAdaptor(Cache<K, V> source, CacheEntryExpiredListener<K, V> listener, CacheEntryEventFilter<K, V> filter,
    boolean requestsOld) {
  super(source, filter, requestsOld);
  this.listener = listener;
}
 
Example #14
Source File: Listener.java    From cache2k with Apache License 2.0 4 votes vote down vote up
public Expired(final CacheEntryListenerConfiguration<K, V> _config, final CacheEntryEventFilter<K, V> _filter, final CacheEntryExpiredListener<K, V> _listener) {
  super(_config, _filter, _listener);
  listener = _listener;
}
 
Example #15
Source File: CacheEventManager.java    From triava with Apache License 2.0 votes vote down vote up
void expired(CacheEntryExpiredListener<K, V> listener, TCacheEntryEventCollection<K, V> eventColl);