|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| package com.opensymphony.oscache.plugins.clustersupport; |
|
6 |
| |
|
7 |
| import com.opensymphony.oscache.base.*; |
|
8 |
| import com.opensymphony.oscache.base.events.*; |
|
9 |
| |
|
10 |
| import org.apache.commons.logging.Log; |
|
11 |
| import org.apache.commons.logging.LogFactory; |
|
12 |
| |
|
13 |
| import java.util.Date; |
|
14 |
| |
|
15 |
| |
|
16 |
| |
|
17 |
| |
|
18 |
| |
|
19 |
| |
|
20 |
| |
|
21 |
| |
|
22 |
| |
|
23 |
| public abstract class AbstractBroadcastingListener implements CacheEntryEventListener, LifecycleAware { |
|
24 |
| private final static Log log = LogFactory.getLog(AbstractBroadcastingListener.class); |
|
25 |
| |
|
26 |
| |
|
27 |
| |
|
28 |
| |
|
29 |
| |
|
30 |
| protected static final String CLUSTER_ORIGIN = "CLUSTER"; |
|
31 |
| protected Cache cache = null; |
|
32 |
| |
|
33 |
0
| public AbstractBroadcastingListener() {
|
|
34 |
0
| if (log.isInfoEnabled()) {
|
|
35 |
0
| log.info("AbstractBroadcastingListener registered");
|
|
36 |
| } |
|
37 |
| } |
|
38 |
| |
|
39 |
| |
|
40 |
| |
|
41 |
| |
|
42 |
| |
|
43 |
0
| public void cacheEntryFlushed(CacheEntryEvent event) {
|
|
44 |
0
| if (!Cache.NESTED_EVENT.equals(event.getOrigin()) && !CLUSTER_ORIGIN.equals(event.getOrigin())) {
|
|
45 |
0
| if (log.isDebugEnabled()) {
|
|
46 |
0
| log.debug("cacheEntryFlushed called (" + event + ")");
|
|
47 |
| } |
|
48 |
| |
|
49 |
0
| sendNotification(new ClusterNotification(ClusterNotification.FLUSH_KEY, event.getKey()));
|
|
50 |
| } |
|
51 |
| } |
|
52 |
| |
|
53 |
| |
|
54 |
| |
|
55 |
| |
|
56 |
| |
|
57 |
| |
|
58 |
0
| public void cacheGroupFlushed(CacheGroupEvent event) {
|
|
59 |
0
| if (!Cache.NESTED_EVENT.equals(event.getOrigin()) && !CLUSTER_ORIGIN.equals(event.getOrigin())) {
|
|
60 |
0
| if (log.isDebugEnabled()) {
|
|
61 |
0
| log.debug("cacheGroupFushed called (" + event + ")");
|
|
62 |
| } |
|
63 |
| |
|
64 |
0
| sendNotification(new ClusterNotification(ClusterNotification.FLUSH_GROUP, event.getGroup()));
|
|
65 |
| } |
|
66 |
| } |
|
67 |
| |
|
68 |
0
| public void cachePatternFlushed(CachePatternEvent event) {
|
|
69 |
0
| if (!Cache.NESTED_EVENT.equals(event.getOrigin()) && !CLUSTER_ORIGIN.equals(event.getOrigin())) {
|
|
70 |
0
| if (log.isDebugEnabled()) {
|
|
71 |
0
| log.debug("cachePatternFushed called (" + event + ")");
|
|
72 |
| } |
|
73 |
| |
|
74 |
0
| sendNotification(new ClusterNotification(ClusterNotification.FLUSH_PATTERN, event.getPattern()));
|
|
75 |
| } |
|
76 |
| } |
|
77 |
| |
|
78 |
0
| public void cacheFlushed(CachewideEvent event) {
|
|
79 |
0
| if (!Cache.NESTED_EVENT.equals(event.getOrigin()) && !CLUSTER_ORIGIN.equals(event.getOrigin())) {
|
|
80 |
0
| if (log.isDebugEnabled()) {
|
|
81 |
0
| log.debug("cacheFushed called (" + event + ")");
|
|
82 |
| } |
|
83 |
| |
|
84 |
0
| sendNotification(new ClusterNotification(ClusterNotification.FLUSH_CACHE, event.getDate()));
|
|
85 |
| } |
|
86 |
| } |
|
87 |
| |
|
88 |
| |
|
89 |
| |
|
90 |
| |
|
91 |
0
| public void cacheEntryAdded(CacheEntryEvent event) {
|
|
92 |
| } |
|
93 |
| |
|
94 |
0
| public void cacheEntryRemoved(CacheEntryEvent event) {
|
|
95 |
| } |
|
96 |
| |
|
97 |
0
| public void cacheEntryUpdated(CacheEntryEvent event) {
|
|
98 |
| } |
|
99 |
| |
|
100 |
0
| public void cacheGroupAdded(CacheGroupEvent event) {
|
|
101 |
| } |
|
102 |
| |
|
103 |
0
| public void cacheGroupEntryAdded(CacheGroupEvent event) {
|
|
104 |
| } |
|
105 |
| |
|
106 |
0
| public void cacheGroupEntryRemoved(CacheGroupEvent event) {
|
|
107 |
| } |
|
108 |
| |
|
109 |
0
| public void cacheGroupRemoved(CacheGroupEvent event) {
|
|
110 |
| } |
|
111 |
| |
|
112 |
0
| public void cacheGroupUpdated(CacheGroupEvent event) {
|
|
113 |
| } |
|
114 |
| |
|
115 |
| |
|
116 |
| |
|
117 |
| |
|
118 |
| |
|
119 |
| |
|
120 |
| |
|
121 |
| |
|
122 |
| |
|
123 |
| |
|
124 |
| |
|
125 |
| |
|
126 |
| |
|
127 |
| |
|
128 |
| |
|
129 |
0
| public void initialize(Cache cache, Config config) throws InitializationException {
|
|
130 |
0
| this.cache = cache;
|
|
131 |
| } |
|
132 |
| |
|
133 |
| |
|
134 |
| |
|
135 |
| |
|
136 |
| |
|
137 |
| |
|
138 |
| |
|
139 |
| |
|
140 |
0
| public void handleClusterNotification(ClusterNotification message) {
|
|
141 |
0
| if (cache == null) {
|
|
142 |
0
| log.warn("A cluster notification (" + message + ") was received, but no cache is registered on this machine. Notification ignored.");
|
|
143 |
| |
|
144 |
0
| return;
|
|
145 |
| } |
|
146 |
| |
|
147 |
0
| if (log.isInfoEnabled()) {
|
|
148 |
0
| log.info("Cluster notification (" + message + ") was received.");
|
|
149 |
| } |
|
150 |
| |
|
151 |
0
| switch (message.getType()) {
|
|
152 |
0
| case ClusterNotification.FLUSH_KEY:
|
|
153 |
0
| cache.flushEntry((String) message.getData(), CLUSTER_ORIGIN);
|
|
154 |
0
| break;
|
|
155 |
0
| case ClusterNotification.FLUSH_GROUP:
|
|
156 |
0
| cache.flushGroup((String) message.getData(), CLUSTER_ORIGIN);
|
|
157 |
0
| break;
|
|
158 |
0
| case ClusterNotification.FLUSH_PATTERN:
|
|
159 |
0
| cache.flushPattern((String) message.getData(), CLUSTER_ORIGIN);
|
|
160 |
0
| break;
|
|
161 |
0
| case ClusterNotification.FLUSH_CACHE:
|
|
162 |
0
| cache.flushAll((Date) message.getData(), CLUSTER_ORIGIN);
|
|
163 |
0
| break;
|
|
164 |
0
| default:
|
|
165 |
0
| log.error("The cluster notification (" + message + ") is of an unknown type. Notification ignored.");
|
|
166 |
| } |
|
167 |
| } |
|
168 |
| |
|
169 |
| |
|
170 |
| |
|
171 |
| |
|
172 |
| |
|
173 |
| |
|
174 |
| |
|
175 |
| |
|
176 |
| abstract protected void sendNotification(ClusterNotification message); |
|
177 |
| } |