当前位置: 首页>>代码示例>>Java>>正文


Java CacheEntryListener类代码示例

本文整理汇总了Java中javax.cache.event.CacheEntryListener的典型用法代码示例。如果您正苦于以下问题:Java CacheEntryListener类的具体用法?Java CacheEntryListener怎么用?Java CacheEntryListener使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


CacheEntryListener类属于javax.cache.event包,在下文中一共展示了CacheEntryListener类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: deregisterCacheEntryListener

import javax.cache.event.CacheEntryListener; //导入依赖的package包/类
@Override
public void deregisterCacheEntryListener(CacheEntryListenerConfiguration<K, V> cacheEntryListenerConfiguration) {
    verifyCacheConnectivity();
    final Factory<CacheEntryListener<? super K,? super V>> factory = cacheEntryListenerConfiguration.getCacheEntryListenerFactory();
    final CacheEntryListener cacheEntryListener = factory.create();
    final CacheEventListener<K,V> cacheEventListener = new CacheEventListener<K, V>(cacheEntryListener, this, cacheEntryListenerConfiguration);
    try {
    if(cacheEventListener.isOnCreatedListenerConfigured() && addEventDescriptor != null) 
        innerCache.removeCacheDataModificationListener(addEventDescriptor);
    if(cacheEventListener.isOnUpdatedListenerConfigured() && updateEventDescriptor != null)
        innerCache.removeCacheDataModificationListener(updateEventDescriptor);
    if(cacheEventListener.isOnRemovedListenerConfigured() && deleteEventDescriptor != null) {
        if(!isExpiryEventConfigured)
            innerCache.removeCacheDataModificationListener(deleteEventDescriptor);
    }
    if(cacheEventListener.isOnExpiredListenerConfigured() && deleteEventDescriptor != null) {
        isExpiryEventConfigured = false;
        innerCache.removeCacheDataModificationListener(deleteEventDescriptor);
    }
    }
    catch (Exception e) {
        
    }
}
 
开发者ID:Alachisoft,项目名称:TayzGrid,代码行数:25,代码来源:TayzGridCache.java

示例2: run

import javax.cache.event.CacheEntryListener; //导入依赖的package包/类
@Override
public void run()
{
	@SuppressWarnings("unchecked")
	CacheEntryListener<K, V> listenerRef = (CacheEntryListener<K, V>) listener;

	while (running)
	{
		try
		{
			TCacheEntryEventCollection<K, V> eventColl = dispatchQueue.take();
			sendEvents(eventColl, listenerRef);
		}
		catch (InterruptedException ie)
		{
			// Interruption policy: Only used for quitting
		}
		catch (Exception exc)
		{
			// If the thread enters this line, there was an issue wit sendEvent(). Likely it
			// is in the user provided Listener code, so we must make sure not to die if this
			// happens. For now we will silently ignore any errors.
		}
	}
}
 
开发者ID:trivago,项目名称:triava,代码行数:26,代码来源:ListenerEntry.java

示例3: checkEvents

import javax.cache.event.CacheEntryListener; //导入依赖的package包/类
/**
 * @param cache Cache.
 * @param lsnrFactory Listener factory.
 * @param key Key.
 * @param create {@code True} if listens for create events.
 * @param update {@code True} if listens for update events.
 * @param rmv {@code True} if listens for remove events.
 * @param expire {@code True} if listens for expire events.
 * @throws Exception If failed.
 */
private void checkEvents(
    final IgniteCache<Object, Object> cache,
    final Factory<CacheEntryListener<Object, Object>> lsnrFactory,
    Integer key,
    boolean create,
    boolean update,
    boolean rmv,
    boolean expire) throws Exception {
    CacheEntryListenerConfiguration<Object, Object> lsnrCfg = new MutableCacheEntryListenerConfiguration<>(
        lsnrFactory,
        null,
        true,
        false
    );

    cache.registerCacheEntryListener(lsnrCfg);

    try {
        checkEvents(cache, lsnrCfg, key, create, update, rmv, expire, true);
    }
    finally {
        cache.deregisterCacheEntryListener(lsnrCfg);
    }
}
 
开发者ID:apache,项目名称:ignite,代码行数:35,代码来源:IgniteCacheEntryListenerAbstractTest.java

示例4: ehListenersFor

import javax.cache.event.CacheEntryListener; //导入依赖的package包/类
@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;
}
 
开发者ID:ehcache,项目名称:ehcache3,代码行数:25,代码来源:EventListenerAdaptors.java

示例5: onExpired

import javax.cache.event.CacheEntryListener; //导入依赖的package包/类
@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));
  }
}
 
开发者ID:cache2k,项目名称:cache2k,代码行数:18,代码来源:CacheEntryListenerClient.java

示例6: getCacheEntryListenerFactory

import javax.cache.event.CacheEntryListener; //导入依赖的package包/类
@Override
public Factory<CacheEntryListener<? super String, ? super String>> getCacheEntryListenerFactory() {
    return (Factory<CacheEntryListener<? super String, ? super String>>) () ->
            (CacheEntryCreatedListener<String, String>) cacheEntryEvents -> cacheEntryEvents.forEach((event) -> {
                logger.info("an entry k: " + event.getKey() + ", v: " + event.getValue() + " is added to myCache2");
            });
}
 
开发者ID:bootique-examples,项目名称:bootique-jcache-demo,代码行数:8,代码来源:MyCache2EntryListenerConfiguration.java

示例7: getCacheEntryListenerFactory

import javax.cache.event.CacheEntryListener; //导入依赖的package包/类
@Override
public Factory<CacheEntryListener<? super Long, ? super Long>> getCacheEntryListenerFactory() {
    return (Factory<CacheEntryListener<? super Long, ? super Long>>) () ->
            (CacheEntryCreatedListener<Long, Long>) cacheEntryEvents -> cacheEntryEvents.forEach((event) -> {
                logger.info("an entry k: " + event.getKey() + ", v: " + event.getValue() + " is added to myCache2");
            });
}
 
开发者ID:bootique-examples,项目名称:bootique-jcache-demo,代码行数:8,代码来源:MyCache2EntryListenerConfiguration.java

示例8: createEntryListenerConfiguration

import javax.cache.event.CacheEntryListener; //导入依赖的package包/类
private CacheEntryListenerConfiguration<Object, Object> createEntryListenerConfiguration() {
    return new MutableCacheEntryListenerConfiguration<>(
        new Factory<CacheEntryListener<Object, Object>>() {
            @Override
            public CacheEntryListener<Object, Object> create() {
                return new JCacheEntryEventListener() {
                    @Override
                    protected void onEvents(Iterable<CacheEntryEvent<?, ?>> events) {
                        for (CacheEntryEvent<?, ?> event : events) {
                            Exchange exchange = getEndpoint().createExchange();
                            Message message = exchange.getIn();
                            message.setHeader(JCacheConstants.EVENT_TYPE, event.getEventType().name());
                            message.setHeader(JCacheConstants.KEY, event.getKey());
                            message.setBody(event.getValue());

                            if (event.isOldValueAvailable()) {
                                message.setHeader(JCacheConstants.OLD_VALUE, event.getOldValue());
                            }

                            try {
                                getProcessor().process(exchange);
                            } catch (Exception e) {
                                LOGGER.error("Error processing event ", e);
                            }
                        }
                    }
                };
            }
        },
        new Factory<CacheEntryEventFilter<Object, Object>>() {
            @Override
            public CacheEntryEventFilter<Object, Object> create() {
                return getJCacheEndpoint().getManager().getEventFilter();
            }
        },
        getJCacheEndpoint().getManager().getConfiguration().isOldValueRequired(),
        getJCacheEndpoint().getManager().getConfiguration().isSynchronous()
    );
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:40,代码来源:JCacheConsumer.java

示例9: CacheEventListener

import javax.cache.event.CacheEntryListener; //导入依赖的package包/类
public CacheEventListener(CacheEntryListener<K,V> cacheEntryListener, final TayzGridCache<K,V> jCache, final CacheEntryListenerConfiguration<K,V> cacheEntryListenerConfiguration) {
    _cacheEntryListener = cacheEntryListener;
    _jCache = jCache;
    
    if(cacheEntryListenerConfiguration.getCacheEntryEventFilterFactory() != null) 
        _cacheEntryEventFilter = cacheEntryListenerConfiguration.getCacheEntryEventFilterFactory().create();
    else
        _cacheEntryEventFilter = null;
    
    _isOnCreatedListener = implementsMethod(CacheEntryCreatedListener.class);
    _isOnExpiredListener = implementsMethod(CacheEntryExpiredListener.class);
    _isOnRemovedListener = implementsMethod(CacheEntryRemovedListener.class);
    _isOnUpdatedListener = implementsMethod(CacheEntryUpdatedListener.class);
}
 
开发者ID:Alachisoft,项目名称:TayzGrid,代码行数:15,代码来源:CacheEventListener.java

示例10: registerCacheEntryListener

import javax.cache.event.CacheEntryListener; //导入依赖的package包/类
@Override
public void registerCacheEntryListener(CacheEntryListenerConfiguration<K, V> cacheEntryListenerConfiguration) {
    verifyCacheConnectivity();
    final Factory<CacheEntryListener<? super K, ? super V> > factory = cacheEntryListenerConfiguration.getCacheEntryListenerFactory();
    final CacheEntryListener cacheEntryListener = factory.create();
    final CacheEventListener<K,V> cacheEventListener = new CacheEventListener<K, V>(cacheEntryListener, this, cacheEntryListenerConfiguration);
    try {
        EnumSet<EventType> eventType = null;
        if(cacheEventListener.isOnCreatedListenerConfigured()) {
            eventType = EnumSet.of(EventType.ItemAdded);
            addEventDescriptor = innerCache.addCacheDataModificationListener(cacheEventListener, eventType, EventDataFilter.DataWithMetaData);
        }
        if(cacheEventListener.isOnUpdatedListenerConfigured()) {
            eventType = EnumSet.of(EventType.ItemUpdated);
            updateEventDescriptor = innerCache.addCacheDataModificationListener(cacheEventListener, eventType, EventDataFilter.DataWithMetaData);
        }
        if(cacheEventListener.isOnExpiredListenerConfigured() || cacheEventListener.isOnRemovedListenerConfigured()) {
            if(cacheEventListener.isOnExpiredListenerConfigured())
                isExpiryEventConfigured = true;
            eventType = EnumSet.of(EventType.ItemRemoved);
            deleteEventDescriptor = innerCache.addCacheDataModificationListener(cacheEventListener, eventType, EventDataFilter.DataWithMetaData);
        }
        
    }
    catch (Exception e) {
        
    }
}
 
开发者ID:Alachisoft,项目名称:TayzGrid,代码行数:29,代码来源:TayzGridCache.java

示例11: scheduleEvents

import javax.cache.event.CacheEntryListener; //导入依赖的package包/类
/**
 * Schedules to send the events to the given listener. Scheduling means to send immediately if this
 * {@link ListenerEntry} is synchronous, or to put it in a queue if asynchronous (including the forceAsync
 * parameter. For synchronous delivery, it is guaranteed that the listener was executed when returning
 * from this method.
 * <p>
 * The given eventType must match all events
 * 
 * @param events The events to send
 * @param listener The listener to notify
 * @param eventType The event type. It must match all events to send
 * @param forceAsync
 */
private void scheduleEvents(List<CacheEntryEvent<? extends K, ? extends V>> events, CacheEntryListener<K, V> listener,
		EventType eventType, boolean forceAsync)
{
	if (eventManager == null)
		return;
	
	TCacheEntryEventCollection<K, V> eventColl = new TCacheEntryEventCollection<>(events, eventType);
	if (!(forceAsync || dispatchMode.isAsync()))
	{
		sendEvents(eventColl, listener);
	}
	else
	{
		try
		{
			dispatchQueue.put(eventColl);
		}
		catch (InterruptedException e)
		{
			/** Interruption policy:
			 * The #dispatch method can be part of client interaction like a put or get call. Or it can
			 * be from internal operations like eviction. In both cases we do not want to blindly
			 * bubble up the stack until some random code catches it. Reason is, that it could leave the
			 * Cache in an inconsistent state, e.g. a value was put() into the cache but the statistics
			 * do not reflect that. Thus, we simply mark the current thread interrupted, so any caller
			 * on any stack level may inspect the status.
			 */
			Thread.currentThread().interrupt();
			// If we come here, the event may not be in the dispatchQueue. But we will not
			// retry, as there are no guarantees when interrupting and it is safer to just go on.
			// For example if during shutdown the dispatchQueue is full, we would iterate here
			// forever as the DispatchRunnable instance could be shutdown and not read from the
			// queue any longer.
		}
	}
}
 
开发者ID:trivago,项目名称:triava,代码行数:50,代码来源:ListenerEntry.java

示例12: sendEvents

import javax.cache.event.CacheEntryListener; //导入依赖的package包/类
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.
        }
	}
 
开发者ID:trivago,项目名称:triava,代码行数:31,代码来源:ListenerEntry.java

示例13: JCacheQueryLocalListener

import javax.cache.event.CacheEntryListener; //导入依赖的package包/类
/**
 * @param impl Listener.
 * @param log Logger.
 */
JCacheQueryLocalListener(CacheEntryListener<K, V> impl, IgniteLogger log) {
    assert impl != null;
    assert log != null;

    this.impl = impl;

    this.log = log;
}
 
开发者ID:apache,项目名称:ignite,代码行数:13,代码来源:CacheContinuousQueryManager.java

示例14: getCacheEntryListenerFactory

import javax.cache.event.CacheEntryListener; //导入依赖的package包/类
/** {@inheritDoc} */
@Override public Factory<CacheEntryListener> getCacheEntryListenerFactory() {
    return new Factory<CacheEntryListener>() {
        @Override public CacheEntryListener create() {
            return new NoopCacheEntryListener();
        }
    };
}
 
开发者ID:apache,项目名称:ignite,代码行数:9,代码来源:ConfigVariations.java

示例15: testNoOldValue

import javax.cache.event.CacheEntryListener; //导入依赖的package包/类
/**
 * @throws Exception If failed.
 */
public void testNoOldValue() throws Exception {
    CacheEntryListenerConfiguration<Object, Object> lsnrCfg = new MutableCacheEntryListenerConfiguration<>(
        new Factory<CacheEntryListener<Object, Object>>() {
            @Override public CacheEntryListener<Object, Object> create() {
                return new CreateUpdateRemoveExpireListener();
            }
        },
        null,
        false,
        true
    );

    IgniteCache<Object, Object> cache = jcache();

    try {
        for (Integer key : keys()) {
            log.info("Check create/update/remove/expire events, no old value [key=" + key + ']');

            cache.registerCacheEntryListener(lsnrCfg);

            checkEvents(cache, lsnrCfg, key, true, true, true, true, false);
        }
    }
    finally {
        cache.deregisterCacheEntryListener(lsnrCfg);
    }
}
 
开发者ID:apache,项目名称:ignite,代码行数:31,代码来源:IgniteCacheEntryListenerAbstractTest.java


注:本文中的javax.cache.event.CacheEntryListener类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。