1 package com.atlassian.cache.impl;
2
3 import com.atlassian.cache.CachedReferenceListener;
4
5 import java.util.Set;
6 import java.util.concurrent.CopyOnWriteArraySet;
7
8 import static com.google.common.base.Preconditions.checkNotNull;
9
10
11
12
13
14
15
16
17 public class DefaultCachedReferenceListenerSupport<V> implements CachedReferenceListenerSupport<V>
18 {
19 private final Set<CachedReferenceListener<V>> listeners = new CopyOnWriteArraySet<CachedReferenceListener<V>>();
20 private final CachedReferenceNotificationSupport notificationSupport =
21 CachedReferenceNotificationSupport.getInstance();
22
23 @Override
24 public void add(CachedReferenceListener<V> listener, boolean includeValues)
25 {
26 listeners.add(checkNotNull(listener));
27 }
28
29 @Override
30 public void remove(CachedReferenceListener<V> listener)
31 {
32 listeners.remove(checkNotNull(listener));
33 }
34
35 @Override
36 public void notifyEvict(V oldValue)
37 {
38 notificationSupport.notifyEvict(listeners, new DefaultCachedReferenceEvent<V>(oldValue));
39 }
40
41 @Override
42 public void notifySet(V value)
43 {
44 notificationSupport.notifySet(listeners, new DefaultCachedReferenceEvent<V>(value));
45 }
46
47 @Override
48 public void notifyReset(V oldValue)
49 {
50 notificationSupport.notifyReset(listeners, new DefaultCachedReferenceEvent<V>(oldValue));
51 }
52 }