|
36 | 36 | * Global notification service for document updates. Other classes
|
37 | 37 | * can subscribe to this service to be notified of document modifications,
|
38 | 38 | * removals or additions.
|
39 |
| - * |
40 |
| - * @author wolf |
41 | 39 | *
|
| 40 | + * @author wolf |
42 | 41 | */
|
43 | 42 | @ThreadSafe
|
44 | 43 | public class NotificationService implements BrokerPoolService {
|
45 | 44 |
|
46 |
| - private static final long serialVersionUID = -3629584664969740903L; |
47 |
| - private static final Logger LOG = LogManager.getLogger(NotificationService.class); |
| 45 | + private static final long serialVersionUID = -3629584664969740903L; |
| 46 | + private static final Logger LOG = LogManager.getLogger(NotificationService.class); |
48 | 47 |
|
49 |
| - private final Map<UpdateListener, Object> listeners = new IdentityHashMap<>(); |
50 |
| - |
51 |
| - public NotificationService() { |
52 |
| - super(); |
53 |
| - } |
54 |
| - |
55 |
| - /** |
56 |
| - * Subscribe an {@link UpdateListener} to receive notifications. |
57 |
| - * |
58 |
| - * @param listener |
59 |
| - */ |
60 |
| - public synchronized void subscribe(final UpdateListener listener) { |
61 |
| - listeners.put(listener, new Object()); |
62 |
| - } |
63 |
| - |
64 |
| - /** |
65 |
| - * Unsubscribe an {@link UpdateListener}. |
66 |
| - * |
67 |
| - * @param listener |
68 |
| - */ |
69 |
| - public synchronized void unsubscribe(final UpdateListener listener) { |
70 |
| - final Object i = listeners.remove(listener); |
71 |
| - if (i == null) { |
72 |
| - throw new RuntimeException(hashCode() + " listener not found: " + listener.hashCode()); |
73 |
| - } |
| 48 | + private final Map<UpdateListener, Object> listeners = new IdentityHashMap<>(); |
| 49 | + |
| 50 | + public NotificationService() { |
| 51 | + super(); |
| 52 | + } |
| 53 | + |
| 54 | + /** |
| 55 | + * Subscribe an {@link UpdateListener} to receive notifications. |
| 56 | + * |
| 57 | + * @param listener |
| 58 | + */ |
| 59 | + public synchronized void subscribe(final UpdateListener listener) { |
| 60 | + listeners.put(listener, new Object()); |
| 61 | + } |
| 62 | + |
| 63 | + /** |
| 64 | + * Unsubscribe an {@link UpdateListener}. |
| 65 | + * |
| 66 | + * @param listener |
| 67 | + */ |
| 68 | + public synchronized void unsubscribe(final UpdateListener listener) { |
| 69 | + final Object i = listeners.remove(listener); |
| 70 | + if (i == null) { |
| 71 | + throw new RuntimeException(hashCode() + " listener not found: " + listener.hashCode()); |
| 72 | + } |
74 | 73 | listener.unsubscribe();
|
75 | 74 | }
|
76 | 75 |
|
77 |
| - /** |
78 |
| - * Notify all subscribers that a document has been updated/removed or |
79 |
| - * a new document has been added. |
80 |
| - * |
81 |
| - * @param document |
82 |
| - * @param event |
83 |
| - */ |
84 |
| - public synchronized void notifyUpdate(final DocumentImpl document, final int event) { |
85 |
| - listeners.keySet().forEach(listener -> listener.documentUpdated(document, event)); |
86 |
| - } |
| 76 | + /** |
| 77 | + * Notify all subscribers that a document has been updated/removed or |
| 78 | + * a new document has been added. |
| 79 | + * |
| 80 | + * @param document |
| 81 | + * @param event |
| 82 | + */ |
| 83 | + public synchronized void notifyUpdate(final DocumentImpl document, final int event) { |
| 84 | + listeners.keySet().forEach(listener -> listener.documentUpdated(document, event)); |
| 85 | + } |
87 | 86 |
|
88 | 87 | /**
|
89 |
| - * Notify all subscribers that a node has been moved. Nodes may be moved during a |
| 88 | + * Notify all subscribers that a node has been moved. Nodes may be moved during a |
90 | 89 | * defragmentation run.
|
91 |
| - */ |
92 |
| - public synchronized void notifyMove(final NodeId oldNodeId, final IStoredNode newNode) { |
93 |
| - listeners.keySet().forEach(listener -> listener.nodeMoved(oldNodeId, newNode)); |
94 |
| - } |
| 90 | + */ |
| 91 | + public synchronized void notifyMove(final NodeId oldNodeId, final IStoredNode newNode) { |
| 92 | + listeners.keySet().forEach(listener -> listener.nodeMoved(oldNodeId, newNode)); |
| 93 | + } |
95 | 94 |
|
96 | 95 | public synchronized void debug() {
|
97 |
| - if (LOG.isDebugEnabled()) { |
98 |
| - LOG.debug("Registered UpdateListeners:"); |
99 |
| - } |
100 |
| - listeners.keySet().forEach(UpdateListener::debug); |
101 |
| - } |
| 96 | + if (LOG.isDebugEnabled()) { |
| 97 | + LOG.debug("Registered UpdateListeners:"); |
| 98 | + } |
| 99 | + listeners.keySet().forEach(UpdateListener::debug); |
| 100 | + } |
102 | 101 | }
|
0 commit comments