1 /**
2 * Copyright Terracotta, Inc.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 package net.sf.ehcache.event;
18
19 /**
20 * This enumeration defines valid values for event listener notification scope.
21 * By default an event listener will be open to listening for events created
22 * on all nodes (ALL). You may also specify to receive only LOCAL events or only
23 * REMOTE events.
24 *
25 * @author Geert Bevin
26 * @since 2.0
27 */
28 public enum NotificationScope {
29 /**
30 * Receive only events generated by this CacheManager
31 */
32 LOCAL(true, false),
33
34 /**
35 * Receive only events generated by another CacheManager
36 */
37 REMOTE(false, true),
38
39 /**
40 * Receive all events
41 */
42 ALL(true, true);
43
44
45 private final boolean deliverLocal;
46 private final boolean deliverRemote;
47
48 private NotificationScope(boolean deliverLocal, boolean deliverRemote) {
49 this.deliverLocal = deliverLocal;
50 this.deliverRemote = deliverRemote;
51 }
52
53 /**
54 * Determine whether an event should be delivered under this notification scope.
55 *
56 * @param isRemote Whether the event is local or remote
57 * @return True if the event should be delivered to a listener with this notification scope
58 */
59 public boolean shouldDeliver(boolean isRemote) {
60 return (isRemote && deliverRemote) || (!isRemote && deliverLocal);
61 }
62
63 }
64