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

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

本文整理了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

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

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

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

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

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

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

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

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

  1. rawCache.getCacheEventNotificationService().registerListener(listener);

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

  1. rawCache.getCacheEventNotificationService().registerListener(listener);

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

  1. /**
  2. * {@inheritDoc}
  3. */
  4. public RegisteredEventListeners getCacheEventNotificationService() {
  5. return underlyingCache.getCacheEventNotificationService();
  6. }

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

  1. /**
  2. * {@inheritDoc}
  3. */
  4. public RegisteredEventListeners getCacheEventNotificationService() {
  5. // THIS IS GENERATED CODE -- DO NOT HAND MODIFY!
  6. Thread t = Thread.currentThread();
  7. ClassLoader prev = t.getContextClassLoader();
  8. t.setContextClassLoader(this.classLoader);
  9. try {
  10. return this.cache.getCacheEventNotificationService();
  11. } finally {
  12. t.setContextClassLoader(prev);
  13. }
  14. }

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

  1. /**
  2. * Determine if the given cache is distributed.
  3. *
  4. * @param cache the cache to check
  5. * @return true if a <code>CacheReplicator</code> is found in the listeners
  6. */
  7. protected boolean isDistributed(Ehcache cache) {
  8. Set listeners = cache.getCacheEventNotificationService().getCacheEventListeners();
  9. for (Iterator iterator = listeners.iterator(); iterator.hasNext();) {
  10. CacheEventListener cacheEventListener = (CacheEventListener) iterator.next();
  11. if (cacheEventListener instanceof CacheReplicator) {
  12. return true;
  13. }
  14. }
  15. return false;
  16. }

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

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

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

  1. /**
  2. * Before eviction elements are checked.
  3. *
  4. * @param element
  5. */
  6. protected final void notifyExpiry(Element element) {
  7. cache.getCacheEventNotificationService().notifyElementExpiry(copyStrategyHandler.copyElementForReadIfNeeded(element), false);
  8. }

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

  1. @Override
  2. public synchronized void notifyCacheEventListenersChanged() {
  3. if (cache.getCacheEventNotificationService().hasCacheEventListeners() && !cacheEventListenerRegistered) {
  4. backend.addListener(evictionListener);
  5. cacheEventListenerRegistered = true;
  6. } else if (!cache.getCacheEventNotificationService().hasCacheEventListeners() && cacheEventListenerRegistered) {
  7. dropLeaderStatus();
  8. backend.removeListener(evictionListener);
  9. cacheEventListenerRegistered = false;
  10. }
  11. }

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

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

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

  1. /**
  2. * Evict the <code>Element</code>.
  3. * <p>
  4. * Evict means that the <code>Element</code> is:
  5. * <ul>
  6. * <li>if, the store is diskPersistent, the <code>Element</code> is spooled to the DiskStore
  7. * <li>if not, the <code>Element</code> is removed.
  8. * </ul>
  9. *
  10. * @param element the <code>Element</code> to be evicted.
  11. */
  12. protected final void evict(Element element) throws CacheException {
  13. if (cache.getCacheConfiguration().isOverflowToDisk()) {
  14. if (!element.isSerializable()) {
  15. if (LOG.isWarnEnabled()) {
  16. LOG.warn(new StringBuilder("Object with key ").append(element.getObjectKey())
  17. .append(" is not Serializable and cannot be overflowed to disk").toString());
  18. }
  19. cache.getCacheEventNotificationService().notifyElementEvicted(copyStrategyHandler.copyElementForReadIfNeeded(element), false);
  20. } else {
  21. spoolToDisk(element);
  22. }
  23. } else {
  24. evictionObserver.begin();
  25. evictionObserver.end(EvictionOutcome.SUCCESS);
  26. cache.getCacheEventNotificationService().notifyElementEvicted(copyStrategyHandler.copyElementForReadIfNeeded(element), false);
  27. }
  28. }

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

  1. /**
  2. * Expire all elements.
  3. * <p>
  4. * This is a default implementation which does nothing. Expiration on demand is only implemented for disk stores.
  5. */
  6. public void expireElements() {
  7. for (Object key : keySet()) {
  8. final Element element = expireElement(key);
  9. if (element != null) {
  10. cache.getCacheEventNotificationService()
  11. .notifyElementExpiry(copyStrategyHandler.copyElementForReadIfNeeded(element), false);
  12. }
  13. }
  14. }

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

  1. public SoftLockManager getOrCreateClusteredSoftLockFactory(Ehcache cache) {
  2. String name = toolkitInstanceFactory.getFullyQualifiedCacheName(cache);
  3. SoftLockManager softLockFactory = softLockFactories.get(name);
  4. if (softLockFactory == null) {
  5. softLockFactory = new ReadCommittedClusteredSoftLockFactory(toolkitInstanceFactory, cache.getCacheManager()
  6. .getName(), cache.getName());
  7. SoftLockManager old = softLockFactories.putIfAbsent(name, softLockFactory);
  8. if (old == null) {
  9. // Put successful add a Cache Event Listener.
  10. cache.getCacheEventNotificationService().registerListener(new EventListener(name));
  11. } else {
  12. softLockFactory = old;
  13. }
  14. }
  15. return softLockFactory;
  16. }

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

  1. /**
  2. * Evicts the element from the store
  3. * @param element the element to be evicted
  4. * @return true if succeeded, false otherwise
  5. */
  6. protected boolean evict(final Element element) {
  7. final ReentrantReadWriteLock.WriteLock lock = map.lockFor(element.getObjectKey()).writeLock();
  8. if (lock.tryLock()) {
  9. evictionObserver.begin();
  10. Element remove;
  11. try {
  12. remove = remove(element.getObjectKey());
  13. } finally {
  14. lock.unlock();
  15. }
  16. if (remove != null) {
  17. evictionObserver.end(EvictionOutcome.SUCCESS);
  18. cache.getCacheEventNotificationService().notifyElementEvicted(copyStrategyHandler.copyElementForReadIfNeeded(remove), false);
  19. }
  20. return remove != null;
  21. }
  22. return false;
  23. }

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

  1. /**
  2. * Creates a persitent-to-disk store for the given cache, using the given disk path.
  3. *
  4. * @param cache cache that fronts this store
  5. * @param onHeapPool pool to track heap usage
  6. * @param onDiskPool pool to track disk usage
  7. * @return a fully initialized store
  8. */
  9. public static DiskStore create(Ehcache cache, Pool onHeapPool, Pool onDiskPool) {
  10. if (cache.getCacheManager() == null) {
  11. throw new CacheException("Can't create diskstore without a cache manager");
  12. }
  13. DiskStorageFactory disk = new DiskStorageFactory(cache, cache.getCacheEventNotificationService());
  14. DiskStore store = new DiskStore(disk, cache, onHeapPool, onDiskPool);
  15. cache.getCacheConfiguration().addConfigurationListener(new CacheConfigurationListenerAdapter(disk, onDiskPool));
  16. return store;
  17. }

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

  1. private DiskStore(DiskStorageFactory disk, Ehcache cache, Pool onHeapPool, Pool onDiskPool) {
  2. this.segments = new Segment[DEFAULT_SEGMENT_COUNT];
  3. this.segmentShift = Integer.numberOfLeadingZeros(segments.length - 1);
  4. EventRateSimpleMovingAverage hitRate = new EventRateSimpleMovingAverage(1, TimeUnit.SECONDS);
  5. EventRateSimpleMovingAverage missRate = new EventRateSimpleMovingAverage(1, TimeUnit.SECONDS);
  6. OperationStatistic<GetOutcome> getStatistic = StatisticsManager.getOperationStatisticFor(getObserver);
  7. getStatistic.addDerivedStatistic(new OperationResultFilter<GetOutcome>(EnumSet.of(GetOutcome.HIT), hitRate));
  8. getStatistic.addDerivedStatistic(new OperationResultFilter<GetOutcome>(EnumSet.of(GetOutcome.MISS), missRate));
  9. this.onHeapPoolAccessor = onHeapPool.createPoolAccessor(new DiskStoreHeapPoolParticipant(hitRate, missRate),
  10. SizeOfPolicyConfiguration.resolveMaxDepth(cache),
  11. SizeOfPolicyConfiguration.resolveBehavior(cache).equals(SizeOfPolicyConfiguration.MaxDepthExceededBehavior.ABORT));
  12. this.onDiskPoolAccessor = onDiskPool.createPoolAccessor(new DiskStoreDiskPoolParticipant(hitRate, missRate), new DiskSizeOfEngine());
  13. for (int i = 0; i < this.segments.length; ++i) {
  14. this.segments[i] = new Segment(DEFAULT_INITIAL_CAPACITY, DEFAULT_LOAD_FACTOR,
  15. disk, cache.getCacheConfiguration(), onHeapPoolAccessor, onDiskPoolAccessor,
  16. cache.getCacheEventNotificationService(), evictionObserver);
  17. }
  18. this.disk = disk;
  19. this.disk.bind(this);
  20. this.status.set(Status.STATUS_ALIVE);
  21. }

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

  1. private void processEventNotification(CacheEventNotificationMsg msg) {
  2. RegisteredEventListeners notificationService = ecache.getCacheEventNotificationService();
  3. switch (msg.getToolkitEventType()) {
  4. case ELEMENT_REMOVED:
  5. notificationService.notifyElementRemoved(msg.getElement(), true);
  6. break;
  7. case ELEMENT_PUT:
  8. notificationService.notifyElementPut(msg.getElement(), true);
  9. break;
  10. case ELEMENT_UPDATED:
  11. notificationService.notifyElementUpdated(msg.getElement(), true);
  12. break;
  13. case ELEMENT_EXPIRED:
  14. notificationService.notifyElementExpiry(msg.getElement(), true);
  15. break;
  16. case ELEMENT_EVICTED:
  17. notificationService.notifyElementEvicted(msg.getElement(), true);
  18. break;
  19. case REMOVEALL:
  20. notificationService.notifyRemoveAll(true);
  21. break;
  22. }
  23. }

相关文章

Ehcache类方法