shuber 2004/08/20 20:06:56 CEST
Modified files: (Branch: JAHIA-4-0-BRANCH)
src/java/org/jahia/services/cache Cache.java
JMSHubConsumer.java
Log:
Adding beginning of system environment management.
Revision Changes Path
1.30.2.6 +15 -11 jahia/src/java/org/jahia/services/cache/Cache.java
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/jahia/src/java/org/jahia/services/cache/Cache.java.diff?r1=1.30.2.5&r2=1.30.2.6&f=h
1.8.4.6 +11 -13 jahia/src/java/org/jahia/services/cache/JMSHubConsumer.java
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/jahia/src/java/org/jahia/services/cache/JMSHubConsumer.java.diff?r1=1.8.4.5&r2=1.8.4.6&f=h
Index: Cache.java
===================================================================
RCS file:
/home/cvs/repository/jahia/src/java/org/jahia/services/cache/Attic/Cache.java,v
retrieving revision 1.30.2.5
retrieving revision 1.30.2.6
diff -u -r1.30.2.5 -r1.30.2.6
--- Cache.java 20 Aug 2004 17:14:48 -0000 1.30.2.5
+++ Cache.java 20 Aug 2004 18:06:56 -0000 1.30.2.6
@@ -275,7 +275,7 @@
* Set it to false it you want to update the cache ONLY locally, for example
* when implementing a cache listener method.
*/
- public synchronized void putCacheEntry (Object entryKey, CacheEntry entry,
boolean propagate) {
+ public void putCacheEntry (Object entryKey, CacheEntry entry, boolean
propagate) {
internalPut(entryKey, entry);
@@ -286,7 +286,7 @@
}
}
- private boolean internalPut (Object entryKey, CacheEntry entry) {
+ private synchronized boolean internalPut (Object entryKey, CacheEntry entry) {
if ((entryKey == null) || (entry == null)) {
logger.debug ("null cache entry key or entry object, cannot cache such
an object!");
return false;
@@ -358,7 +358,7 @@
*
* @param entryKey the cache entry key, <code>null</code> is not allowed
*/
- public synchronized void remove (Object entryKey) {
+ public void remove (Object entryKey) {
internalRemove (entryKey);
// Create the removal message if needed
@@ -415,14 +415,16 @@
/** <p>Flushs all the cache entries. When <code>sendToListeners</code> is
* <code>true</code>, the event is send to the cache's listeners.</p>
*/
- public synchronized void flush(boolean propagate) {
+ public void flush(boolean propagate) {
- // clears the cache
- cache.clear();
-
- // reset the cache statistics
- successHitCount = 0;
- totalHitCount = 0;
+ synchronized (this) {
+ // clears the cache
+ cache.clear();
+
+ // reset the cache statistics
+ successHitCount = 0;
+ totalHitCount = 0;
+ }
logger.debug("Flushed all entries from cache [" + name + "]");
@@ -605,7 +607,9 @@
return;
// remove the object from the cache
- cache.remove (entryKey);
+ synchronized (this) {
+ cache.remove(entryKey);
+ }
logger.debug ("Removed the entry [" + entryKey.toString () +
"] from cache [" + name + "]!");
}
Index: JMSHubConsumer.java
===================================================================
RCS file:
/home/cvs/repository/jahia/src/java/org/jahia/services/cache/Attic/JMSHubConsumer.java,v
retrieving revision 1.8.4.5
retrieving revision 1.8.4.6
diff -u -r1.8.4.5 -r1.8.4.6
--- JMSHubConsumer.java 13 Aug 2004 17:03:01 -0000 1.8.4.5
+++ JMSHubConsumer.java 20 Aug 2004 18:06:56 -0000 1.8.4.6
@@ -68,14 +68,12 @@
/** references to the caches. */
private Hashtable caches;
+ private String hubClientID;
+ private CacheFactory cacheFactory;
+
/** the consumer connection to the server. */
private TopicSubscriber topicSubscriber;
- /** the reference to the <code>JMSHub</code>. */
- private JMSHub jmsHub;
-
-
-
/** Default constructor, creates a new <code>JMSHubConsumer</code> instance.*/
public JMSHubConsumer () {
// instanciate the caches hashtable
@@ -103,18 +101,19 @@
"Cannot initialize the JMS Message Consumer with a null JMSHub
instance!");
}
- // keep track of the hub reference
- jmsHub = hub;
+ cacheFactory = hub.getCacheFactory();
// Initialize the subscription to the related topic
try {
+ hubClientID = hub.getTopicConnection().getClientID();
+
// get the subscriber instance from the session
- topicSubscriber = jmsHub.getTopicSession().createSubscriber (
- jmsHub.getTopic(), null, false);
+ topicSubscriber = hub.getTopicSession().createSubscriber (
+ hub.getTopic(), null, false);
if (topicSubscriber != null) {
topicSubscriber.setMessageListener (this);
logger.debug ("JMS Hub successfully set as a listenenr on topic ["+
- jmsHub.getTopic().toString() +"]");
+ hub.getTopic().toString() +"]");
} else {
throw new JahiaInitializationException(
@@ -153,7 +152,7 @@
// check if the received message was not been sent by this client
String clientID = msg.getString (JMSCacheMessage.CLIENT_KEY);
if (clientID != null) {
- if (clientID.equals (jmsHub.getTopicConnection().getClientID())) {
+ if (clientID.equals (hubClientID)) {
logger.debug("ignoring message, cyclic message!");
return;
}
@@ -273,7 +272,7 @@
logger.debug("Cache ["+ cacheName +"] is not registered in the JMS Hub.
Try to register it");
// Retrieve the cache from the Cache Factory
- cache = jmsHub.getCacheFactory().getCache (cacheName);
+ cache = cacheFactory.getCache (cacheName);
if (cache != null) {
caches.put (cache.getName(), cache);
@@ -320,7 +319,6 @@
} finally {
// let's kill definitively the beast
topicSubscriber = null;
- jmsHub = null;
}
}
}