net.sf.ehcache.Ehcache.getCacheEventNotificationService()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(9.6k)|赞(0)|评价(0)|浏览(170)

本文整理了Java中net.sf.ehcache.Ehcache.getCacheEventNotificationService()方法的一些代码示例,展示了Ehcache.getCacheEventNotificationService()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Ehcache.getCacheEventNotificationService()方法的具体详情如下:
包路径:net.sf.ehcache.Ehcache
类名称:Ehcache
方法名:getCacheEventNotificationService

Ehcache.getCacheEventNotificationService介绍

[英]Use this to access the service in order to register and unregister listeners
[中]使用此选项访问服务,以便注册和注销侦听器

代码示例

代码示例来源:origin: gocd/gocd

public void addListener(CacheEventListener listener) {
  ehCache.getCacheEventNotificationService().registerListener(listener);
}

代码示例来源:origin: gocd/gocd

public void removeListener(CacheEventListener cacheEventListener) {
  ehCache.getCacheEventNotificationService().unregisterListener(cacheEventListener);
}

代码示例来源:origin: AxonFramework/AxonFramework

@Override
protected Registration doRegisterListener(CacheEventListener listenerAdapter) {
  ehCache.getCacheEventNotificationService().registerListener(listenerAdapter);
  return () -> ehCache.getCacheEventNotificationService().unregisterListener(listenerAdapter);
}

代码示例来源:origin: gocd/gocd

protected void registerAsCacheEvictionListener() {
  ehCache.getCacheEventNotificationService().registerListener(new CacheEvictionListener(this));
}

代码示例来源:origin: spring-projects/spring-framework

rawCache.getCacheEventNotificationService().registerListener(listener);

代码示例来源:origin: org.springframework/spring-context-support

rawCache.getCacheEventNotificationService().registerListener(listener);

代码示例来源:origin: net.sf.ehcache/ehcache

/**
 * {@inheritDoc}
 */
public RegisteredEventListeners getCacheEventNotificationService() {
  return underlyingCache.getCacheEventNotificationService();
}

代码示例来源:origin: net.sf.ehcache/ehcache

/**
* {@inheritDoc}
*/
public RegisteredEventListeners getCacheEventNotificationService() {
  // THIS IS GENERATED CODE -- DO NOT HAND MODIFY!
  Thread t = Thread.currentThread();
  ClassLoader prev = t.getContextClassLoader();
  t.setContextClassLoader(this.classLoader);
  try {
    return this.cache.getCacheEventNotificationService();
  } finally {
    t.setContextClassLoader(prev);
  }
}

代码示例来源:origin: net.sf.ehcache/ehcache

/**
 * Determine if the given cache is distributed.
 *
 * @param cache the cache to check
 * @return true if a <code>CacheReplicator</code> is found in the listeners
 */
protected boolean isDistributed(Ehcache cache) {
  Set listeners = cache.getCacheEventNotificationService().getCacheEventListeners();
  for (Iterator iterator = listeners.iterator(); iterator.hasNext();) {
    CacheEventListener cacheEventListener = (CacheEventListener) iterator.next();
    if (cacheEventListener instanceof CacheReplicator) {
      return true;
    }
  }
  return false;
}

代码示例来源:origin: net.sf.ehcache/ehcache

/**
 * Before eviction elements are checked.
 *
 * @param element the element to notify about its expiry
 */
private void notifyExpiry(final Element element) {
  cache.getCacheEventNotificationService().notifyElementExpiry(copyStrategyHandler.copyElementForReadIfNeeded(element), false);
}

代码示例来源:origin: net.sf.ehcache/ehcache

/**
 * Before eviction elements are checked.
 *
 * @param element
 */
protected final void notifyExpiry(Element element) {
  cache.getCacheEventNotificationService().notifyElementExpiry(copyStrategyHandler.copyElementForReadIfNeeded(element), false);
}

代码示例来源:origin: net.sf.ehcache/ehcache

@Override
public synchronized void notifyCacheEventListenersChanged() {
 if (cache.getCacheEventNotificationService().hasCacheEventListeners() && !cacheEventListenerRegistered) {
  backend.addListener(evictionListener);
  cacheEventListenerRegistered = true;
 } else if (!cache.getCacheEventNotificationService().hasCacheEventListeners() && cacheEventListenerRegistered) {
  dropLeaderStatus();
  backend.removeListener(evictionListener);
  cacheEventListenerRegistered = false;
 }
}

代码示例来源:origin: net.sf.ehcache/ehcache

/**
 * Called when an element is evicted even before it could be installed inside the store
 *
 * @param element the evicted element
 */
protected void notifyDirectEviction(final Element element) {
  evictionObserver.begin();
  evictionObserver.end(EvictionOutcome.SUCCESS);
  cache.getCacheEventNotificationService().notifyElementEvicted(copyStrategyHandler.copyElementForReadIfNeeded(element), false);
}

代码示例来源:origin: net.sf.ehcache/ehcache

/**
 * Evict the <code>Element</code>.
 * <p>
 * Evict means that the <code>Element</code> is:
 * <ul>
 * <li>if, the store is diskPersistent, the <code>Element</code> is spooled to the DiskStore
 * <li>if not, the <code>Element</code> is removed.
 * </ul>
 *
 * @param element the <code>Element</code> to be evicted.
 */
protected final void evict(Element element) throws CacheException {
  if (cache.getCacheConfiguration().isOverflowToDisk()) {
    if (!element.isSerializable()) {
      if (LOG.isWarnEnabled()) {
        LOG.warn(new StringBuilder("Object with key ").append(element.getObjectKey())
            .append(" is not Serializable and cannot be overflowed to disk").toString());
      }
      cache.getCacheEventNotificationService().notifyElementEvicted(copyStrategyHandler.copyElementForReadIfNeeded(element), false);
    } else {
      spoolToDisk(element);
    }
  } else {
    evictionObserver.begin();
    evictionObserver.end(EvictionOutcome.SUCCESS);
    cache.getCacheEventNotificationService().notifyElementEvicted(copyStrategyHandler.copyElementForReadIfNeeded(element), false);
  }
}

代码示例来源:origin: net.sf.ehcache/ehcache

/**
 * Expire all elements.
 * <p>
 * This is a default implementation which does nothing. Expiration on demand is only implemented for disk stores.
 */
public void expireElements() {
  for (Object key : keySet()) {
    final Element element = expireElement(key);
    if (element != null) {
      cache.getCacheEventNotificationService()
        .notifyElementExpiry(copyStrategyHandler.copyElementForReadIfNeeded(element), false);
    }
  }
}

代码示例来源:origin: net.sf.ehcache/ehcache

public SoftLockManager getOrCreateClusteredSoftLockFactory(Ehcache cache) {
 String name = toolkitInstanceFactory.getFullyQualifiedCacheName(cache);
 SoftLockManager softLockFactory = softLockFactories.get(name);
 if (softLockFactory == null) {
  softLockFactory = new ReadCommittedClusteredSoftLockFactory(toolkitInstanceFactory, cache.getCacheManager()
    .getName(), cache.getName());
  SoftLockManager old = softLockFactories.putIfAbsent(name, softLockFactory);
  if (old == null) {
   // Put successful add a Cache Event Listener.
   cache.getCacheEventNotificationService().registerListener(new EventListener(name));
  } else {
   softLockFactory = old;
  }
 }
 return softLockFactory;
}

代码示例来源:origin: net.sf.ehcache/ehcache

/**
 * Evicts the element from the store
 * @param element the element to be evicted
 * @return true if succeeded, false otherwise
 */
protected boolean evict(final Element element) {
  final ReentrantReadWriteLock.WriteLock lock = map.lockFor(element.getObjectKey()).writeLock();
  if (lock.tryLock()) {
    evictionObserver.begin();
    Element remove;
    try {
      remove = remove(element.getObjectKey());
    } finally {
      lock.unlock();
    }
    if (remove != null) {
      evictionObserver.end(EvictionOutcome.SUCCESS);
      cache.getCacheEventNotificationService().notifyElementEvicted(copyStrategyHandler.copyElementForReadIfNeeded(remove), false);
    }
    return remove != null;
  }
  return false;
}

代码示例来源:origin: net.sf.ehcache/ehcache

/**
 * Creates a persitent-to-disk store for the given cache, using the given disk path.
 *
 * @param cache cache that fronts this store
 * @param onHeapPool pool to track heap usage
 * @param onDiskPool pool to track disk usage
 * @return a fully initialized store
 */
public static DiskStore create(Ehcache cache, Pool onHeapPool, Pool onDiskPool) {
  if (cache.getCacheManager() == null) {
    throw new CacheException("Can't create diskstore without a cache manager");
  }
  DiskStorageFactory disk = new DiskStorageFactory(cache, cache.getCacheEventNotificationService());
  DiskStore store = new DiskStore(disk, cache, onHeapPool, onDiskPool);
  cache.getCacheConfiguration().addConfigurationListener(new CacheConfigurationListenerAdapter(disk, onDiskPool));
  return store;
}

代码示例来源:origin: net.sf.ehcache/ehcache

private DiskStore(DiskStorageFactory disk, Ehcache cache, Pool onHeapPool, Pool onDiskPool) {
  this.segments = new Segment[DEFAULT_SEGMENT_COUNT];
  this.segmentShift = Integer.numberOfLeadingZeros(segments.length - 1);
  EventRateSimpleMovingAverage hitRate = new EventRateSimpleMovingAverage(1, TimeUnit.SECONDS);
  EventRateSimpleMovingAverage missRate = new EventRateSimpleMovingAverage(1, TimeUnit.SECONDS);
  OperationStatistic<GetOutcome> getStatistic = StatisticsManager.getOperationStatisticFor(getObserver);
  getStatistic.addDerivedStatistic(new OperationResultFilter<GetOutcome>(EnumSet.of(GetOutcome.HIT), hitRate));
  getStatistic.addDerivedStatistic(new OperationResultFilter<GetOutcome>(EnumSet.of(GetOutcome.MISS), missRate));
  this.onHeapPoolAccessor = onHeapPool.createPoolAccessor(new DiskStoreHeapPoolParticipant(hitRate, missRate),
    SizeOfPolicyConfiguration.resolveMaxDepth(cache),
    SizeOfPolicyConfiguration.resolveBehavior(cache).equals(SizeOfPolicyConfiguration.MaxDepthExceededBehavior.ABORT));
  this.onDiskPoolAccessor = onDiskPool.createPoolAccessor(new DiskStoreDiskPoolParticipant(hitRate, missRate), new DiskSizeOfEngine());
  for (int i = 0; i < this.segments.length; ++i) {
    this.segments[i] = new Segment(DEFAULT_INITIAL_CAPACITY, DEFAULT_LOAD_FACTOR,
        disk, cache.getCacheConfiguration(), onHeapPoolAccessor, onDiskPoolAccessor,
        cache.getCacheEventNotificationService(), evictionObserver);
  }
  this.disk = disk;
  this.disk.bind(this);
  this.status.set(Status.STATUS_ALIVE);
}

代码示例来源:origin: net.sf.ehcache/ehcache

private void processEventNotification(CacheEventNotificationMsg msg) {
 RegisteredEventListeners notificationService = ecache.getCacheEventNotificationService();
 switch (msg.getToolkitEventType()) {
  case ELEMENT_REMOVED:
   notificationService.notifyElementRemoved(msg.getElement(), true);
   break;
  case ELEMENT_PUT:
   notificationService.notifyElementPut(msg.getElement(), true);
   break;
  case ELEMENT_UPDATED:
   notificationService.notifyElementUpdated(msg.getElement(), true);
   break;
  case ELEMENT_EXPIRED:
   notificationService.notifyElementExpiry(msg.getElement(), true);
   break;
  case ELEMENT_EVICTED:
   notificationService.notifyElementEvicted(msg.getElement(), true);
   break;
  case REMOVEALL:
   notificationService.notifyRemoveAll(true);
   break;
 }
}

相关文章

Ehcache类方法