@SuppressWarnings("ClassEscapesDefinedScope") @Override protected EhCacheAdapter.CacheEventListenerAdapter createListenerAdapter(EntryListener cacheEntryListener) { return new EhCacheAdapter.CacheEventListenerAdapter(ehCache, cacheEntryListener); }
@Override protected CacheEntryListenerConfiguration createListenerAdapter(EntryListener cacheEntryListener) { return new JCacheListenerAdapter(cacheEntryListener); }
@Override public <K, V> boolean putIfAbsent(K key, V value) { if (value == null) { throw new IllegalArgumentException("Null values not supported"); } purgeItems(); if (cache.putIfAbsent(key, new Entry(key, value)) == null) { for (EntryListener adapter : adapters) { adapter.onEntryCreated(key, value); } return true; } return false; }
@Override public <K, V> void put(K key, V value) { if (value == null) { throw new IllegalArgumentException("Null values not supported"); } purgeItems(); if (cache.put(key, new Entry(key, value)) != null) { for (EntryListener adapter : adapters) { adapter.onEntryUpdated(key, value); } } else { for (EntryListener adapter : adapters) { adapter.onEntryCreated(key, value); } } }
private void removeAssociationValueFromCache(Class<?> sagaType, String sagaIdentifier, AssociationValue associationValue) { String key = cacheKey(associationValue, sagaType); Set<String> associations = associationsCache.get(key); if (associations != null && associations.remove(sagaIdentifier)) { associationsCache.put(key, associations); } }
private void purgeItems() { Entry purgedEntry; while ((purgedEntry = (Entry) referenceQueue.poll()) != null) { if (cache.remove(purgedEntry.getKey()) != null) { for (EntryListener adapter : adapters) { adapter.onEntryExpired(purgedEntry.getKey()); } } } }
@Override @SuppressWarnings("unchecked") public <K, V> V get(K key) { purgeItems(); final Reference<Object> entry = cache.get(key); final V returnValue = entry == null ? null : (V) entry.get(); if (returnValue != null) { for (EntryListener adapter : adapters) { adapter.onEntryRead(key, returnValue); } } return returnValue; }
private void removeEntry(String aggregateIdentifier) { for (DisruptorRepository repository : repositories.values()) { repository.removeFromCache(aggregateIdentifier); } cache.remove(aggregateIdentifier); }
@Override public <K> boolean remove(K key) { if (cache.remove(key) != null) { for (EntryListener adapter : adapters) { adapter.onEntryRemoved(key); } return true; } return false; }
@Override public void onExpired(Iterable<CacheEntryEvent<? extends K, ? extends V>> iterable) throws CacheEntryListenerException { for (CacheEntryEvent event : iterable) { delegate.onEntryExpired(event.getKey()); } }
@Override public void notifyElementUpdated(Ehcache cache, Element element) throws CacheException { if (cache.equals(ehCache)) { delegate.onEntryUpdated(element.getObjectKey(), element.getObjectValue()); } }
@Override public void notifyElementPut(Ehcache cache, Element element) throws CacheException { if (cache.equals(ehCache)) { delegate.onEntryCreated(element.getObjectKey(), element.getObjectValue()); } }
@Override public <K> boolean containsKey(K key) { purgeItems(); final Reference<Object> entry = cache.get(key); return entry != null && entry.get() != null; }
@Override public CacheEventListenerAdapter clone() throws CloneNotSupportedException { CacheEventListenerAdapter clone = (CacheEventListenerAdapter) super.clone(); clone.ehCache = (Ehcache) ehCache.clone(); clone.delegate = (EntryListener) delegate.clone(); return clone; } }
@Override public void onRemoved(Iterable<CacheEntryEvent<? extends K, ? extends V>> iterable) throws CacheEntryListenerException { for (CacheEntryEvent event : iterable) { delegate.onEntryRemoved(event.getKey()); } }
@Override public void notifyElementEvicted(Ehcache cache, Element element) { if (cache.equals(ehCache)) { delegate.onEntryExpired(element.getObjectKey()); } }
@Override public void onUpdated(Iterable<CacheEntryEvent<? extends K, ? extends V>> iterable) throws CacheEntryListenerException { for (CacheEntryEvent event : iterable) { delegate.onEntryUpdated(event.getKey(), event.getValue()); } }
@Override public void onCreated(Iterable<CacheEntryEvent<? extends K, ? extends V>> cacheEntryEvents) throws CacheEntryListenerException { for (CacheEntryEvent event : cacheEntryEvents) { delegate.onEntryCreated(event.getKey(), event.getValue()); } }
@Override public void notifyElementRemoved(Ehcache cache, Element element) throws CacheException { if (cache.equals(ehCache)) { delegate.onEntryRemoved(element.getObjectKey()); } }
@Override public void notifyElementExpired(Ehcache cache, Element element) { if (cache.equals(ehCache)) { delegate.onEntryExpired(element.getObjectKey()); } }