Author: chris.laprun(a)jboss.com
Date: 2011-11-03 18:07:30 -0400 (Thu, 03 Nov 2011)
New Revision: 7963
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/registry/InMemoryConsumerRegistry.java
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/registry/xml/XMLConsumerRegistry.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/consumer/registry/ConsumerRegistryTestCase.java
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/test/support/MockConsumerRegistry.java
components/wsrp/trunk/hibernate-impl/src/main/java/org/gatein/wsrp/consumer/registry/hibernate/HibernateConsumerRegistry.java
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/consumer/registry/JCRConsumerRegistry.java
Log:
- Fixed several issues with ConsumerRegistry implementations.
- Rewrote InMemoryConsumerCache.
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-11-03
21:52:27 UTC (rev 7962)
+++
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/registry/AbstractConsumerRegistry.java 2011-11-03
22:07:30 UTC (rev 7963)
@@ -39,12 +39,13 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.util.AbstractCollection;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
/**
@@ -66,15 +67,22 @@
private static final Logger log =
LoggerFactory.getLogger(AbstractConsumerRegistry.class);
- protected ConsumerCache consumers = new InMemoryConsumerCache();
+ protected ConsumerCache consumerCache;
+ protected AbstractConsumerRegistry()
+ {
+ initConsumerCache();
+ }
+
+ protected abstract void initConsumerCache();
+
public synchronized void setConsumerCache(ConsumerCache consumers)
{
if (consumers == null)
{
- consumers = new InMemoryConsumerCache();
+ consumers = new InMemoryConsumerCache(this);
}
- this.consumers = consumers;
+ this.consumerCache = consumers;
}
public synchronized void setSessionRegistry(SessionRegistry sessionRegistry)
@@ -137,7 +145,7 @@
save(info, "Couldn't create Consumer '" + id +
"'");
log.debug(CONSUMER_WITH_ID + id + "' created");
- return createConsumerFrom(info);
+ return createConsumerFrom(info, true);
}
public void destroyConsumer(String id)
@@ -169,7 +177,7 @@
delete(info);
// remove from cache
- consumers.removeConsumer(id);
+ consumerCache.removeConsumer(id);
}
else
{
@@ -187,7 +195,7 @@
save(info, CONSUMER_WITH_ID + info.getId() + "' couldn't be
persisted!");
- createConsumerFrom(info);
+ createConsumerFrom(info, true);
}
public synchronized void setFederatingPortletInvoker(FederatingPortletInvoker
federatingPortletInvoker)
@@ -195,7 +203,7 @@
this.federatingPortletInvoker = federatingPortletInvoker;
}
- public WSRPConsumer createConsumerFrom(ProducerInfo producerInfo)
+ public WSRPConsumer createConsumerFrom(ProducerInfo producerInfo, boolean putInCache)
{
// make sure we set the registry after loading from DB since registry is not
persisted.
// producerInfo.setRegistry(this);
@@ -203,7 +211,10 @@
final WSRPConsumerImpl consumer = createAndActivateIfNeeded(producerInfo);
// cache consumer
- consumers.putConsumer(producerInfo.getId(), consumer);
+ if (putInCache)
+ {
+ consumerCache.putConsumer(producerInfo.getId(), consumer);
+ }
return consumer;
}
@@ -254,7 +265,15 @@
public long getPersistedLastModifiedForProducerInfoWith(String id)
{
- return loadProducerInfo(id).getLastModified();
+ ProducerInfo producerInfo = loadProducerInfo(id);
+ if (producerInfo == null)
+ {
+ return Long.MAX_VALUE;
+ }
+ else
+ {
+ return producerInfo.getLastModified();
+ }
}
public synchronized String updateProducerInfo(ProducerInfo producerInfo)
@@ -266,7 +285,7 @@
// if we updated and oldId is not null, we need to update the local information
if (oldId != null)
{
- WSRPConsumer consumer = createConsumerFrom(producerInfo);
+ WSRPConsumer consumer = createConsumerFrom(producerInfo, true);
// update the federating portlet invoker if needed
if (federatingPortletInvoker.isResolved(oldId))
@@ -275,12 +294,10 @@
}
// update cache
- consumers.removeConsumer(oldId);
- consumers.putConsumer(producerInfo.getId(), consumer);
+ consumerCache.removeConsumer(oldId);
+ consumerCache.putConsumer(producerInfo.getId(), consumer);
}
- consumers.markAsModifiedNow();
-
return oldId;
}
@@ -291,7 +308,7 @@
public void reloadConsumers()
{
- consumers.initFromStorage();
+ consumerCache.initFromStorage();
}
public void stop() throws Exception
@@ -327,7 +344,7 @@
{
ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(id, "consumer
id", null);
- return consumers.getConsumer(id);
+ return consumerCache.getConsumer(id);
}
public boolean containsConsumer(String id)
@@ -335,44 +352,6 @@
return getConsumer(id) != null;
}
- public Collection<String> getConfiguredConsumersIds()
- {
- return new AbstractCollection<String>()
- {
- final private List<WSRPConsumer> consumers = getConsumers(false);
-
- @Override
- public Iterator<String> iterator()
- {
- return new Iterator<String>()
- {
- private Iterator<WSRPConsumer> consumerIterator =
consumers.iterator();
-
- public boolean hasNext()
- {
- return consumerIterator.hasNext();
- }
-
- public String next()
- {
- return consumerIterator.next().getProducerId();
- }
-
- public void remove()
- {
- throw new UnsupportedOperationException();
- }
- };
- }
-
- @Override
- public int size()
- {
- return consumers.size();
- }
- };
- }
-
public int getConfiguredConsumerNumber()
{
return getConfiguredConsumersIds().size();
@@ -420,7 +399,7 @@
{
if (!registerOrDeregisterOnly)
{
- consumer.activate();
+ consumer.refresh(false);
}
if (!federatingPortletInvoker.isResolved(id))
@@ -461,10 +440,11 @@
protected List<WSRPConsumer> getConsumers(boolean startConsumers)
{
- final Collection<WSRPConsumer> consumerz = consumers.getConsumers();
- for (WSRPConsumer consumer : consumerz)
+ final Collection<WSRPConsumer> consumerz = consumerCache.getConsumers();
+
+ if (startConsumers)
{
- if (startConsumers)
+ for (WSRPConsumer consumer : consumerz)
{
final ProducerInfo info = consumer.getProducerInfo();
if (info.isActive() && !consumer.isActive())
@@ -510,28 +490,33 @@
}
}
- protected class InMemoryConsumerCache implements ConsumerCache
+ protected static class InMemoryConsumerCache implements ConsumerCache
{
+
private Map<String, WSRPConsumer> consumers = new
ConcurrentHashMap<String, WSRPConsumer>(11);
private boolean invalidated;
- private long lastModified;
+ private ConsumerRegistrySPI registry;
+ public InMemoryConsumerCache(ConsumerRegistrySPI registry)
+ {
+ this.registry = registry;
+ }
+
public void initFromStorage()
{
clear();
- Iterator<ProducerInfo> infosFromStorage = getProducerInfosFromStorage();
+ Iterator<ProducerInfo> infosFromStorage =
registry.getProducerInfosFromStorage();
while (infosFromStorage.hasNext())
{
ProducerInfo info = infosFromStorage.next();
- consumers.put(info.getId(), createAndActivateIfNeeded(info));
+ consumers.put(info.getId(), createConsumer(info));
}
- markAsModifiedNow();
setInvalidated(false);
}
- public void markAsModifiedNow()
+ private WSRPConsumer createConsumer(ProducerInfo info)
{
- lastModified = System.currentTimeMillis();
+ return registry.createConsumerFrom(info, false);
}
public Collection<WSRPConsumer> getConsumers()
@@ -545,35 +530,46 @@
// try cache first
WSRPConsumer consumer = consumers.get(id);
- // 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))
+ return getUpdatedConsumer(id, consumer);
+ }
+
+ private WSRPConsumer getUpdatedConsumer(String id, WSRPConsumer consumer)
+ {
+ if (consumer == null || consumer.getProducerInfo().getLastModified() <
registry.getPersistedLastModifiedForProducerInfoWith(id))
{
- ProducerInfo info = loadProducerInfo(id);
+ // if consumer is not in cache or was modified in persistence, (re-)load it
from persistence
+ ProducerInfo info = registry.loadProducerInfo(id);
if (info != null)
{
- consumer = createAndActivateIfNeeded(info);
+ consumer = createConsumer(info);
+ consumers.put(id, consumer);
+ return consumer;
}
+ else
+ {
+ return null;
+ }
}
- return consumer;
+ else
+ {
+ return consumer;
+ }
}
public WSRPConsumer removeConsumer(String id)
{
- markAsModifiedNow();
return consumers.remove(id);
}
public void putConsumer(String id, WSRPConsumer consumer)
{
consumers.put(id, consumer);
- markAsModifiedNow();
}
public void clear()
{
consumers.clear();
invalidated = true;
- markAsModifiedNow();
}
public boolean isInvalidated()
@@ -586,39 +582,38 @@
this.invalidated = invalidated;
}
- public long getLastModified()
- {
- return lastModified;
- }
-
protected void refreshIfNeeded()
{
- AbstractConsumerRegistry registry = AbstractConsumerRegistry.this;
- // check if we need to refresh the local cache
- if (isInvalidated() || registry.producerInfosGotModifiedSince(lastModified))
+ if (isInvalidated())
{
- for (String id : registry.getConfiguredConsumersIds())
+ consumers.clear();
+ }
+
+ // first remove all obsolete Consumers in cache
+ Collection<String> consumersIds = registry.getConfiguredConsumersIds();
+ Set<String> obsoleteConsumers = new
HashSet<String>(consumers.keySet());
+ obsoleteConsumers.removeAll(consumersIds);
+ for (String obsolete : obsoleteConsumers)
+ {
+ consumers.remove(obsolete);
+ }
+
+ // then check, for each consumer, if it has been modified since we last checked
+ for (String id : consumersIds)
+ {
+ WSRPConsumer consumerInfo = consumers.get(id);
+ if (consumerInfo != null)
{
- // only recreate the consumer if it's not in the cache or it's
been modified after we've been last modified
- ProducerInfo info =
registry.getUpdatedProducerInfoIfModifiedSinceOrNull(id, lastModified);
- if (consumers.get(id) == null)
- {
- if (info == null)
- {
- info = loadProducerInfo(id);
- }
- consumers.put(id, createAndActivateIfNeeded(info));
- }
+ getUpdatedConsumer(id, consumerInfo);
}
-
- markAsModifiedNow();
- setInvalidated(false);
+ else
+ {
+ ProducerInfo producerInfo = registry.loadProducerInfo(id);
+ consumers.put(id, createConsumer(producerInfo));
+ }
}
+ setInvalidated(false);
}
}
-
- protected abstract ProducerInfo getUpdatedProducerInfoIfModifiedSinceOrNull(String id,
long lastModified);
-
- protected abstract boolean producerInfosGotModifiedSince(long lastModified);
}
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-11-03
21:52:27 UTC (rev 7962)
+++
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/registry/ConsumerCache.java 2011-11-03
22:07:30 UTC (rev 7963)
@@ -44,9 +44,5 @@
void setInvalidated(boolean invalidated);
- long getLastModified();
-
void initFromStorage();
-
- void markAsModifiedNow();
}
Modified:
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/registry/InMemoryConsumerRegistry.java
===================================================================
---
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/registry/InMemoryConsumerRegistry.java 2011-11-03
21:52:27 UTC (rev 7962)
+++
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/registry/InMemoryConsumerRegistry.java 2011-11-03
22:07:30 UTC (rev 7963)
@@ -29,6 +29,7 @@
import org.gatein.wsrp.consumer.ProducerInfo;
import org.gatein.wsrp.consumer.migration.InMemoryMigrationService;
+import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
@@ -53,10 +54,16 @@
}
@Override
- public WSRPConsumer createConsumerFrom(ProducerInfo producerInfo)
+ protected void initConsumerCache()
{
- WSRPConsumer consumer = super.createConsumerFrom(producerInfo);
+ setConsumerCache(new InMemoryConsumerCache(this));
+ }
+ @Override
+ public WSRPConsumer createConsumerFrom(ProducerInfo producerInfo, boolean putInCache)
+ {
+ WSRPConsumer consumer = super.createConsumerFrom(producerInfo, putInCache);
+
String id = consumer.getProducerId();
consumers.put(id, consumer);
ProducerInfo info = consumer.getProducerInfo();
@@ -98,12 +105,16 @@
{
String key = producerInfo.getKey();
String oldId = keysToIds.get(key);
- if (oldId.equals(producerInfo.getId()))
+ String newId = producerInfo.getId();
+ if (oldId.equals(newId))
{
return null;
}
else
{
+ keysToIds.put(key, newId);
+ WSRPConsumer consumer = consumers.get(oldId);
+ consumers.put(newId, consumer);
return oldId;
}
}
@@ -141,18 +152,11 @@
keysToIds = null;
}
- @Override
- protected ProducerInfo getUpdatedProducerInfoIfModifiedSinceOrNull(String id, long
lastModified)
+ public Collection<String> getConfiguredConsumersIds()
{
- return null;
+ return consumers.keySet();
}
- @Override
- protected boolean producerInfosGotModifiedSince(long lastModified)
- {
- return false;
- }
-
protected void initConsumers(SortedMap<String, WSRPConsumer> consumers)
{
if (!ParameterValidation.existsAndIsNotEmpty(consumers))
@@ -162,5 +166,9 @@
this.consumers = consumers;
int size = consumers.size();
keysToIds = size == 0 ? new HashMap<String, String>() : new
HashMap<String, String>(size);
+ for (WSRPConsumer consumer : consumers.values())
+ {
+ keysToIds.put(consumer.getProducerInfo().getKey(), consumer.getProducerId());
+ }
}
}
Modified:
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/registry/xml/XMLConsumerRegistry.java
===================================================================
---
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/registry/xml/XMLConsumerRegistry.java 2011-11-03
21:52:27 UTC (rev 7962)
+++
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/registry/xml/XMLConsumerRegistry.java 2011-11-03
22:07:30 UTC (rev 7963)
@@ -24,7 +24,6 @@
import org.gatein.common.xml.NullEntityResolver;
import org.gatein.wsrp.WSRPConsumer;
-import org.gatein.wsrp.consumer.ProducerInfo;
import org.gatein.wsrp.consumer.registry.InMemoryConsumerRegistry;
import org.jboss.xb.binding.JBossXBException;
import org.jboss.xb.binding.ObjectModelFactory;
@@ -101,19 +100,4 @@
throw new RuntimeException("Couldn't unmarshall WSRP Consumers
configuration", e);
}
}
-
- public void save(ProducerInfo info, String messageOnError)
- {
- // do nothing
- }
-
- public void delete(ProducerInfo info)
- {
- // do nothing
- }
-
- public String update(ProducerInfo producerInfo)
- {
- return null;
- }
}
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-11-03
21:52:27 UTC (rev 7962)
+++
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/spi/ConsumerRegistrySPI.java 2011-11-03
22:07:30 UTC (rev 7963)
@@ -69,7 +69,7 @@
ProducerInfo loadProducerInfo(String id);
- WSRPConsumer createConsumerFrom(ProducerInfo producerInfo);
+ WSRPConsumer createConsumerFrom(ProducerInfo producerInfo, boolean putInCache);
void registerWithFederatingPortletInvoker(WSRPConsumer consumer);
Modified:
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/consumer/registry/ConsumerRegistryTestCase.java
===================================================================
---
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/consumer/registry/ConsumerRegistryTestCase.java 2011-11-03
21:52:27 UTC (rev 7962)
+++
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/consumer/registry/ConsumerRegistryTestCase.java 2011-11-03
22:07:30 UTC (rev 7963)
@@ -137,9 +137,14 @@
WSRPConsumer consumer = registry.createConsumer(id, null, null);
ProducerInfo info = consumer.getProducerInfo();
+ // update unchanged ProducerInfo should return null
+ String previousId = registry.updateProducerInfo(info);
+ assertNull(previousId);
+
// change the id on the consumer's producer info and save it
info.setId("bar");
- registry.updateProducerInfo(info);
+ previousId = registry.updateProducerInfo(info);
+ assertEquals("foo", previousId);
assertNull(registry.getConsumer(id));
assertFalse(registry.containsConsumer(id));
@@ -161,7 +166,7 @@
Mockito.stub(info.getEndpointConfigurationInfo()).toReturn(endpoint);
registry.save(info, "Couldn't save ProducerInfo");
- WSRPConsumer original = registry.createConsumerFrom(info);
+ WSRPConsumer original = registry.createConsumerFrom(info, true);
// since consumer is supposed to be active, the registry will attempt to start it:
assertEquals(original,
registry.getFederatingPortletInvoker().getFederatedInvoker("foo").getPortletInvoker());
@@ -202,4 +207,39 @@
assertEquals(consumer1, registry.getConsumer(consumer1.getProducerId()));
assertEquals(consumer2, registry.getConsumer(consumer2.getProducerId()));
}
+
+ public void testCacheSimple()
+ {
+ WSRPConsumer consumer1 = registry.createConsumer("consumer1", null,
null);
+
+ assertTrue(registry.containsConsumer(consumer1.getProducerId()));
+
+ assertEquals(consumer1,
registry.consumerCache.getConsumer(consumer1.getProducerId()));
+
+ final ProducerInfo info = consumer1.getProducerInfo();
+ info.setId("foo");
+
+ registry.updateProducerInfo(info);
+
+ assertEquals(consumer1, registry.getConsumer("foo"));
+
+ registry.destroyConsumer("foo");
+ assertFalse(registry.containsConsumer("foo"));
+ }
+
+ public void testCacheModifyingProducerInfo()
+ {
+ WSRPConsumer consumer1 = registry.createConsumer("consumer1", null,
null);
+
+ assertTrue(registry.containsConsumer(consumer1.getProducerId()));
+
+ final ProducerInfo info = consumer1.getProducerInfo();
+ info.setId("foo");
+
+ // use lower-level method to simulate change from persistence layer
+ registry.update(info);
+
+ // retrieving the consumer with its new id should work
+ assertEquals(consumer1, registry.getConsumer("foo"));
+ }
}
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-11-03
21:52:27 UTC (rev 7962)
+++
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/test/support/MockConsumerRegistry.java 2011-11-03
22:07:30 UTC (rev 7963)
@@ -220,7 +220,7 @@
return consumers.size();
}
- public WSRPConsumer createConsumerFrom(ProducerInfo producerInfo)
+ public WSRPConsumer createConsumerFrom(ProducerInfo producerInfo, boolean putInCache)
{
throw new UnsupportedOperationException();
}
Modified:
components/wsrp/trunk/hibernate-impl/src/main/java/org/gatein/wsrp/consumer/registry/hibernate/HibernateConsumerRegistry.java
===================================================================
---
components/wsrp/trunk/hibernate-impl/src/main/java/org/gatein/wsrp/consumer/registry/hibernate/HibernateConsumerRegistry.java 2011-11-03
21:52:27 UTC (rev 7962)
+++
components/wsrp/trunk/hibernate-impl/src/main/java/org/gatein/wsrp/consumer/registry/hibernate/HibernateConsumerRegistry.java 2011-11-03
22:07:30 UTC (rev 7963)
@@ -31,6 +31,7 @@
import org.hibernate.SessionFactory;
import javax.naming.InitialContext;
+import java.util.Collection;
import java.util.Iterator;
/**
@@ -134,15 +135,14 @@
super.stop();
}
- @Override
- protected ProducerInfo getUpdatedProducerInfoIfModifiedSinceOrNull(String id, long
lastModified)
+ public Collection<String> getConfiguredConsumersIds()
{
throw new UnsupportedOperationException();
}
@Override
- protected boolean producerInfosGotModifiedSince(long lastModified)
+ protected void initConsumerCache()
{
- throw new UnsupportedOperationException();
+ setConsumerCache(new InMemoryConsumerCache(this));
}
}
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-11-03
21:52:27 UTC (rev 7962)
+++
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/consumer/registry/JCRConsumerRegistry.java 2011-11-03
22:07:30 UTC (rev 7963)
@@ -68,7 +68,6 @@
public static final List<Class> mappingClasses = new ArrayList<Class>(6);
private InputStream configurationIS;
- private long lastModified;
static
{
@@ -106,8 +105,15 @@
this.persister = persister;
this.loadFromXMLIfNeeded = loadFromXMLIfNeeded;
this.rootNodePath = rootNodePath.endsWith("/") ? rootNodePath :
rootNodePath + "/";
+ initConsumerCache();
}
+ @Override
+ protected void initConsumerCache()
+ {
+ setConsumerCache(new InMemoryConsumerCache(this));
+ }
+
/** @param is */
public void setConfigurationIS(InputStream is)
{
@@ -121,9 +127,7 @@
{
ChromatticSession session = persister.getSession();
- // update cache
final long now = System.currentTimeMillis();
- lastModified = now;
ProducerInfosMapping pims = getProducerInfosMapping(session);
pims.setLastModified(now);
@@ -180,14 +184,13 @@
idUnchanged = oldId.equals(newId);
+ ProducerInfosMapping pims = getProducerInfosMapping(session);
+ pims.setLastModified(now);
+
if (!idUnchanged)
{
- ProducerInfosMapping pims = getProducerInfosMapping(session);
Map<String, ProducerInfoMapping> nameToProducerInfoMap =
pims.getNameToProducerInfoMap();
nameToProducerInfoMap.put(pim.getId(), pim);
-
- pims.setLastModified(now);
- lastModified = now;
}
persister.closeSession(true);
@@ -283,7 +286,6 @@
}
}
- @Override
public Collection<String> getConfiguredConsumersIds()
{
ChromatticSession session = persister.getSession();
@@ -349,41 +351,6 @@
}
}
- @Override
- protected ProducerInfo getUpdatedProducerInfoIfModifiedSinceOrNull(String id, long
lastModified)
- {
- try
- {
- ChromatticSession session = persister.getSession();
- ProducerInfoMapping pim = getProducerInfoMapping(id, session);
- if (lastModified < pim.getLastModified())
- {
- return pim.toModel(null, this);
- }
- else
- {
- return null;
- }
- }
- finally
- {
- persister.closeSession(false);
- }
- }
-
- @Override
- protected boolean producerInfosGotModifiedSince(long lastModified)
- {
- try
- {
- return lastModified <
getProducerInfosMapping(persister.getSession()).getLastModified();
- }
- finally
- {
- persister.closeSession(false);
- }
- }
-
private ProducerInfosMapping getProducerInfosMapping(ChromatticSession session)
{
ProducerInfosMapping producerInfosMapping =
session.findByPath(ProducerInfosMapping.class, PRODUCER_INFOS_PATH);
@@ -417,11 +384,10 @@
// update ProducerInfo with the persistence key
info.setKey(pim.getKey());
- consumers.putConsumer(info.getId(), consumer);
+ consumerCache.putConsumer(info.getId(), consumer);
}
- lastModified = System.currentTimeMillis();
- producerInfosMapping.setLastModified(lastModified);
+ producerInfosMapping.setLastModified(System.currentTimeMillis());
session.save();
}
}