From do-not-reply at jboss.org Tue Sep 20 13:32:45 2011
Content-Type: multipart/mixed; boundary="===============6176226482020793919=="
MIME-Version: 1.0
From: do-not-reply at jboss.org
To: gatein-commits at lists.jboss.org
Subject: [gatein-commits] gatein SVN: r7469 - in components/wsrp/trunk:
hibernate-impl/src/main/java/org/gatein/wsrp/consumer/registry/hibernate and
1 other directories.
Date: Tue, 20 Sep 2011 13:32:45 -0400
Message-ID: <201109201732.p8KHWju5015574@svn01.web.mwc.hst.phx2.redhat.com>
--===============6176226482020793919==
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: quoted-printable
Author: chris.laprun(a)jboss.com
Date: 2011-09-20 13:32:45 -0400 (Tue, 20 Sep 2011)
New Revision: 7469
Modified:
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/re=
gistry/AbstractConsumerRegistry.java
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/re=
gistry/ConsumerCache.java
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/re=
gistry/InMemoryConsumerRegistry.java
components/wsrp/trunk/hibernate-impl/src/main/java/org/gatein/wsrp/consu=
mer/registry/hibernate/HibernateConsumerRegistry.java
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/consumer/re=
gistry/JCRConsumerRegistry.java
Log:
- More clustering work: smarter ConsumerCache in AbstractConsumerRegistry w=
hich should now properly work in a clustering environment.
- Removed some commented-out code.
Modified: components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/cons=
umer/registry/AbstractConsumerRegistry.java
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/r=
egistry/AbstractConsumerRegistry.java 2011-09-20 17:20:48 UTC (rev 7468)
+++ components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/r=
egistry/AbstractConsumerRegistry.java 2011-09-20 17:32:45 UTC (rev 7469)
@@ -1,6 +1,6 @@
/*
* JBoss, a division of Red Hat
- * Copyright 2010, Red Hat Middleware, LLC, and individual
+ * Copyright 2011, Red Hat Middleware, LLC, and individual
* contributors as indicated by the @authors tag. See the
* copyright.txt in the distribution for a full listing of
* individual contributors.
@@ -42,10 +42,10 @@
import java.util.AbstractCollection;
import java.util.ArrayList;
import java.util.Collection;
-import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
=
/**
* @author Chris Laprun
@@ -68,7 +68,7 @@
=
protected ConsumerCache consumers =3D new InMemoryConsumerCache();
=
- public void setConsumerCache(ConsumerCache consumers)
+ public synchronized void setConsumerCache(ConsumerCache consumers)
{
if (consumers =3D=3D null)
{
@@ -77,7 +77,7 @@
this.consumers =3D consumers;
}
=
- public void setSessionRegistry(SessionRegistry sessionRegistry)
+ public synchronized void setSessionRegistry(SessionRegistry sessionRegi=
stry)
{
if (sessionRegistry =3D=3D null)
{
@@ -96,7 +96,7 @@
return federatingPortletInvoker;
}
=
- public void setSessionEventBroadcaster(SessionEventBroadcaster sessionE=
ventBroadcaster)
+ public synchronized void setSessionEventBroadcaster(SessionEventBroadca=
ster sessionEventBroadcaster)
{
if (sessionEventBroadcaster =3D=3D null)
{
@@ -110,7 +110,7 @@
return migrationService;
}
=
- public void setMigrationService(MigrationService migrationService)
+ public synchronized void setMigrationService(MigrationService migration=
Service)
{
if (migrationService =3D=3D null)
{
@@ -190,7 +190,7 @@
createConsumerFrom(info);
}
=
- public void setFederatingPortletInvoker(FederatingPortletInvoker federa=
tingPortletInvoker)
+ public synchronized void setFederatingPortletInvoker(FederatingPortletI=
nvoker federatingPortletInvoker)
{
this.federatingPortletInvoker =3D federatingPortletInvoker;
}
@@ -240,7 +240,7 @@
startOrStopConsumer(consumer, false, true);
}
=
- public String updateProducerInfo(ProducerInfo producerInfo)
+ public synchronized String updateProducerInfo(ProducerInfo producerInfo)
{
ParameterValidation.throwIllegalArgExceptionIfNull(producerInfo, "Pr=
oducerInfo");
=
@@ -273,18 +273,7 @@
=
public void reloadConsumers()
{
- consumers.clear();
-
- Iterator producerInfos =3D getProducerInfosFromStorage=
();
-
- // load the configured producers
- ProducerInfo producerInfo;
- while (producerInfos.hasNext())
- {
- producerInfo =3D producerInfos.next();
-
- createConsumerFrom(producerInfo);
- }
+ consumers.initFromStorage();
}
=
public void stop() throws Exception
@@ -503,35 +492,65 @@
}
}
=
- protected static class InMemoryConsumerCache implements ConsumerCache
+ protected class InMemoryConsumerCache implements ConsumerCache
{
- private Map consumers =3D new HashMap(11);
+ private Map consumers =3D new ConcurrentHashMa=
p(11);
private boolean invalidated;
+ private long lastModified;
=
+ public void initFromStorage()
+ {
+ clear();
+ Iterator infosFromStorage =3D getProducerInfosFromS=
torage();
+ while (infosFromStorage.hasNext())
+ {
+ ProducerInfo info =3D infosFromStorage.next();
+ consumers.put(info.getId(), createConsumerFrom(info));
+ }
+ lastModified =3D System.currentTimeMillis();
+ setInvalidated(false);
+ }
+
public Collection getConsumers()
{
+ refreshIfNeeded();
return consumers.values();
}
=
public WSRPConsumer getConsumer(String id)
{
- return consumers.get(id);
+ // try cache first
+ WSRPConsumer consumer =3D consumers.get(id);
+
+ // if we didn't find the consumer in cache, try to load it from J=
CR
+ if (consumer =3D=3D null)
+ {
+ ProducerInfo info =3D loadProducerInfo(id);
+ if (info !=3D null)
+ {
+ consumer =3D createConsumerFrom(info);
+ }
+ }
+ return consumer;
}
=
public WSRPConsumer removeConsumer(String id)
{
+ lastModified =3D System.currentTimeMillis();
return consumers.remove(id);
}
=
public void putConsumer(String id, WSRPConsumer consumer)
{
consumers.put(id, consumer);
+ lastModified =3D System.currentTimeMillis();
}
=
public void clear()
{
consumers.clear();
invalidated =3D true;
+ lastModified =3D System.currentTimeMillis();
}
=
public boolean isInvalidated()
@@ -543,5 +562,40 @@
{
this.invalidated =3D invalidated;
}
+
+ public long getLastModified()
+ {
+ return lastModified;
+ }
+
+ protected void refreshIfNeeded()
+ {
+ AbstractConsumerRegistry registry =3D AbstractConsumerRegistry.th=
is;
+ // check if we need to refresh the local cache
+ if (isInvalidated() || registry.producerInfosGotModifiedSince(las=
tModified))
+ {
+ for (String id : registry.getConfiguredConsumersIds())
+ {
+ // only recreate the consumer if it's not in the cache or i=
t's been modified after we've been last modified
+ ProducerInfo info =3D registry.getUpdatedProducerInfoIfModi=
fiedSinceOrNull(id, lastModified);
+ if (consumers.get(id) =3D=3D null)
+ {
+ if (info =3D=3D null)
+ {
+ info =3D loadProducerInfo(id);
+ }
+ consumers.put(id, createConsumerFrom(info));
+ }
+ }
+
+ lastModified =3D System.currentTimeMillis();
+ setInvalidated(false);
+ }
+
+ }
}
+
+ protected abstract ProducerInfo getUpdatedProducerInfoIfModifiedSinceOr=
Null(String id, long lastModified);
+
+ protected abstract boolean producerInfosGotModifiedSince(long lastModif=
ied);
}
Modified: components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/cons=
umer/registry/ConsumerCache.java
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/r=
egistry/ConsumerCache.java 2011-09-20 17:20:48 UTC (rev 7468)
+++ components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/r=
egistry/ConsumerCache.java 2011-09-20 17:32:45 UTC (rev 7469)
@@ -43,4 +43,8 @@
boolean isInvalidated();
=
void setInvalidated(boolean invalidated);
+
+ long getLastModified();
+
+ void initFromStorage();
}
Modified: components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/cons=
umer/registry/InMemoryConsumerRegistry.java
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/r=
egistry/InMemoryConsumerRegistry.java 2011-09-20 17:20:48 UTC (rev 7468)
+++ components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/r=
egistry/InMemoryConsumerRegistry.java 2011-09-20 17:32:45 UTC (rev 7469)
@@ -140,6 +140,18 @@
keysToIds =3D null;
}
=
+ @Override
+ protected ProducerInfo getUpdatedProducerInfoIfModifiedSinceOrNull(Stri=
ng id, long lastModified)
+ {
+ return null;
+ }
+
+ @Override
+ protected boolean producerInfosGotModifiedSince(long lastModified)
+ {
+ return false;
+ }
+
protected void initConsumers(SortedMap consumers)
{
if (!ParameterValidation.existsAndIsNotEmpty(consumers))
Modified: components/wsrp/trunk/hibernate-impl/src/main/java/org/gatein/wsr=
p/consumer/registry/hibernate/HibernateConsumerRegistry.java
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- components/wsrp/trunk/hibernate-impl/src/main/java/org/gatein/wsrp/cons=
umer/registry/hibernate/HibernateConsumerRegistry.java 2011-09-20 17:20:48 =
UTC (rev 7468)
+++ components/wsrp/trunk/hibernate-impl/src/main/java/org/gatein/wsrp/cons=
umer/registry/hibernate/HibernateConsumerRegistry.java 2011-09-20 17:32:45 =
UTC (rev 7469)
@@ -133,4 +133,16 @@
sessionFactory =3D null;
super.stop();
}
+
+ @Override
+ protected ProducerInfo getUpdatedProducerInfoIfModifiedSinceOrNull(Stri=
ng id, long lastModified)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ protected boolean producerInfosGotModifiedSince(long lastModified)
+ {
+ throw new UnsupportedOperationException();
+ }
}
Modified: components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/cons=
umer/registry/JCRConsumerRegistry.java
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/consumer/r=
egistry/JCRConsumerRegistry.java 2011-09-20 17:20:48 UTC (rev 7468)
+++ components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/consumer/r=
egistry/JCRConsumerRegistry.java 2011-09-20 17:32:45 UTC (rev 7469)
@@ -69,7 +69,6 @@
public static final List mappingClasses =3D new ArrayList=
(6);
private InputStream configurationIS;
private long lastModified;
-// private Map infoCache;
=
static
{
@@ -167,35 +166,32 @@
=
ChromatticSession session =3D persister.getSession();
=
- synchronized (this)
+ final long now =3D System.currentTimeMillis();
+
+ ProducerInfoMapping pim =3D session.findById(ProducerInfoMapping.cla=
ss, key);
+ if (pim =3D=3D null)
{
- final long now =3D System.currentTimeMillis();
+ throw new IllegalArgumentException("Couldn't find ProducerInfoMap=
ping associated with key " + key);
+ }
+ oldId =3D pim.getId();
+ newId =3D producerInfo.getId();
+ producerInfo.setLastModified(now);
+ pim.initFrom(producerInfo);
=
- ProducerInfoMapping pim =3D session.findById(ProducerInfoMapping.=
class, key);
- if (pim =3D=3D null)
- {
- throw new IllegalArgumentException("Couldn't find ProducerInfo=
Mapping associated with key " + key);
- }
- oldId =3D pim.getId();
- newId =3D producerInfo.getId();
- producerInfo.setLastModified(now);
- pim.initFrom(producerInfo);
+ idUnchanged =3D oldId.equals(newId);
=
- idUnchanged =3D oldId.equals(newId);
+ if (!idUnchanged)
+ {
+ ProducerInfosMapping pims =3D getProducerInfosMapping(session);
+ Map nameToProducerInfoMap =3D pims.g=
etNameToProducerInfoMap();
+ nameToProducerInfoMap.put(pim.getId(), pim);
=
- if (!idUnchanged)
- {
- ProducerInfosMapping pims =3D getProducerInfosMapping(session);
- Map nameToProducerInfoMap =3D pim=
s.getNameToProducerInfoMap();
- nameToProducerInfoMap.put(pim.getId(), pim);
-
- pims.setLastModified(now);
- lastModified =3D now;
- }
-
- persister.closeSession(true);
+ pims.setLastModified(now);
+ lastModified =3D now;
}
=
+ persister.closeSession(true);
+
// if the consumer's id has changed, return the old one so that stat=
e can be updated
return idUnchanged ? null : oldId;
}
@@ -204,111 +200,32 @@
{
ChromatticSession session =3D persister.getSession();
=
- Collection consumers =3D getRefreshedInfoCache(session=
).getConsumers();
-
- // GTNWSRP-239
- // Kindof crappy place to put this, but we need to be able to retrie=
ve the mixin from the jcr so that it can be used to
- // configure the ProducerInfo
- /*Iterator consumersIterator =3D consumers.iterator();
- while (consumersIterator.hasNext())
+ try
{
- ProducerInfo pi =3D consumersIterator.next().getProducerInfo();
- String key =3D pi.getKey();
- ProducerInfoMapping pim =3D session.findById(ProducerInfoMapping.=
class, key);
- if (pim =3D=3D null)
+ List pims =3D getProducerInfosMapping(sessio=
n).getProducerInfos();
+ List infos =3D new ArrayList(pims.siz=
e());
+ for (ProducerInfoMapping pim : pims)
{
- throw new IllegalArgumentException("Couldn't find ProducerInfo=
Mapping associated with key " + key);
+ infos.add(pim.toModel(null, this));
}
- WSSEndpointEnabled wssee =3D getMixin(pim.getEndpointInfo(), sess=
ion, WSSEndpointEnabled.class);
- if (wssee !=3D null)
- {
- pi.getEndpointConfigurationInfo().setWSSEnabled(wssee.getWSSEn=
abled());
- }
- }*/
=
- final Iterator iterator =3D new ProducerInfoIterator(c=
onsumers.iterator());
- persister.closeSession(false);
- return iterator;
- }
-
- /*private Map getRefreshedInfoCache(ChromatticSes=
sion session)
- {
- ProducerInfosMapping producerInfosMapping =3D getProducerInfosMappin=
g(session);
-
- // check if we need to refresh the local cache
- if (lastModified < getMixin(producerInfosMapping, session, LastModif=
ied.class).getLastModified())
- {
- List mappings =3D producerInfosMapping.getPr=
oducerInfos();
-
-
- for (ProducerInfoMapping mapping : mappings)
- {
- infoCache.put(mapping.getId(), mapping.toModel(null, this));
- }
-
- lastModified =3D System.currentTimeMillis();
+ return infos.iterator();
}
-
- return infoCache;
- }*/
-
- private ConsumerCache getRefreshedInfoCache(ChromatticSession session)
- {
- ProducerInfosMapping producerInfosMapping =3D getProducerInfosMappin=
g(session);
-
- // check if we need to refresh the local cache
- if (consumers.isInvalidated() || lastModified < producerInfosMapping=
.getLastModified())
+ finally
{
- List mappings =3D producerInfosMapping.getPr=
oducerInfos();
-
- for (ProducerInfoMapping pim : mappings)
- {
- String id =3D pim.getId();
- // only recreate the consumer if it's not in the cache or it's=
been modified after we've been last modified
- if (consumers.getConsumer(id) =3D=3D null || lastModified < pi=
m.getLastModified())
- {
- consumers.putConsumer(id, createConsumerFrom(pim.toModel(nu=
ll, this)));
- }
- }
-
- lastModified =3D System.currentTimeMillis();
- consumers.setInvalidated(false);
+ persister.closeSession(false);
}
-
- return consumers;
}
=
public ProducerInfo loadProducerInfo(String id)
{
- ChromatticSession session =3D persister.getSession();
try
{
- ProducerInfoMapping pim =3D session.findByPath(ProducerInfoMappin=
g.class, getPathFor(id));
-
+ ChromatticSession session =3D persister.getSession();
+ ProducerInfoMapping pim =3D getProducerInfoMapping(id, session);
if (pim !=3D null)
{
- WSRPConsumer consumer =3D getRefreshedInfoCache(session).getCo=
nsumer(id);
-
- if (consumer =3D=3D null)
- {
- return null;
- }
- else
- {
- return consumer.getProducerInfo();
- /*ProducerInfo producerInfo =3D consumer.getProducerInfo();
- if(producerInfo =3D=3D null || producerInfo.getLastModified=
() < getMixin(pim, session, LastModified.class).getLastModified())
- {
- producerInfo =3D pim.toModel(producerInfo, this);
- getRefreshedInfoCache(session).put(id, producerInfo);
- return producerInfo;
- }
- else
- {
- return producerInfo;
- }*/
- }
-
+ return pim.toModel(null, this);
}
else
{
@@ -319,19 +236,13 @@
{
persister.closeSession(false);
}
+
}
=
- /*private M getMixin(Object objectToCheck, Chroma=
tticSession session, Class type)
+ private ProducerInfoMapping getProducerInfoMapping(String id, Chromatti=
cSession session)
{
- M mixin =3D session.getEmbedded(objectToCheck, type);
- if (mixin =3D=3D null)
- {
- mixin =3D session.create(type);
- session.setEmbedded(objectToCheck, type, mixin);
- mixin.initializeValue();
- }
- return mixin;
- }*/
+ return session.findByPath(ProducerInfoMapping.class, getPathFor(id));
+ }
=
@Override
public boolean containsConsumer(String id)
@@ -417,6 +328,41 @@
}
}
=
+ @Override
+ protected ProducerInfo getUpdatedProducerInfoIfModifiedSinceOrNull(Stri=
ng id, long lastModified)
+ {
+ try
+ {
+ ChromatticSession session =3D persister.getSession();
+ ProducerInfoMapping pim =3D 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.getSessio=
n()).getLastModified();
+ }
+ finally
+ {
+ persister.closeSession(false);
+ }
+ }
+
private ProducerInfosMapping getProducerInfosMapping(ChromatticSession =
session)
{
ProducerInfosMapping producerInfosMapping =3D session.findByPath(Pro=
ducerInfosMapping.class, PRODUCER_INFOS_PATH);
@@ -513,31 +459,4 @@
{
return persister;
}
-
- private static class MappingToProducerInfoIterator implements Iterator<=
ProducerInfo>
- {
- private Iterator mappings;
- private final JCRConsumerRegistry registry;
-
- public MappingToProducerInfoIterator(Iterator i=
nfoMappingIterator, JCRConsumerRegistry jcrConsumerRegistry)
- {
- this.mappings =3D infoMappingIterator;
- this.registry =3D jcrConsumerRegistry;
- }
-
- public boolean hasNext()
- {
- return mappings.hasNext();
- }
-
- public ProducerInfo next()
- {
- return mappings.next().toModel(null, registry);
- }
-
- public void remove()
- {
- throw new UnsupportedOperationException("Remove not supported!");
- }
- }
}
--===============6176226482020793919==--