Author: chris.laprun(a)jboss.com
Date: 2011-09-01 16:03:19 -0400 (Thu, 01 Sep 2011)
New Revision: 7287
Modified:
components/wsrp/branches/clustering/consumer/src/main/java/org/gatein/wsrp/consumer/registry/AbstractConsumerRegistry.java
components/wsrp/branches/clustering/consumer/src/main/java/org/gatein/wsrp/consumer/registry/ActivatingNullInvokerHandler.java
components/wsrp/branches/clustering/consumer/src/main/java/org/gatein/wsrp/consumer/registry/ConsumerRegistry.java
components/wsrp/branches/clustering/consumer/src/test/java/org/gatein/wsrp/consumer/registry/ConsumerRegistryTestCase.java
components/wsrp/branches/clustering/consumer/src/test/java/org/gatein/wsrp/test/support/MockConsumerRegistry.java
components/wsrp/branches/clustering/jcr-impl/src/main/java/org/gatein/wsrp/consumer/registry/JCRConsumerRegistry.java
components/wsrp/branches/clustering/jcr-impl/src/test/java/org/gatein/wsrp/consumer/registry/JCRConsumerRegistryTestCase.java
components/wsrp/branches/clustering/pom.xml
Log:
- Upgraded to PC 2.3.0-Beta06-SNAPSHOT to get changes from federation and adapted to
them.
Modified:
components/wsrp/branches/clustering/consumer/src/main/java/org/gatein/wsrp/consumer/registry/AbstractConsumerRegistry.java
===================================================================
---
components/wsrp/branches/clustering/consumer/src/main/java/org/gatein/wsrp/consumer/registry/AbstractConsumerRegistry.java 2011-09-01
19:52:28 UTC (rev 7286)
+++
components/wsrp/branches/clustering/consumer/src/main/java/org/gatein/wsrp/consumer/registry/AbstractConsumerRegistry.java 2011-09-01
20:03:19 UTC (rev 7287)
@@ -37,7 +37,9 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import java.util.AbstractCollection;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.Iterator;
import java.util.List;
@@ -151,36 +153,6 @@
this.federatingPortletInvoker = federatingPortletInvoker;
}
- /*protected ProducerInfo getProducerInfoByKey(String key)
- {
- String id = getIdForKey(key);
- if (id != null)
- {
- return getConsumer(id).getProducerInfo();
- }
- else
- {
- return null;
- }
- }*/
-
- /*protected String getIdForKey(String key)
- {
- // try local cache first
- String id = keysToIds.get(key);
-
- // if it's not in the local cache, reload from persistence and check again
- if(id == null)
- {
- reloadConsumers();
- return keysToIds.get(key);
- }
- else
- {
- return id;
- }
- }*/
-
protected WSRPConsumer createConsumerFrom(ProducerInfo producerInfo)
{
// make sure we set the registry after loading from DB since registry is not
persisted.
@@ -200,19 +172,10 @@
ParameterValidation.throwIllegalArgExceptionIfNull(consumer,
"WSRPConsumer");
String id = consumer.getProducerId();
- if (federatingPortletInvoker.getFederatedInvoker(id) == null)
+ if (!federatingPortletInvoker.isResolved(id))
{
startOrStopConsumer(consumer, true);
}
- else
- {
- // todo: fix-me federated portlet invoker gets desynchronized...
- if (!consumer.isActive())
- {
- federatingPortletInvoker.unregisterInvoker(id);
- startOrStopConsumer(consumer, true);
- }
- }
}
public void deactivateConsumerWith(String id) throws ConsumerException
@@ -227,19 +190,10 @@
String id = consumer.getProducerId();
// only process if there is a registered Consumer with the specified id
- if (federatingPortletInvoker.getFederatedInvoker(id) != null)
+ if (federatingPortletInvoker.isResolved(id))
{
startOrStopConsumer(consumer, false);
}
- else
- {
- // todo: fix-me federated portlet invoker gets desynchronized...
- if (consumer.isActive())
- {
- federatingPortletInvoker.registerInvoker(id, consumer);
- startOrStopConsumer(consumer, false);
- }
- }
}
public String updateProducerInfo(ProducerInfo producerInfo)
@@ -253,9 +207,8 @@
{
WSRPConsumer consumer = createConsumerFrom(producerInfo);
- // update the federating portlet invoker:
- FederatedPortletInvoker invoker =
federatingPortletInvoker.getFederatedInvoker(oldId);
- if (invoker != null)
+ // update the federating portlet invoker if needed
+ if (federatingPortletInvoker.isResolved(oldId))
{
federatingPortletInvoker.unregisterInvoker(oldId);
federatingPortletInvoker.registerInvoker(producerInfo.getId(), consumer);
@@ -292,7 +245,7 @@
// unregister it. We have changed how consumers are registered (active consumers
are not automatically
// registered anymore), we also need to check if the consumer is known by the
federating portlet invoker...
String producerId = consumer.getProducerId();
- if (consumer.getProducerInfo().isActive() &&
federatingPortletInvoker.getFederatedInvoker(producerId) != null)
+ if (consumer.getProducerInfo().isActive() &&
federatingPortletInvoker.isResolved(producerId))
{
federatingPortletInvoker.unregisterInvoker(producerId);
}
@@ -328,6 +281,49 @@
}
}
+ public boolean containsConsumer(String id)
+ {
+ 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 void registerOrDeregisterConsumerWith(String id, boolean register)
{
ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(id, "Consumer
identifier", "Registering or deregistering a Consumer");
Modified:
components/wsrp/branches/clustering/consumer/src/main/java/org/gatein/wsrp/consumer/registry/ActivatingNullInvokerHandler.java
===================================================================
---
components/wsrp/branches/clustering/consumer/src/main/java/org/gatein/wsrp/consumer/registry/ActivatingNullInvokerHandler.java 2011-09-01
19:52:28 UTC (rev 7286)
+++
components/wsrp/branches/clustering/consumer/src/main/java/org/gatein/wsrp/consumer/registry/ActivatingNullInvokerHandler.java 2011-09-01
20:03:19 UTC (rev 7287)
@@ -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.
@@ -27,8 +27,11 @@
import org.gatein.pc.federation.FederatedPortletInvoker;
import org.gatein.pc.federation.FederatingPortletInvoker;
import org.gatein.pc.federation.NullInvokerHandler;
+import org.gatein.pc.federation.impl.FederatedPortletInvokerService;
import org.gatein.wsrp.WSRPConsumer;
+import java.util.Collection;
+
/**
* Attempts to activate a WSRP consumer named like the missing invoker that trigger the
invocation of this
* NullInvokerHandler. This is in particularly helpful to activate configured consumers
that haven't been started yet
@@ -41,7 +44,7 @@
{
private transient ConsumerRegistry consumerRegistry;
- public FederatedPortletInvoker resolvePortletInvokerFor(String compoundPortletId,
String invokerId, FederatingPortletInvoker callingInvoker) throws NoSuchPortletException
+ public FederatedPortletInvoker resolvePortletInvokerFor(String invokerId,
FederatingPortletInvoker callingInvoker, String compoundPortletId) throws
NoSuchPortletException
{
FederatingPortletInvoker registryInvoker =
consumerRegistry.getFederatingPortletInvoker();
if (registryInvoker != callingInvoker)
@@ -50,14 +53,19 @@
+ registryInvoker + ") than the specified one (" + callingInvoker +
")");
}
- FederatedPortletInvoker federated;
-
WSRPConsumer consumer = consumerRegistry.getConsumer(invokerId);
// if there's no consumer with that invoker id, then there's nothing much
we can do
if (consumer == null)
{
- throw new NoSuchPortletException(compoundPortletId);
+ if (compoundPortletId != null)
+ {
+ throw new NoSuchPortletException(compoundPortletId);
+ }
+ else
+ {
+ return null;
+ }
}
else
{
@@ -66,14 +74,21 @@
{
consumerRegistry.activateConsumerWith(invokerId);
- federated = callingInvoker.getFederatedInvoker(invokerId);
+ return new FederatedPortletInvokerService(callingInvoker, invokerId,
consumer);
}
}
+ }
- //
- return federated;
+ public boolean knows(String invoker)
+ {
+ return consumerRegistry.containsConsumer(invoker);
}
+ public Collection<String> getKnownInvokerIds()
+ {
+ return consumerRegistry.getConfiguredConsumersIds();
+ }
+
public void setConsumerRegistry(ConsumerRegistry consumerRegistry)
{
this.consumerRegistry = consumerRegistry;
Modified:
components/wsrp/branches/clustering/consumer/src/main/java/org/gatein/wsrp/consumer/registry/ConsumerRegistry.java
===================================================================
---
components/wsrp/branches/clustering/consumer/src/main/java/org/gatein/wsrp/consumer/registry/ConsumerRegistry.java 2011-09-01
19:52:28 UTC (rev 7286)
+++
components/wsrp/branches/clustering/consumer/src/main/java/org/gatein/wsrp/consumer/registry/ConsumerRegistry.java 2011-09-01
20:03:19 UTC (rev 7287)
@@ -30,6 +30,7 @@
import org.gatein.wsrp.consumer.ProducerInfo;
import org.gatein.wsrp.consumer.migration.MigrationService;
+import java.util.Collection;
import java.util.List;
/**
@@ -85,4 +86,8 @@
MigrationService getMigrationService();
void setMigrationService(MigrationService migrationService);
+
+ boolean containsConsumer(String id);
+
+ Collection<String> getConfiguredConsumersIds();
}
Modified:
components/wsrp/branches/clustering/consumer/src/test/java/org/gatein/wsrp/consumer/registry/ConsumerRegistryTestCase.java
===================================================================
---
components/wsrp/branches/clustering/consumer/src/test/java/org/gatein/wsrp/consumer/registry/ConsumerRegistryTestCase.java 2011-09-01
19:52:28 UTC (rev 7286)
+++
components/wsrp/branches/clustering/consumer/src/test/java/org/gatein/wsrp/consumer/registry/ConsumerRegistryTestCase.java 2011-09-01
20:03:19 UTC (rev 7287)
@@ -64,6 +64,7 @@
RegistrationInfo regInfo = info.getRegistrationInfo();
assertTrue(regInfo.isUndetermined());
assertEquals(registry, info.getRegistry());
+ assertTrue(registry.containsConsumer(id));
WSRPConsumer fromRegistry = registry.getConsumer(id);
assertNotNull(fromRegistry);
@@ -83,6 +84,11 @@
assertNotNull(consumers);
assertEquals(1, consumers.size());
assertTrue(consumers.contains(consumer));
+
+ final Collection<String> ids = registry.getConfiguredConsumersIds();
+ assertNotNull(ids);
+ assertEquals(1, ids.size());
+ assertTrue(ids.contains(id));
}
public void testGetConsumer()
@@ -112,9 +118,11 @@
WSRPConsumer consumer = registry.createConsumer(id, null, null);
assertEquals(consumer, registry.getConsumer(id));
+ assertTrue(registry.containsConsumer(id));
registry.destroyConsumer(id);
+ assertFalse(registry.containsConsumer(id));
assertNull(registry.getConsumer(id));
}
@@ -130,8 +138,11 @@
registry.updateProducerInfo(info);
assertNull(registry.getConsumer(id));
+ assertFalse(registry.containsConsumer(id));
+
assertEquals(info, consumer.getProducerInfo());
assertEquals(consumer, registry.getConsumer("bar"));
+ assertTrue(registry.containsConsumer("bar"));
}
public void testStoppingShouldntStartConsumers() throws Exception
Modified:
components/wsrp/branches/clustering/consumer/src/test/java/org/gatein/wsrp/test/support/MockConsumerRegistry.java
===================================================================
---
components/wsrp/branches/clustering/consumer/src/test/java/org/gatein/wsrp/test/support/MockConsumerRegistry.java 2011-09-01
19:52:28 UTC (rev 7286)
+++
components/wsrp/branches/clustering/consumer/src/test/java/org/gatein/wsrp/test/support/MockConsumerRegistry.java 2011-09-01
20:03:19 UTC (rev 7287)
@@ -34,6 +34,7 @@
import org.gatein.wsrp.consumer.registry.ConsumerRegistry;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -45,7 +46,7 @@
*/
public class MockConsumerRegistry implements ConsumerRegistry
{
- private Map consumers = new HashMap(3);
+ private Map<String, WSRPConsumer> consumers = new HashMap(3);
public static final String MOCK_SERVICE_DESCRIPTION =
"mock-service-description";
public static final String MOCK_MARKUP = "mock-markup";
public static final String CONSUMER1 = "inDB";
@@ -69,7 +70,7 @@
public WSRPConsumer getConsumer(String id)
{
- return (WSRPConsumer)consumers.get(id);
+ return consumers.get(id);
}
public FederatingPortletInvoker getFederatingPortletInvoker()
@@ -162,4 +163,14 @@
{
//To change body of implemented methods use File | Settings | File Templates.
}
+
+ public boolean containsConsumer(String id)
+ {
+ return consumers.containsKey(id);
+ }
+
+ public Collection<String> getConfiguredConsumersIds()
+ {
+ return consumers.keySet();
+ }
}
Modified:
components/wsrp/branches/clustering/jcr-impl/src/main/java/org/gatein/wsrp/consumer/registry/JCRConsumerRegistry.java
===================================================================
---
components/wsrp/branches/clustering/jcr-impl/src/main/java/org/gatein/wsrp/consumer/registry/JCRConsumerRegistry.java 2011-09-01
19:52:28 UTC (rev 7286)
+++
components/wsrp/branches/clustering/jcr-impl/src/main/java/org/gatein/wsrp/consumer/registry/JCRConsumerRegistry.java 2011-09-01
20:03:19 UTC (rev 7287)
@@ -37,8 +37,16 @@
import org.gatein.wsrp.jcr.StoresByPathManager;
import org.gatein.wsrp.registration.mapping.RegistrationPropertyDescriptionMapping;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.jcr.Value;
+import javax.jcr.query.Query;
+import javax.jcr.query.QueryResult;
+import javax.jcr.query.Row;
+import javax.jcr.query.RowIterator;
import java.io.InputStream;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
@@ -52,6 +60,7 @@
{
private ChromatticPersister persister;
private boolean loadFromXMLIfNeeded;
+ private final String rootNodePath;
private static final String PRODUCER_INFOS_PATH = ProducerInfosMapping.NODE_NAME;
public static final List<Class> mappingClasses = new ArrayList<Class>(6);
@@ -69,10 +78,29 @@
this(persister, true);
}
+ /**
+ * for tests
+ *
+ * @param persister
+ * @param loadFromXMLIfNeeded
+ */
protected JCRConsumerRegistry(ChromatticPersister persister, boolean
loadFromXMLIfNeeded)
{
+ this(persister, loadFromXMLIfNeeded, "/");
+ }
+
+ /**
+ * for tests
+ *
+ * @param persister
+ * @param loadFromXMLIfNeeded
+ * @param rootNodePath
+ */
+ protected JCRConsumerRegistry(ChromatticPersister persister, boolean
loadFromXMLIfNeeded, String rootNodePath)
+ {
this.persister = persister;
this.loadFromXMLIfNeeded = loadFromXMLIfNeeded;
+ this.rootNodePath = rootNodePath.endsWith("/") ? rootNodePath :
rootNodePath + "/";
}
/** @param is */
@@ -173,18 +201,84 @@
protected ProducerInfo loadProducerInfo(String id)
{
ChromatticSession session = persister.getSession();
- ProducerInfoMapping pim = session.findByPath(ProducerInfoMapping.class,
getPathFor(id));
+ try
+ {
+ ProducerInfoMapping pim = session.findByPath(ProducerInfoMapping.class,
getPathFor(id));
- if (pim != null)
+ if (pim != null)
+ {
+ return pim.toModel(null);
+ }
+ else
+ {
+ return null;
+ }
+ }
+ finally
{
- return pim.toModel(null);
+ persister.closeSession(false);
}
- else
+ }
+
+ @Override
+ public boolean containsConsumer(String id)
+ {
+ ChromatticSession session = persister.getSession();
+ try
{
- return null;
+ return session.getJCRSession().itemExists(rootNodePath + getPathFor(id));
}
+ catch (RepositoryException e)
+ {
+ throw new RuntimeException(e);
+ }
+ finally
+ {
+ persister.closeSession(false);
+ }
}
+ @Override
+ public Collection<String> getConfiguredConsumersIds()
+ {
+ ChromatticSession session = persister.getSession();
+ try
+ {
+ final Session jcrSession = session.getJCRSession();
+
+ final Query query =
jcrSession.getWorkspace().getQueryManager().createQuery("select producerid from
wsrp:producerinfo", Query.SQL);
+ final QueryResult queryResult = query.execute();
+ final RowIterator rows = queryResult.getRows();
+
+ final long size = rows.getSize();
+ if (size == 0)
+ {
+ return Collections.emptyList();
+ }
+ else
+ {
+ List<String> ids = new ArrayList<String>(size != -1 ? (int)size :
7);
+
+ while (rows.hasNext())
+ {
+ final Row row = rows.nextRow();
+ final Value rowValue = row.getValue("producerid");
+ ids.add(rowValue.getString());
+ }
+
+ return ids;
+ }
+ }
+ catch (RepositoryException e)
+ {
+ throw new RuntimeException(e);
+ }
+ finally
+ {
+ persister.closeSession(false);
+ }
+ }
+
private ProducerInfosMapping getProducerInfosMapping(ChromatticSession session)
{
ProducerInfosMapping producerInfosMapping =
session.findByPath(ProducerInfosMapping.class, PRODUCER_INFOS_PATH);
Modified:
components/wsrp/branches/clustering/jcr-impl/src/test/java/org/gatein/wsrp/consumer/registry/JCRConsumerRegistryTestCase.java
===================================================================
---
components/wsrp/branches/clustering/jcr-impl/src/test/java/org/gatein/wsrp/consumer/registry/JCRConsumerRegistryTestCase.java 2011-09-01
19:52:28 UTC (rev 7286)
+++
components/wsrp/branches/clustering/jcr-impl/src/test/java/org/gatein/wsrp/consumer/registry/JCRConsumerRegistryTestCase.java 2011-09-01
20:03:19 UTC (rev 7287)
@@ -44,7 +44,8 @@
@Override
protected void setUp() throws Exception
{
- String workspaceName = "/wsrp-jcr-test" + Math.round(Math.abs(100000 *
Math.random()));
+ final long random = Math.round(Math.abs(100000 * Math.random()));
+ String workspaceName = "/wsrp-jcr-test" + random;
BaseChromatticPersister persister = new BaseChromatticPersister(workspaceName)
{
@Override
@@ -56,7 +57,7 @@
}
};
persister.initializeBuilderFor(JCRConsumerRegistry.mappingClasses);
- registry = new JCRConsumerRegistry(persister, false);
+ registry = new JCRConsumerRegistry(persister, false, workspaceName);
registry.setFederatingPortletInvoker(new FederatingPortletInvokerService());
}
Modified: components/wsrp/branches/clustering/pom.xml
===================================================================
--- components/wsrp/branches/clustering/pom.xml 2011-09-01 19:52:28 UTC (rev 7286)
+++ components/wsrp/branches/clustering/pom.xml 2011-09-01 20:03:19 UTC (rev 7287)
@@ -47,7 +47,7 @@
</scm>
<properties>
- <org.gatein.pc.version>2.3.0-Beta05</org.gatein.pc.version>
+ <org.gatein.pc.version>2.3.0-Beta06-SNAPSHOT</org.gatein.pc.version>
<org.gatein.common.version>2.0.4-Beta02</org.gatein.common.version>
<org.gatein.wci.version>2.1.0-Beta01</org.gatein.wci.version>