Clover coverage report - Coverage timestamp: Sa Jul 7 2007 09:11:40 CEST FRAMES NO FRAMES |
file stats: | LOC: | 177 |  | Methods: | 15
| NCLOC: | 93 |  | Classes: | 1
Source file | Conditionals | Statements | Methods | TOTAL
AbstractBroadcastingListener.java | 0% | 0% | 0% | 0% |

1 |  | /*
2 |  | * Copyright (c) 2002-2003 by OpenSymphony
3 |  | * All rights reserved.
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 |  | * Implementation of a CacheEntryEventListener. It broadcasts the flush events
17 |  | * across a cluster to other listening caches. Note that this listener cannot
18 |  | * be used in conjection with session caches.
19 |  | *
20 |  | * @version $Revision: 254 $
21 |  | * @author <a href="&#109;a&#105;&#108;&#116;&#111;:chris&#64;swebtec.&#99;&#111;&#109;">Chris Miller</a>
22 |  | */
23 |  | public abstract class AbstractBroadcastingListener implements CacheEntryEventListener, LifecycleAware {
24 |  | private final static Log log = LogFactory.getLog(AbstractBroadcastingListener.class);
25 |  |
26 |  | /**
27 |  | * The name to use for the origin of cluster events. Using this ensures
28 |  | * events are not fired recursively back over the cluster.
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 |  | * Event fired when an entry is flushed from the cache. This broadcasts
41 |  | * the flush message to any listening nodes on the network.
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 |  | * Event fired when an entry is removed from the cache. This broadcasts
55 |  | * the remove method to any listening nodes on the network, as long as
56 |  | * this event wasn't from a broadcast in the first place.
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 |  | // The remaining events are of no interest to this listener
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 |  | * Called by the cache administrator class when a cache is instantiated.
117 |  | *
118 |  | * @param cache the cache instance that this listener is attached to.
119 |  | * @param config The cache's configuration details. This allows the event handler
120 |  | * to initialize itself based on the cache settings, and also to receive <em>additional</em>
121 |  | * settings that were part of the cache configuration but that the cache
122 |  | * itself does not care about. If you are using <code>cache.properties</code>
123 |  | * for your configuration, simply add any additional properties that your event
124 |  | * handler requires and they will be passed through in this parameter.
125 |  | *
126 |  | * @throws InitializationException thrown when there was a problem initializing the
127 |  | * listener. The cache administrator will log this error and disable the listener.
128 |  | */
129 | 0 | public void initialize(Cache cache, Config config) throws InitializationException {
130 | 0 | this.cache = cache;
131 |  | }
132 |  |
133 |  | /**
134 |  | * Handles incoming notification messages. This method should be called by the
135 |  | * underlying broadcasting implementation when a message is received from another
136 |  | * node in the cluster.
137 |  | *
138 |  | * @param message The incoming cluster notification message object.
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 |  | * Called when a cluster notification message is to be broadcast. Implementing
171 |  | * classes should use their underlying transport to broadcast the message across
172 |  | * the cluster.
173 |  | *
174 |  | * @param message The notification message to broadcast.
175 |  | */
176 |  | abstract protected void sendNotification(ClusterNotification message);
177 |  | }