Author: chris.laprun(a)jboss.com
Date: 2011-10-21 07:23:26 -0400 (Fri, 21 Oct 2011)
New Revision: 7820
Modified:
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/registry/AbstractConsumerRegistry.java
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/registry/ConsumerCache.java
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/spi/ConsumerRegistrySPI.java
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/test/support/MockConsumerRegistry.java
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/consumer/registry/JCRConsumerRegistry.java
Log:
- InMemoryConsumerCache should now properly check if a ProducerInfo needs to be updated
from persistence before being returned.
- Added markAsModifiedNow method on ConsumerCache.
Modified:
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/registry/AbstractConsumerRegistry.java
===================================================================
---
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/registry/AbstractConsumerRegistry.java 2011-10-21
11:00:18 UTC (rev 7819)
+++
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/registry/AbstractConsumerRegistry.java 2011-10-21
11:23:26 UTC (rev 7820)
@@ -252,6 +252,11 @@
startOrStopConsumer(consumer, false, true);
}
+ public long getPersistedLastModifiedForProducerInfoWith(String id)
+ {
+ return loadProducerInfo(id).getLastModified();
+ }
+
public synchronized String updateProducerInfo(ProducerInfo producerInfo)
{
ParameterValidation.throwIllegalArgExceptionIfNull(producerInfo,
"ProducerInfo");
@@ -275,6 +280,8 @@
consumers.putConsumer(producerInfo.getId(), consumer);
}
+ consumers.markAsModifiedNow();
+
return oldId;
}
@@ -519,10 +526,15 @@
ProducerInfo info = infosFromStorage.next();
consumers.put(info.getId(), createAndActivateIfNeeded(info));
}
- lastModified = System.currentTimeMillis();
+ markAsModifiedNow();
setInvalidated(false);
}
+ public void markAsModifiedNow()
+ {
+ lastModified = System.currentTimeMillis();
+ }
+
public Collection<WSRPConsumer> getConsumers()
{
refreshIfNeeded();
@@ -534,8 +546,8 @@
// try cache first
WSRPConsumer consumer = consumers.get(id);
- // if we didn't find the consumer in cache, try to load it from JCR
- if (consumer == null)
+ // if consumer is not in cache or has been modified after the cache was last
updated, load it from JCR
+ if (consumer == null || lastModified <
getPersistedLastModifiedForProducerInfoWith(id))
{
ProducerInfo info = loadProducerInfo(id);
if (info != null)
@@ -548,21 +560,21 @@
public WSRPConsumer removeConsumer(String id)
{
- lastModified = System.currentTimeMillis();
+ markAsModifiedNow();
return consumers.remove(id);
}
public void putConsumer(String id, WSRPConsumer consumer)
{
consumers.put(id, consumer);
- lastModified = System.currentTimeMillis();
+ markAsModifiedNow();
}
public void clear()
{
consumers.clear();
invalidated = true;
- lastModified = System.currentTimeMillis();
+ markAsModifiedNow();
}
public boolean isInvalidated()
@@ -600,7 +612,7 @@
}
}
- lastModified = System.currentTimeMillis();
+ markAsModifiedNow();
setInvalidated(false);
}
Modified:
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/registry/ConsumerCache.java
===================================================================
---
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/registry/ConsumerCache.java 2011-10-21
11:00:18 UTC (rev 7819)
+++
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/registry/ConsumerCache.java 2011-10-21
11:23:26 UTC (rev 7820)
@@ -47,4 +47,6 @@
long getLastModified();
void initFromStorage();
+
+ void markAsModifiedNow();
}
Modified:
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/spi/ConsumerRegistrySPI.java
===================================================================
---
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/spi/ConsumerRegistrySPI.java 2011-10-21
11:00:18 UTC (rev 7819)
+++
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/spi/ConsumerRegistrySPI.java 2011-10-21
11:23:26 UTC (rev 7820)
@@ -74,4 +74,6 @@
void registerWithFederatingPortletInvoker(WSRPConsumer consumer);
void deregisterWithFederatingPortletInvoker(WSRPConsumer consumer);
+
+ long getPersistedLastModifiedForProducerInfoWith(String id);
}
Modified:
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/test/support/MockConsumerRegistry.java
===================================================================
---
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/test/support/MockConsumerRegistry.java 2011-10-21
11:00:18 UTC (rev 7819)
+++
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/test/support/MockConsumerRegistry.java 2011-10-21
11:23:26 UTC (rev 7820)
@@ -234,4 +234,9 @@
{
consumers.remove(consumer.getProducerId());
}
+
+ public long getPersistedLastModifiedForProducerInfoWith(String id)
+ {
+ return System.currentTimeMillis();
+ }
}
Modified:
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/consumer/registry/JCRConsumerRegistry.java
===================================================================
---
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/consumer/registry/JCRConsumerRegistry.java 2011-10-21
11:00:18 UTC (rev 7819)
+++
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/consumer/registry/JCRConsumerRegistry.java 2011-10-21
11:23:26 UTC (rev 7820)
@@ -236,7 +236,28 @@
{
persister.closeSession(false);
}
+ }
+ @Override
+ public long getPersistedLastModifiedForProducerInfoWith(String id)
+ {
+ try
+ {
+ ChromatticSession session = persister.getSession();
+ ProducerInfoMapping pim = getProducerInfoMapping(id, session);
+ if (pim != null)
+ {
+ return pim.getLastModified();
+ }
+ else
+ {
+ throw new IllegalArgumentException("There is no ProducerInfo with id
'" + id + "'");
+ }
+ }
+ finally
+ {
+ persister.closeSession(false);
+ }
}
private ProducerInfoMapping getProducerInfoMapping(String id, ChromatticSession
session)
Show replies by date