Source Code Cross Referenced for AbstractBroadcastingListener.java in  » Cache » OSCache » com » opensymphony » oscache » plugins » clustersupport » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / C Sharp
C# / CSharp Tutorial
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Cache » OSCache » com.opensymphony.oscache.plugins.clustersupport 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright (c) 2002-2003 by OpenSymphony
003:         * All rights reserved.
004:         */
005:        package com.opensymphony.oscache.plugins.clustersupport;
006:
007:        import com.opensymphony.oscache.base.*;
008:        import com.opensymphony.oscache.base.events.*;
009:
010:        import org.apache.commons.logging.Log;
011:        import org.apache.commons.logging.LogFactory;
012:
013:        import java.util.Date;
014:
015:        /**
016:         * Implementation of a CacheEntryEventListener. It broadcasts the flush events
017:         * across a cluster to other listening caches. Note that this listener cannot
018:         * be used in conjection with session caches.
019:         *
020:         * @version        $Revision: 254 $
021:         * @author <a href="&#109;a&#105;&#108;&#116;&#111;:chris&#64;swebtec.&#99;&#111;&#109;">Chris Miller</a>
022:         */
023:        public abstract class AbstractBroadcastingListener implements 
024:                CacheEntryEventListener, LifecycleAware {
025:            private final static Log log = LogFactory
026:                    .getLog(AbstractBroadcastingListener.class);
027:
028:            /**
029:             * The name to use for the origin of cluster events. Using this ensures
030:             * events are not fired recursively back over the cluster.
031:             */
032:            protected static final String CLUSTER_ORIGIN = "CLUSTER";
033:            protected Cache cache = null;
034:
035:            public AbstractBroadcastingListener() {
036:                if (log.isInfoEnabled()) {
037:                    log.info("AbstractBroadcastingListener registered");
038:                }
039:            }
040:
041:            /**
042:             * Event fired when an entry is flushed from the cache. This broadcasts
043:             * the flush message to any listening nodes on the network.
044:             */
045:            public void cacheEntryFlushed(CacheEntryEvent event) {
046:                if (!Cache.NESTED_EVENT.equals(event.getOrigin())
047:                        && !CLUSTER_ORIGIN.equals(event.getOrigin())) {
048:                    if (log.isDebugEnabled()) {
049:                        log.debug("cacheEntryFlushed called (" + event + ")");
050:                    }
051:
052:                    sendNotification(new ClusterNotification(
053:                            ClusterNotification.FLUSH_KEY, event.getKey()));
054:                }
055:            }
056:
057:            /**
058:             * Event fired when an entry is removed from the cache. This broadcasts
059:             * the remove method to any listening nodes on the network, as long as
060:             * this event wasn't from a broadcast in the first place.
061:             */
062:            public void cacheGroupFlushed(CacheGroupEvent event) {
063:                if (!Cache.NESTED_EVENT.equals(event.getOrigin())
064:                        && !CLUSTER_ORIGIN.equals(event.getOrigin())) {
065:                    if (log.isDebugEnabled()) {
066:                        log.debug("cacheGroupFushed called (" + event + ")");
067:                    }
068:
069:                    sendNotification(new ClusterNotification(
070:                            ClusterNotification.FLUSH_GROUP, event.getGroup()));
071:                }
072:            }
073:
074:            public void cachePatternFlushed(CachePatternEvent event) {
075:                if (!Cache.NESTED_EVENT.equals(event.getOrigin())
076:                        && !CLUSTER_ORIGIN.equals(event.getOrigin())) {
077:                    if (log.isDebugEnabled()) {
078:                        log.debug("cachePatternFushed called (" + event + ")");
079:                    }
080:
081:                    sendNotification(new ClusterNotification(
082:                            ClusterNotification.FLUSH_PATTERN, event
083:                                    .getPattern()));
084:                }
085:            }
086:
087:            public void cacheFlushed(CachewideEvent event) {
088:                if (!Cache.NESTED_EVENT.equals(event.getOrigin())
089:                        && !CLUSTER_ORIGIN.equals(event.getOrigin())) {
090:                    if (log.isDebugEnabled()) {
091:                        log.debug("cacheFushed called (" + event + ")");
092:                    }
093:
094:                    sendNotification(new ClusterNotification(
095:                            ClusterNotification.FLUSH_CACHE, event.getDate()));
096:                }
097:            }
098:
099:            // --------------------------------------------------------
100:            // The remaining events are of no interest to this listener
101:            // --------------------------------------------------------
102:            public void cacheEntryAdded(CacheEntryEvent event) {
103:            }
104:
105:            public void cacheEntryRemoved(CacheEntryEvent event) {
106:            }
107:
108:            public void cacheEntryUpdated(CacheEntryEvent event) {
109:            }
110:
111:            public void cacheGroupAdded(CacheGroupEvent event) {
112:            }
113:
114:            public void cacheGroupEntryAdded(CacheGroupEvent event) {
115:            }
116:
117:            public void cacheGroupEntryRemoved(CacheGroupEvent event) {
118:            }
119:
120:            public void cacheGroupRemoved(CacheGroupEvent event) {
121:            }
122:
123:            public void cacheGroupUpdated(CacheGroupEvent event) {
124:            }
125:
126:            /**
127:             * Called by the cache administrator class when a cache is instantiated.
128:             *
129:             * @param cache the cache instance that this listener is attached to.
130:             * @param config The cache's configuration details. This allows the event handler
131:             * to initialize itself based on the cache settings, and also to receive <em>additional</em>
132:             * settings that were part of the cache configuration but that the cache
133:             * itself does not care about. If you are using <code>cache.properties</code>
134:             * for your configuration, simply add any additional properties that your event
135:             * handler requires and they will be passed through in this parameter.
136:             *
137:             * @throws InitializationException thrown when there was a problem initializing the
138:             * listener. The cache administrator will log this error and disable the listener.
139:             */
140:            public void initialize(Cache cache, Config config)
141:                    throws InitializationException {
142:                this .cache = cache;
143:            }
144:
145:            /**
146:             * Handles incoming notification messages. This method should be called by the
147:             * underlying broadcasting implementation when a message is received from another
148:             * node in the cluster.
149:             *
150:             * @param message The incoming cluster notification message object.
151:             */
152:            public void handleClusterNotification(ClusterNotification message) {
153:                if (cache == null) {
154:                    log
155:                            .warn("A cluster notification ("
156:                                    + message
157:                                    + ") was received, but no cache is registered on this machine. Notification ignored.");
158:
159:                    return;
160:                }
161:
162:                if (log.isInfoEnabled()) {
163:                    log.info("Cluster notification (" + message
164:                            + ") was received.");
165:                }
166:
167:                switch (message.getType()) {
168:                case ClusterNotification.FLUSH_KEY:
169:                    cache
170:                            .flushEntry((String) message.getData(),
171:                                    CLUSTER_ORIGIN);
172:                    break;
173:                case ClusterNotification.FLUSH_GROUP:
174:                    cache
175:                            .flushGroup((String) message.getData(),
176:                                    CLUSTER_ORIGIN);
177:                    break;
178:                case ClusterNotification.FLUSH_PATTERN:
179:                    cache.flushPattern((String) message.getData(),
180:                            CLUSTER_ORIGIN);
181:                    break;
182:                case ClusterNotification.FLUSH_CACHE:
183:                    cache.flushAll((Date) message.getData(), CLUSTER_ORIGIN);
184:                    break;
185:                default:
186:                    log.error("The cluster notification (" + message
187:                            + ") is of an unknown type. Notification ignored.");
188:                }
189:            }
190:
191:            /**
192:             * Called when a cluster notification message is to be broadcast. Implementing
193:             * classes should use their underlying transport to broadcast the message across
194:             * the cluster.
195:             *
196:             * @param message The notification message to broadcast.
197:             */
198:            abstract protected void sendNotification(ClusterNotification message);
199:        }
www.java2java.com | Contact Us
Copyright 2010 - 2030 Java Source and Support. All rights reserved.
All other trademarks are property of their respective owners.