[gatein-commits] gatein SVN: r7226 - in components/wsrp/branches/clustering: consumer/src/main/java/org/gatein/wsrp/consumer/registry and 9 other directories.
do-not-reply at jboss.org
do-not-reply at jboss.org
Thu Aug 25 04:35:47 EDT 2011
Author: chris.laprun at jboss.com
Date: 2011-08-25 04:35:46 -0400 (Thu, 25 Aug 2011)
New Revision: 7226
Modified:
components/wsrp/branches/clustering/consumer/src/main/java/org/gatein/wsrp/consumer/EndpointConfigurationInfo.java
components/wsrp/branches/clustering/consumer/src/main/java/org/gatein/wsrp/consumer/RegistrationInfo.java
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/ConsumerRegistry.java
components/wsrp/branches/clustering/consumer/src/main/java/org/gatein/wsrp/consumer/registry/InMemoryConsumerRegistry.java
components/wsrp/branches/clustering/consumer/src/main/java/org/gatein/wsrp/consumer/registry/xml/XMLConsumerRegistry.java
components/wsrp/branches/clustering/consumer/src/main/java/org/gatein/wsrp/services/SOAPServiceFactory.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/hibernate-impl/src/main/java/org/gatein/wsrp/consumer/registry/hibernate/HibernateConsumerRegistry.java
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/mapping/ProducerInfoMapping.java
components/wsrp/branches/clustering/jcr-impl/src/main/java/org/gatein/wsrp/registration/JCRRegistrationPersistenceManager.java
components/wsrp/branches/clustering/jcr-impl/src/test/java/org/gatein/wsrp/consumer/registry/JCRConsumerRegistryTestCase.java
Log:
- Initial commit of work on properly clustering WSRP: basically removing a lot of local state in ConsumerRegistry, hitting persistence instead. Not very well tested, just wanted to get the code out of my machine.
Modified: components/wsrp/branches/clustering/consumer/src/main/java/org/gatein/wsrp/consumer/EndpointConfigurationInfo.java
===================================================================
--- components/wsrp/branches/clustering/consumer/src/main/java/org/gatein/wsrp/consumer/EndpointConfigurationInfo.java 2011-08-25 07:49:56 UTC (rev 7225)
+++ components/wsrp/branches/clustering/consumer/src/main/java/org/gatein/wsrp/consumer/EndpointConfigurationInfo.java 2011-08-25 08:35:46 UTC (rev 7226)
@@ -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.
@@ -55,6 +55,30 @@
serviceFactory = new SOAPServiceFactory();
}
+ @Override
+ public boolean equals(Object o)
+ {
+ if (this == o)
+ {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass())
+ {
+ return false;
+ }
+
+ EndpointConfigurationInfo that = (EndpointConfigurationInfo)o;
+
+ return serviceFactory.equals(that.serviceFactory);
+
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return serviceFactory.hashCode();
+ }
+
public EndpointConfigurationInfo(ServiceFactory serviceFactory)
{
ParameterValidation.throwIllegalArgExceptionIfNull(serviceFactory, "ServiceFactory");
@@ -237,17 +261,17 @@
{
return serviceFactory.getWSRPVersion();
}
-
+
public boolean getWSSEnabled()
{
return serviceFactory.isWSSEnabled();
}
-
+
public void setWSSEnabled(boolean enable)
{
serviceFactory.enableWSS(enable);
}
-
+
public boolean isWSSAvailable()
{
return serviceFactory.isWSSAvailable();
Modified: components/wsrp/branches/clustering/consumer/src/main/java/org/gatein/wsrp/consumer/RegistrationInfo.java
===================================================================
--- components/wsrp/branches/clustering/consumer/src/main/java/org/gatein/wsrp/consumer/RegistrationInfo.java 2011-08-25 07:49:56 UTC (rev 7225)
+++ components/wsrp/branches/clustering/consumer/src/main/java/org/gatein/wsrp/consumer/RegistrationInfo.java 2011-08-25 08:35:46 UTC (rev 7226)
@@ -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.
@@ -41,6 +41,7 @@
import javax.xml.namespace.QName;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
@@ -77,6 +78,50 @@
*/
private static final String UNDETERMINED_REGISTRATION = "__JBP__UNDETERMINED__REGISTRATION__";
+ @Override
+ public boolean equals(Object o)
+ {
+ if (this == o)
+ {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass())
+ {
+ return false;
+ }
+
+ RegistrationInfo that = (RegistrationInfo)o;
+
+ if (persistentConsumerName != null ? !persistentConsumerName.equals(that.persistentConsumerName) : that.persistentConsumerName != null)
+ {
+ return false;
+ }
+ if (persistentRegistrationHandle != null ? !persistentRegistrationHandle.equals(that.persistentRegistrationHandle) : that.persistentRegistrationHandle != null)
+ {
+ return false;
+ }
+ if (persistentRegistrationProperties != null ? !persistentRegistrationProperties.equals(that.persistentRegistrationProperties) : that.persistentRegistrationProperties != null)
+ {
+ return false;
+ }
+ if (!Arrays.equals(persistentRegistrationState, that.persistentRegistrationState))
+ {
+ return false;
+ }
+
+ return true;
+ }
+
+ @Override
+ public int hashCode()
+ {
+ int result = persistentConsumerName != null ? persistentConsumerName.hashCode() : 0;
+ result = 31 * result + (persistentRegistrationHandle != null ? persistentRegistrationHandle.hashCode() : 0);
+ result = 31 * result + (persistentRegistrationState != null ? Arrays.hashCode(persistentRegistrationState) : 0);
+ result = 31 * result + (persistentRegistrationProperties != null ? persistentRegistrationProperties.hashCode() : 0);
+ return result;
+ }
+
public RegistrationInfo(ProducerInfo producerInfo)
{
this();
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-08-25 07:49:56 UTC (rev 7225)
+++ components/wsrp/branches/clustering/consumer/src/main/java/org/gatein/wsrp/consumer/registry/AbstractConsumerRegistry.java 2011-08-25 08:35:46 UTC (rev 7226)
@@ -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.
@@ -38,14 +38,8 @@
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
-import java.util.Map;
-import java.util.SortedMap;
-import java.util.TreeMap;
/**
* @author <a href="mailto:chris.laprun at jboss.com">Chris Laprun</a>
@@ -57,9 +51,6 @@
/** Gives access to the Portal's portlet invokers */
private FederatingPortletInvoker federatingPortletInvoker;
- private SortedMap<String, WSRPConsumer> consumers;
- private Map<String, String> keysToIds;
-
private SessionEventBroadcaster sessionEventBroadcaster = SessionEventBroadcaster.NO_OP_BROADCASTER;
private MigrationService migrationService;
@@ -68,11 +59,6 @@
private static final Logger log = LoggerFactory.getLogger(AbstractConsumerRegistry.class);
- protected AbstractConsumerRegistry()
- {
- initConsumers(null);
- }
-
public FederatingPortletInvoker getFederatingPortletInvoker()
{
return federatingPortletInvoker;
@@ -105,7 +91,6 @@
ProducerInfo info = new ProducerInfo();
info.setId(id);
- info.setRegistry(this);
info.setExpirationCacheSeconds(expirationCacheSeconds);
info.getEndpointConfigurationInfo().setWsdlDefinitionURL(wsdlURL);
@@ -140,8 +125,6 @@
}
deactivateConsumer(consumer);
- remove(consumer);
-
delete(info);
}
else
@@ -168,9 +151,9 @@
this.federatingPortletInvoker = federatingPortletInvoker;
}
- public ProducerInfo getProducerInfoByKey(String key)
+ /*protected ProducerInfo getProducerInfoByKey(String key)
{
- String id = keysToIds.get(key);
+ String id = getIdForKey(key);
if (id != null)
{
return getConsumer(id).getProducerInfo();
@@ -179,24 +162,30 @@
{
return null;
}
- }
+ }*/
- private WSRPConsumer createConsumerFrom(ProducerInfo producerInfo)
+ /*protected String getIdForKey(String key)
{
- WSRPConsumer consumer = newConsumer(producerInfo);
- add(consumer);
+ // try local cache first
+ String id = keysToIds.get(key);
- return consumer;
- }
+ // 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;
+ }
+ }*/
- /**
- * Extracted for testing purposes...
- *
- * @param producerInfo
- * @return
- */
- protected WSRPConsumer newConsumer(ProducerInfo producerInfo)
+ protected WSRPConsumer createConsumerFrom(ProducerInfo producerInfo)
{
+ // make sure we set the registry after loading from DB since registry is not persisted.
+ producerInfo.setRegistry(this);
+
return new WSRPConsumerImpl(producerInfo, migrationService);
}
@@ -253,7 +242,7 @@
}
}
- public void updateProducerInfo(ProducerInfo producerInfo)
+ public String updateProducerInfo(ProducerInfo producerInfo)
{
ParameterValidation.throwIllegalArgExceptionIfNull(producerInfo, "ProducerInfo");
@@ -262,7 +251,6 @@
// if we updated and oldId is not null, we need to update the local information
if (oldId != null)
{
- remove(getConsumer(oldId));
WSRPConsumer consumer = createConsumerFrom(producerInfo);
// update the federating portlet invoker:
@@ -273,6 +261,8 @@
federatingPortletInvoker.registerInvoker(producerInfo.getId(), consumer);
}
}
+
+ return oldId;
}
public void start() throws Exception
@@ -282,9 +272,6 @@
public void reloadConsumers()
{
- // load the configured consumers
- initConsumers(null);
-
Iterator<ProducerInfo> producerInfos = getProducerInfosFromStorage();
// load the configured producers
@@ -293,9 +280,6 @@
{
producerInfo = producerInfos.next();
- // need to set the registry after loading from DB since registry is not persisted.
- producerInfo.setRegistry(this);
-
createConsumerFrom(producerInfo);
}
}
@@ -322,19 +306,26 @@
// ignore and continue
}
}
-
- clearConsumers();
}
public List<WSRPConsumer> getConfiguredConsumers()
{
- return new ArrayList<WSRPConsumer>(getConsumers());
+ return getConsumers(true);
}
public WSRPConsumer getConsumer(String id)
{
ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(id, "consumer id", null);
- return consumers.get(id);
+
+ ProducerInfo info = loadProducerInfo(id);
+ if (info != null)
+ {
+ return createConsumerFrom(info);
+ }
+ else
+ {
+ return null;
+ }
}
public void registerOrDeregisterConsumerWith(String id, boolean register)
@@ -432,36 +423,20 @@
protected abstract Iterator<ProducerInfo> getProducerInfosFromStorage();
- // internal management methods
+ protected abstract ProducerInfo loadProducerInfo(String id);
- protected void add(WSRPConsumer consumer)
+ protected List<WSRPConsumer> getConsumers(boolean startConsumers)
{
- String id = consumer.getProducerId();
- consumers.put(id, consumer);
- ProducerInfo info = consumer.getProducerInfo();
- keysToIds.put(info.getKey(), id);
- }
-
- protected WSRPConsumer remove(WSRPConsumer consumer)
- {
- String id = keysToIds.remove(consumer.getProducerInfo().getKey());
- return consumers.remove(id);
- }
-
- protected Collection<WSRPConsumer> getConsumers()
- {
- return getConsumers(true);
- }
-
- protected Collection<WSRPConsumer> getConsumers(boolean startConsumers)
- {
- Collection<WSRPConsumer> consumerz = consumers.values();
-
- if (startConsumers)
+ Iterator<ProducerInfo> infos = getProducerInfosFromStorage();
+ List<WSRPConsumer> consumers = new ArrayList<WSRPConsumer>();
+ while (infos.hasNext())
{
- for (WSRPConsumer consumer : consumerz)
+ ProducerInfo info = infos.next();
+ WSRPConsumer consumer = createConsumerFrom(info);
+ consumers.add(consumer);
+ if (startConsumers)
{
- if (consumer.getProducerInfo().isActive() && !consumer.isActive())
+ if (info.isActive() && !consumer.isActive())
{
try
{
@@ -470,38 +445,15 @@
catch (Exception e)
{
log.info("Couldn't activate consumer " + consumer.getProducerId());
- consumer.getProducerInfo().setActiveAndSave(false);
+ info.setActiveAndSave(false);
}
}
}
}
- return consumerz;
- }
- protected Map<String, String> getKeyMappings()
- {
- return Collections.unmodifiableMap(keysToIds);
+ return consumers;
}
- protected void initConsumers(SortedMap<String, WSRPConsumer> consumers)
- {
- if (!ParameterValidation.existsAndIsNotEmpty(consumers))
- {
- consumers = new TreeMap<String, WSRPConsumer>();
- }
- this.consumers = consumers;
- int size = consumers.size();
- keysToIds = size == 0 ? new HashMap<String, String>() : new HashMap<String, String>(size);
- }
-
- private void clearConsumers()
- {
- consumers.clear();
- keysToIds.clear();
- consumers = null;
- keysToIds = null;
- }
-
protected class ProducerInfoIterator implements Iterator<ProducerInfo>
{
private Iterator<WSRPConsumer> consumers;
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-08-25 07:49:56 UTC (rev 7225)
+++ components/wsrp/branches/clustering/consumer/src/main/java/org/gatein/wsrp/consumer/registry/ConsumerRegistry.java 2011-08-25 08:35:46 UTC (rev 7226)
@@ -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.
@@ -58,7 +58,13 @@
*/
void activateConsumerWith(String id) throws ConsumerException;
- void updateProducerInfo(ProducerInfo producerInfo) throws ConsumerException;
+ /**
+ * Persists the changes made to ProducerInfo.
+ *
+ * @param producerInfo the ProducerInfo to persist
+ * @return the previous value of the ProducerInfo's id if it has changed, <code>null</code> otherwise
+ */
+ String updateProducerInfo(ProducerInfo producerInfo) throws ConsumerException;
void deactivateConsumerWith(String id) throws ConsumerException;
@@ -76,9 +82,7 @@
void setFederatingPortletInvoker(FederatingPortletInvoker federatingPortletInvoker);
- ProducerInfo getProducerInfoByKey(String key);
-
MigrationService getMigrationService();
void setMigrationService(MigrationService migrationService);
-}
\ No newline at end of file
+}
Modified: components/wsrp/branches/clustering/consumer/src/main/java/org/gatein/wsrp/consumer/registry/InMemoryConsumerRegistry.java
===================================================================
--- components/wsrp/branches/clustering/consumer/src/main/java/org/gatein/wsrp/consumer/registry/InMemoryConsumerRegistry.java 2011-08-25 07:49:56 UTC (rev 7225)
+++ components/wsrp/branches/clustering/consumer/src/main/java/org/gatein/wsrp/consumer/registry/InMemoryConsumerRegistry.java 2011-08-25 08:35:46 UTC (rev 7226)
@@ -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.
@@ -23,11 +23,17 @@
package org.gatein.wsrp.consumer.registry;
+import org.gatein.common.util.ParameterValidation;
import org.gatein.pc.federation.impl.FederatingPortletInvokerService;
+import org.gatein.wsrp.WSRPConsumer;
import org.gatein.wsrp.consumer.ProducerInfo;
import org.gatein.wsrp.consumer.migration.InMemoryMigrationService;
+import java.util.HashMap;
import java.util.Iterator;
+import java.util.Map;
+import java.util.SortedMap;
+import java.util.TreeMap;
import java.util.UUID;
/**
@@ -36,13 +42,42 @@
*/
public class InMemoryConsumerRegistry extends AbstractConsumerRegistry
{
+ private SortedMap<String, WSRPConsumer> consumers;
+ private Map<String, String> keysToIds;
+
public InMemoryConsumerRegistry()
{
+ initConsumers(null);
setFederatingPortletInvoker(new FederatingPortletInvokerService());
setMigrationService(new InMemoryMigrationService());
}
@Override
+ protected WSRPConsumer createConsumerFrom(ProducerInfo producerInfo)
+ {
+ WSRPConsumer consumer = super.createConsumerFrom(producerInfo);
+
+ String id = consumer.getProducerId();
+ consumers.put(id, consumer);
+ ProducerInfo info = consumer.getProducerInfo();
+ keysToIds.put(info.getKey(), id);
+
+ return consumer;
+ }
+
+ @Override
+ public String updateProducerInfo(ProducerInfo producerInfo)
+ {
+ String oldId = super.updateProducerInfo(producerInfo);
+ if (oldId != null)
+ {
+ keysToIds.put(producerInfo.getKey(), producerInfo.getId());
+ consumers.remove(oldId);
+ }
+ return oldId;
+ }
+
+ @Override
protected void save(ProducerInfo info, String messageOnError)
{
// generate a UUID for ProducerInfo
@@ -52,19 +87,72 @@
@Override
protected void delete(ProducerInfo info)
{
- // nothing to do here
+ String key = info.getKey();
+ String removed = keysToIds.remove(key);
+ if (removed != null)
+ {
+ consumers.remove(removed);
+ }
}
@Override
protected String update(ProducerInfo producerInfo)
{
String key = producerInfo.getKey();
- return getKeyMappings().get(key);
+ String oldId = keysToIds.get(key);
+ if (oldId.equals(producerInfo.getId()))
+ {
+ return null;
+ }
+ else
+ {
+ return oldId;
+ }
}
@Override
+ public void reloadConsumers()
+ {
+ // do nothing
+ }
+
+ @Override
protected Iterator<ProducerInfo> getProducerInfosFromStorage()
{
- return new ProducerInfoIterator(getConsumers().iterator());
+ return new ProducerInfoIterator(consumers.values().iterator());
}
+
+ @Override
+ protected ProducerInfo loadProducerInfo(String id)
+ {
+ if (keysToIds.containsValue(id))
+ {
+ return consumers.get(id).getProducerInfo();
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ @Override
+ public void stop() throws Exception
+ {
+ super.stop();
+ consumers.clear();
+ keysToIds.clear();
+ consumers = null;
+ keysToIds = null;
+ }
+
+ protected void initConsumers(SortedMap<String, WSRPConsumer> consumers)
+ {
+ if (!ParameterValidation.existsAndIsNotEmpty(consumers))
+ {
+ consumers = new TreeMap<String, WSRPConsumer>();
+ }
+ this.consumers = consumers;
+ int size = consumers.size();
+ keysToIds = size == 0 ? new HashMap<String, String>() : new HashMap<String, String>(size);
+ }
}
Modified: components/wsrp/branches/clustering/consumer/src/main/java/org/gatein/wsrp/consumer/registry/xml/XMLConsumerRegistry.java
===================================================================
--- components/wsrp/branches/clustering/consumer/src/main/java/org/gatein/wsrp/consumer/registry/xml/XMLConsumerRegistry.java 2011-08-25 07:49:56 UTC (rev 7225)
+++ components/wsrp/branches/clustering/consumer/src/main/java/org/gatein/wsrp/consumer/registry/xml/XMLConsumerRegistry.java 2011-08-25 08:35:46 UTC (rev 7226)
@@ -1,31 +1,31 @@
-/******************************************************************************
- * JBoss, a division of Red Hat *
- * Copyright 2006, 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. *
- * *
- * This is free software; you can redistribute it and/or modify it *
- * under the terms of the GNU Lesser General Public License as *
- * published by the Free Software Foundation; either version 2.1 of *
- * the License, or (at your option) any later version. *
- * *
- * This software is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
- * Lesser General Public License for more details. *
- * *
- * You should have received a copy of the GNU Lesser General Public *
- * License along with this software; if not, write to the Free *
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
- ******************************************************************************/
+/*
+ * JBoss, a division of Red Hat
+ * 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.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
package org.gatein.wsrp.consumer.registry.xml;
import org.gatein.common.xml.NullEntityResolver;
import org.gatein.wsrp.WSRPConsumer;
import org.gatein.wsrp.consumer.ProducerInfo;
-import org.gatein.wsrp.consumer.registry.AbstractConsumerRegistry;
+import org.gatein.wsrp.consumer.registry.InMemoryConsumerRegistry;
import org.jboss.xb.binding.JBossXBException;
import org.jboss.xb.binding.ObjectModelFactory;
import org.jboss.xb.binding.Unmarshaller;
@@ -37,14 +37,13 @@
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
-import java.util.Iterator;
import java.util.SortedMap;
/**
* @author <a href="mailto:chris.laprun at jboss.com">Chris Laprun</a>
* @version $Revision: 9360 $
*/
-public class XMLConsumerRegistry extends AbstractConsumerRegistry
+public class XMLConsumerRegistry extends InMemoryConsumerRegistry
{
private final static Logger log = LoggerFactory.getLogger(XMLConsumerRegistry.class);
@@ -101,34 +100,9 @@
{
throw new RuntimeException("Couldn't set unmarshall WSRP Consumers configuration", e);
}
-
- for (WSRPConsumer consumer : getConsumers())
- {
-
- ProducerInfo producerInfo = consumer.getProducerInfo();
- try
- {
- // try to activate the consumer
- activateConsumer(consumer);
- }
- catch (Exception e)
- {
- producerInfo.setActive(false);
- updateProducerInfo(producerInfo);
- }
- }
}
@Override
- public void stop() throws Exception
- {
- for (WSRPConsumer consumer : getConsumers())
- {
- consumer.stop();
- }
- }
-
- @Override
protected void save(ProducerInfo info, String messageOnError)
{
// do nothing
@@ -145,10 +119,4 @@
{
return null;
}
-
- @Override
- protected Iterator<ProducerInfo> getProducerInfosFromStorage()
- {
- return new ProducerInfoIterator(getConsumers().iterator());
- }
}
Modified: components/wsrp/branches/clustering/consumer/src/main/java/org/gatein/wsrp/services/SOAPServiceFactory.java
===================================================================
--- components/wsrp/branches/clustering/consumer/src/main/java/org/gatein/wsrp/services/SOAPServiceFactory.java 2011-08-25 07:49:56 UTC (rev 7225)
+++ components/wsrp/branches/clustering/consumer/src/main/java/org/gatein/wsrp/services/SOAPServiceFactory.java 2011-08-25 08:35:46 UTC (rev 7226)
@@ -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.
@@ -58,7 +58,6 @@
import javax.xml.ws.handler.Handler;
import javax.xml.ws.handler.soap.SOAPHandler;
import javax.xml.ws.handler.soap.SOAPMessageContext;
-
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
@@ -100,9 +99,48 @@
private boolean failed;
private boolean available;
private int msBeforeTimeOut = DEFAULT_TIMEOUT_MS;
-
+
private boolean wssEnabled;
+ @Override
+ public boolean equals(Object o)
+ {
+ if (this == o)
+ {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass())
+ {
+ return false;
+ }
+
+ SOAPServiceFactory that = (SOAPServiceFactory)o;
+
+ if (msBeforeTimeOut != that.msBeforeTimeOut)
+ {
+ return false;
+ }
+ if (wssEnabled != that.wssEnabled)
+ {
+ return false;
+ }
+ if (wsdlDefinitionURL != null ? !wsdlDefinitionURL.equals(that.wsdlDefinitionURL) : that.wsdlDefinitionURL != null)
+ {
+ return false;
+ }
+
+ return true;
+ }
+
+ @Override
+ public int hashCode()
+ {
+ int result = wsdlDefinitionURL != null ? wsdlDefinitionURL.hashCode() : 0;
+ result = 31 * result + msBeforeTimeOut;
+ result = 31 * result + (wssEnabled ? 1 : 0);
+ return result;
+ }
+
private void setTimeout(Map<String, Object> requestContext)
{
int timeout = getWSOperationTimeOut();
@@ -138,7 +176,7 @@
{
handlerChain.add(REQUEST_HEADER_CLIENT_HANDLER);
}
-
+
addWSSHandlers(handlerChain);
}
else
@@ -146,7 +184,7 @@
// otherwise, create a handler chain and add our handler to it
handlerChain = new ArrayList<Handler>(1);
handlerChain.add(REQUEST_HEADER_CLIENT_HANDLER);
-
+
addWSSHandlers(handlerChain);
}
binding.setHandlerChain(handlerChain);
@@ -518,7 +556,7 @@
{
return this.wssEnabled;
}
-
+
public boolean isWSSAvailable()
{
WebServiceSecurityFactory wssFactory = WebServiceSecurityFactory.getInstance();
@@ -531,7 +569,7 @@
return false;
}
}
-
+
protected void addWSSHandlers(List<Handler> handlerChain)
{
if (wssEnabled)
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-08-25 07:49:56 UTC (rev 7225)
+++ components/wsrp/branches/clustering/consumer/src/test/java/org/gatein/wsrp/consumer/registry/ConsumerRegistryTestCase.java 2011-08-25 08:35:46 UTC (rev 7226)
@@ -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.
@@ -41,7 +41,7 @@
*/
public class ConsumerRegistryTestCase extends TestCase
{
- protected ConsumerRegistry registry;
+ protected AbstractConsumerRegistry registry;
@Override
protected void setUp() throws Exception
@@ -57,11 +57,13 @@
assertEquals(id, consumer.getProducerId());
ProducerInfo info = consumer.getProducerInfo();
assertNotNull(info);
+ assertNotNull(info.getKey());
assertEquals(consumer.getProducerId(), info.getId());
EndpointConfigurationInfo endpoint = info.getEndpointConfigurationInfo();
assertNotNull(endpoint);
RegistrationInfo regInfo = info.getRegistrationInfo();
assertTrue(regInfo.isUndetermined());
+ assertEquals(registry, info.getRegistry());
WSRPConsumer fromRegistry = registry.getConsumer(id);
assertNotNull(fromRegistry);
@@ -71,6 +73,7 @@
assertEquals(fromRegistry.getProducerId(), fromRegistryInfo.getId());
assertNotNull(fromRegistryInfo.getEndpointConfigurationInfo());
assertTrue(fromRegistryInfo.getRegistrationInfo().isUndetermined());
+ assertEquals(registry, fromRegistryInfo.getRegistry());
assertEquals(info.getId(), fromRegistryInfo.getId());
assertEquals(info.getEndpointConfigurationInfo(), fromRegistryInfo.getEndpointConfigurationInfo());
@@ -87,17 +90,6 @@
assertNull(registry.getConsumer("inexistent"));
}
- public void testGetProducerInfoByKey()
- {
- WSRPConsumer consumer = registry.createConsumer("id", null, null);
- ProducerInfo info = consumer.getProducerInfo();
-
- String key = info.getKey();
- assertNotNull(key);
-
- assertEquals(info, registry.getProducerInfoByKey(key));
- }
-
public void testDoubleRegistrationOfConsumerWithSameId()
{
String id = "foo";
@@ -121,12 +113,9 @@
WSRPConsumer consumer = registry.createConsumer(id, null, null);
assertEquals(consumer, registry.getConsumer(id));
- String key = consumer.getProducerInfo().getKey();
-
registry.destroyConsumer(id);
assertNull(registry.getConsumer(id));
- assertNull(registry.getProducerInfoByKey(key));
}
public void testUpdateProducerInfo()
@@ -135,7 +124,6 @@
String id = "foo";
WSRPConsumer consumer = registry.createConsumer(id, null, null);
ProducerInfo info = consumer.getProducerInfo();
- String key = info.getKey();
// change the id on the consumer's producer info and save it
info.setId("bar");
@@ -143,7 +131,6 @@
assertNull(registry.getConsumer(id));
assertEquals(info, consumer.getProducerInfo());
- assertEquals(info, registry.getProducerInfoByKey(key));
assertEquals(consumer, registry.getConsumer("bar"));
}
@@ -158,14 +145,13 @@
Mockito.stub(info.getEndpointConfigurationInfo()).toReturn(endpoint);
// create a consumer to spy from
- WSRPConsumer original = ((AbstractConsumerRegistry)registry).newConsumer(info);
+ WSRPConsumer original = registry.createConsumerFrom(info);
WSRPConsumer consumer = Mockito.spy(original);
// force re-init of registry from "persistence" to ensure that the spy registry actually uses our spy consumer
ConsumerRegistry registrySpy = Mockito.spy(registry);
- Mockito.doReturn(Collections.singletonList(info).iterator()).when((AbstractConsumerRegistry)registrySpy).getProducerInfosFromStorage();
- Mockito.doReturn(consumer).when((AbstractConsumerRegistry)registrySpy).newConsumer(info);
- registrySpy.reloadConsumers();
+ Mockito.doReturn(consumer).when(registrySpy).getConsumer("foo");
+ Mockito.doReturn(Collections.singletonList(consumer)).when((AbstractConsumerRegistry)registrySpy).getConsumers(false);
WSRPConsumer foo = registrySpy.getConsumer("foo");
assertTrue(foo.getProducerInfo().isActive());
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-08-25 07:49:56 UTC (rev 7225)
+++ components/wsrp/branches/clustering/consumer/src/test/java/org/gatein/wsrp/test/support/MockConsumerRegistry.java 2011-08-25 08:35:46 UTC (rev 7226)
@@ -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.
@@ -53,7 +53,8 @@
/**
* Creates a ConsumerRegistry containing 2 consumers with id '{@link #CONSUMER1}' and '{@link #CONSUMER2}'
- * respectively. CONSUMER2 is active and has a service description URL set to {@link #MOCK_SERVICE_DESCRIPTION} and a
+ * respectively. CONSUMER2 is active and has a service description URL set to {@link #MOCK_SERVICE_DESCRIPTION} and
+ * a
* markup URL set to {@link #MOCK_MARKUP}
*/
public MockConsumerRegistry()
@@ -97,9 +98,9 @@
// do nothing
}
- public void updateProducerInfo(ProducerInfo producerInfo)
+ public String updateProducerInfo(ProducerInfo producerInfo)
{
- // do nothing
+ return null;
}
public void deactivateConsumerWith(String id) throws ConsumerException
Modified: components/wsrp/branches/clustering/hibernate-impl/src/main/java/org/gatein/wsrp/consumer/registry/hibernate/HibernateConsumerRegistry.java
===================================================================
--- components/wsrp/branches/clustering/hibernate-impl/src/main/java/org/gatein/wsrp/consumer/registry/hibernate/HibernateConsumerRegistry.java 2011-08-25 07:49:56 UTC (rev 7225)
+++ components/wsrp/branches/clustering/hibernate-impl/src/main/java/org/gatein/wsrp/consumer/registry/hibernate/HibernateConsumerRegistry.java 2011-08-25 08:35:46 UTC (rev 7226)
@@ -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.
@@ -113,6 +113,14 @@
}
@Override
+ protected ProducerInfo loadProducerInfo(String id)
+ {
+ Session session = sessionFactory.getCurrentSession();
+ return (ProducerInfo)session.createQuery("from ProducerInfo pi where pi.persistentId = :id")
+ .setParameter("id", id).uniqueResult();
+ }
+
+ @Override
public void start() throws Exception
{
InitialContext initialContext = new InitialContext();
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-08-25 07:49:56 UTC (rev 7225)
+++ components/wsrp/branches/clustering/jcr-impl/src/main/java/org/gatein/wsrp/consumer/registry/JCRConsumerRegistry.java 2011-08-25 08:35:46 UTC (rev 7226)
@@ -169,6 +169,22 @@
return new MappingToProducerInfoIterator(mappings.iterator());
}
+ @Override
+ protected ProducerInfo loadProducerInfo(String id)
+ {
+ ChromatticSession session = persister.getSession();
+ ProducerInfoMapping pim = session.findByPath(ProducerInfoMapping.class, getPathFor(id));
+
+ if (pim != null)
+ {
+ return pim.toModel(null);
+ }
+ else
+ {
+ return null;
+ }
+ }
+
private ProducerInfosMapping getProducerInfosMapping(ChromatticSession session)
{
ProducerInfosMapping producerInfosMapping = session.findByPath(ProducerInfosMapping.class, PRODUCER_INFOS_PATH);
@@ -212,9 +228,14 @@
private static String getPathFor(ProducerInfo info)
{
- return PRODUCER_INFOS_PATH + "/" + info.getId();
+ return getPathFor(info.getId());
}
+ private static String getPathFor(final String producerInfoId)
+ {
+ return PRODUCER_INFOS_PATH + "/" + producerInfoId;
+ }
+
private static ProducerInfoMapping toProducerInfoMapping(ProducerInfo producerInfo, ChromatticSession session)
{
ProducerInfoMapping pim = session.findById(ProducerInfoMapping.class, producerInfo.getKey());
Modified: components/wsrp/branches/clustering/jcr-impl/src/main/java/org/gatein/wsrp/consumer/registry/mapping/ProducerInfoMapping.java
===================================================================
--- components/wsrp/branches/clustering/jcr-impl/src/main/java/org/gatein/wsrp/consumer/registry/mapping/ProducerInfoMapping.java 2011-08-25 07:49:56 UTC (rev 7225)
+++ components/wsrp/branches/clustering/jcr-impl/src/main/java/org/gatein/wsrp/consumer/registry/mapping/ProducerInfoMapping.java 2011-08-25 08:35:46 UTC (rev 7226)
@@ -95,7 +95,11 @@
public ProducerInfo toModel(ProducerInfo initial)
{
// todo: should probably use a ProducerInfo implementation backed by mapping at some point
- ProducerInfo info = new ProducerInfo();
+ ProducerInfo info = initial;
+ if (initial == null)
+ {
+ info = new ProducerInfo();
+ }
// basic properties
info.setKey(getKey());
Modified: components/wsrp/branches/clustering/jcr-impl/src/main/java/org/gatein/wsrp/registration/JCRRegistrationPersistenceManager.java
===================================================================
--- components/wsrp/branches/clustering/jcr-impl/src/main/java/org/gatein/wsrp/registration/JCRRegistrationPersistenceManager.java 2011-08-25 07:49:56 UTC (rev 7225)
+++ components/wsrp/branches/clustering/jcr-impl/src/main/java/org/gatein/wsrp/registration/JCRRegistrationPersistenceManager.java 2011-08-25 08:35:46 UTC (rev 7226)
@@ -42,6 +42,7 @@
import org.gatein.wsrp.registration.mapping.RegistrationPropertiesMapping;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
@@ -53,7 +54,6 @@
public class JCRRegistrationPersistenceManager extends RegistrationPersistenceManagerImpl
{
private ChromatticPersister persister;
- private ConsumersAndGroupsMapping mappings;
public static final List<Class> mappingClasses = new ArrayList<Class>(6);
@@ -70,33 +70,142 @@
this.persister = persister;
ChromatticSession session = persister.getSession();
- mappings = session.findByPath(ConsumersAndGroupsMapping.class, ConsumersAndGroupsMapping.NODE_NAME);
+ ConsumersAndGroupsMapping mappings = session.findByPath(ConsumersAndGroupsMapping.class, ConsumersAndGroupsMapping.NODE_NAME);
if (mappings == null)
{
mappings = session.insert(ConsumersAndGroupsMapping.class, ConsumersAndGroupsMapping.NODE_NAME);
}
persister.save(); // needed right now as the session must still be open to iterate over nodes
- for (ConsumerGroupMapping cgm : mappings.getConsumerGroups())
+ initLocalCaches(mappings);
+
+ persister.closeSession(false);
+ }
+
+ public Collection<ConsumerSPI> getConsumers() throws RegistrationException
+ {
+ initLocalConsumerCache();
+
+ return super.getConsumers();
+ }
+
+ public Collection<RegistrationSPI> getRegistrations() throws RegistrationException
+ {
+ initLocalConsumerCache();
+
+ return super.getRegistrations();
+ }
+
+ public Collection<ConsumerGroupSPI> getConsumerGroups() throws RegistrationException
+ {
+ initLocalConsumerGroupCache();
+
+ return super.getConsumerGroups();
+ }
+
+ public Registration getRegistration(String registrationId) throws RegistrationException
+ {
+ Registration registration = super.getRegistration(registrationId);
+ // if we didn't find it in local cache, reload from JCR and check again;
+ if (registration == null)
{
- internalAddConsumerGroup(cgm.toConsumerGroup(this));
+ initLocalConsumerCache();
+ return super.getRegistration(registrationId);
}
+ else
+ {
+ return registration;
+ }
+ }
- for (ConsumerMapping cm : mappings.getConsumers())
+ public ConsumerGroup getConsumerGroup(String name) throws RegistrationException
+ {
+ ConsumerGroup consumerGroup = super.getConsumerGroup(name);
+ // if we didn't find it in local cache, reload from JCR and check again;
+ if (consumerGroup == null)
{
- ConsumerSPI consumer = cm.toConsumer(this);
- internalAddConsumer(consumer);
+ initLocalConsumerGroupCache();
+ return super.getConsumerGroup(name);
+ }
+ else
+ {
+ return consumerGroup;
+ }
+ }
- // get the registrations and add them to local map.
- for (Registration registration : consumer.getRegistrations())
+ public Consumer getConsumerById(String consumerId) throws RegistrationException
+ {
+ Consumer consumer = super.getConsumerById(consumerId);
+ // if we didn't find it in local cache, reload from JCR and check again;
+ if (consumer == null)
+ {
+ initLocalConsumerCache();
+ return super.getConsumerById(consumerId);
+ }
+ else
+ {
+ return consumer;
+ }
+ }
+
+ private void initLocalCaches(ConsumersAndGroupsMapping mappings) throws RegistrationException
+ {
+ initLocalCache(mappings, false);
+
+ initLocalCache(mappings, true);
+ }
+
+ private void initLocalCache(ConsumersAndGroupsMapping mappings, final boolean loadConsumers) throws RegistrationException
+ {
+ // if we already have mappings, no need to get them from JCR
+ ChromatticSession session = null;
+ if (mappings == null)
+ {
+ session = persister.getSession();
+ mappings = session.findByPath(ConsumersAndGroupsMapping.class, ConsumersAndGroupsMapping.NODE_NAME);
+ }
+
+ if (loadConsumers)
+ {
+ // load consumers and registrations
+ for (ConsumerMapping cm : mappings.getConsumers())
{
- internalAddRegistration((RegistrationSPI)registration);
+ ConsumerSPI consumer = cm.toConsumer(this);
+ internalAddConsumer(consumer);
+
+ // get the registrations and add them to local map.
+ for (Registration registration : consumer.getRegistrations())
+ {
+ internalAddRegistration((RegistrationSPI)registration);
+ }
}
}
+ else
+ {
+ // load consumer groups
+ for (ConsumerGroupMapping cgm : mappings.getConsumerGroups())
+ {
+ internalAddConsumerGroup(cgm.toConsumerGroup(this));
+ }
+ }
- persister.closeSession(false);
+ // if session is not null, we need to close it
+ if (session != null)
+ {
+ persister.closeSession(false);
+ }
}
+ private void initLocalConsumerCache() throws RegistrationException
+ {
+ initLocalCache(null, true);
+ }
+
+ private void initLocalConsumerGroupCache() throws RegistrationException
+ {
+ initLocalCache(null, false);
+ }
+
@Override
protected RegistrationSPI internalRemoveRegistration(String registrationId) throws RegistrationException
{
@@ -110,7 +219,7 @@
protected RegistrationSPI internalCreateRegistration(ConsumerSPI consumer, Map registrationProperties) throws RegistrationException
{
ChromatticSession session = persister.getSession();
- RegistrationSPI registration = null;
+ RegistrationSPI registration;
try
{
ConsumerMapping cm = session.findById(ConsumerMapping.class, consumer.getPersistentKey());
@@ -149,7 +258,7 @@
ConsumerSPI consumer = super.internalCreateConsumer(consumerId, consumerName);
ChromatticSession session = persister.getSession();
- mappings = session.findByPath(ConsumersAndGroupsMapping.class, ConsumersAndGroupsMapping.NODE_NAME);
+ ConsumersAndGroupsMapping mappings = session.findByPath(ConsumersAndGroupsMapping.class, ConsumersAndGroupsMapping.NODE_NAME);
try
{
ConsumerMapping cm = mappings.createConsumer(consumerId);
@@ -237,7 +346,7 @@
ConsumerGroupSPI group = super.internalCreateConsumerGroup(name);
ChromatticSession session = persister.getSession();
- mappings = session.findByPath(ConsumersAndGroupsMapping.class, ConsumersAndGroupsMapping.NODE_NAME);
+ ConsumersAndGroupsMapping mappings = session.findByPath(ConsumersAndGroupsMapping.class, ConsumersAndGroupsMapping.NODE_NAME);
try
{
ConsumerGroupMapping cgm = mappings.createConsumerGroup(name);
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-08-25 07:49:56 UTC (rev 7225)
+++ components/wsrp/branches/clustering/jcr-impl/src/test/java/org/gatein/wsrp/consumer/registry/JCRConsumerRegistryTestCase.java 2011-08-25 08:35:46 UTC (rev 7226)
@@ -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.
@@ -29,8 +29,7 @@
/**
* This is essentially the same class as org.gatein.wsrp.state.consumer.ConsumerRegistryTestCase in WSRP consumer
- * module
- * tests.
+ * module tests.
*
* @author <a href="mailto:chris.laprun at jboss.com">Chris Laprun</a>
* @version $Revision$
More information about the gatein-commits
mailing list