Author: chris.laprun(a)jboss.com
Date: 2011-09-06 16:55:01 -0400 (Tue, 06 Sep 2011)
New Revision: 7315
Added:
components/wsrp/branches/clustering/consumer/src/main/java/org/gatein/wsrp/consumer/handlers/session/
components/wsrp/branches/clustering/consumer/src/main/java/org/gatein/wsrp/consumer/handlers/session/InMemorySessionRegistry.java
components/wsrp/branches/clustering/consumer/src/main/java/org/gatein/wsrp/consumer/handlers/session/SessionRegistry.java
components/wsrp/branches/clustering/consumer/src/main/java/org/gatein/wsrp/consumer/spi/ConsumerRegistrySPI.java
Modified:
components/wsrp/branches/clustering/consumer/src/main/java/org/gatein/wsrp/consumer/ProducerInfo.java
components/wsrp/branches/clustering/consumer/src/main/java/org/gatein/wsrp/consumer/WSRPConsumerImpl.java
components/wsrp/branches/clustering/consumer/src/main/java/org/gatein/wsrp/consumer/handlers/SessionHandler.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/spi/WSRPConsumerSPI.java
components/wsrp/branches/clustering/consumer/src/test/java/org/gatein/wsrp/consumer/ProducerInfoTestCase.java
components/wsrp/branches/clustering/consumer/src/test/java/org/gatein/wsrp/consumer/RegistrationInfoTestCase.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/protocol/v1/WSRP1ConsumerBaseTest.java
components/wsrp/branches/clustering/consumer/src/test/java/org/gatein/wsrp/protocol/v2/WSRP2ConsumerBaseTest.java
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/MockWSRPConsumer.java
components/wsrp/branches/clustering/jcr-impl/src/main/java/org/gatein/wsrp/consumer/migration/JCRMigrationService.java
components/wsrp/branches/clustering/jcr-impl/src/main/java/org/gatein/wsrp/consumer/migration/mapping/ExportInfoMapping.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/jcr/mapping/BaseMapping.java
Log:
- Moved session state from SessionHandler to ConsumerRegistry and introduced
SessionRegistry interface so that session information can be more easily distributed.
- Introduced ConsumerRegistrySPI interface to gather SPI-related behavior and moved some
methods from ConsumerRegistry to ConsumerRegistrySPI.
- ProducerInfo now needs to have a ConsumerRegistrySPI instance set to be properly
instantiated (instead of relying on setter).
- WSRPConsumerImpl now uses the information held by the ConsumerRegistrySPI instance it
gets from its ProducerInfo to retrieve MigrationService and SessionRegistry instances.
Should lighten the objects up a little in addition to making them easier to distribute.
- BaseMapping now needs to be parametrized by a second type representing an optional
registry object to be used in toModel method so that ProducerInfo can properly get a
ConsumerRegistry instance on creation.
- Adapted test cases.
Modified:
components/wsrp/branches/clustering/consumer/src/main/java/org/gatein/wsrp/consumer/ProducerInfo.java
===================================================================
---
components/wsrp/branches/clustering/consumer/src/main/java/org/gatein/wsrp/consumer/ProducerInfo.java 2011-09-06
11:41:54 UTC (rev 7314)
+++
components/wsrp/branches/clustering/consumer/src/main/java/org/gatein/wsrp/consumer/ProducerInfo.java 2011-09-06
20:55:01 UTC (rev 7315)
@@ -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,7 +38,7 @@
import org.gatein.wsrp.consumer.portlet.WSRPPortlet;
import org.gatein.wsrp.consumer.portlet.info.WSRPEventInfo;
import org.gatein.wsrp.consumer.portlet.info.WSRPPortletInfo;
-import org.gatein.wsrp.consumer.registry.ConsumerRegistry;
+import org.gatein.wsrp.consumer.spi.ConsumerRegistrySPI;
import org.gatein.wsrp.servlet.UserAccess;
import org.oasis.wsrp.v2.CookieProtocol;
import org.oasis.wsrp.v2.EventDescription;
@@ -124,7 +124,7 @@
private boolean isModifyRegistrationRequired;
- private ConsumerRegistry registry;
+ private final ConsumerRegistrySPI registry;
private static final String ERASED_LOCAL_REGISTRATION_INFORMATION = "Erased local
registration information!";
private transient RegistrationInfo expectedRegistrationInfo;
@@ -142,10 +142,11 @@
protected org.oasis.wsrp.v1.ResourceList resourceList;*/
- public ProducerInfo()
+ public ProducerInfo(ConsumerRegistrySPI consumerRegistry)
{
persistentEndpointInfo = new EndpointConfigurationInfo();
persistentRegistrationInfo =
RegistrationInfo.createUndeterminedRegistration(this);
+ this.registry = consumerRegistry;
}
@Override
@@ -193,16 +194,11 @@
return sb.toString();
}
- public ConsumerRegistry getRegistry()
+ public ConsumerRegistrySPI getRegistry()
{
return registry;
}
- public void setRegistry(ConsumerRegistry registry)
- {
- this.registry = registry;
- }
-
public String getKey()
{
return key;
Modified:
components/wsrp/branches/clustering/consumer/src/main/java/org/gatein/wsrp/consumer/WSRPConsumerImpl.java
===================================================================
---
components/wsrp/branches/clustering/consumer/src/main/java/org/gatein/wsrp/consumer/WSRPConsumerImpl.java 2011-09-06
11:41:54 UTC (rev 7314)
+++
components/wsrp/branches/clustering/consumer/src/main/java/org/gatein/wsrp/consumer/WSRPConsumerImpl.java 2011-09-06
20:55:01 UTC (rev 7315)
@@ -51,12 +51,13 @@
import org.gatein.wsrp.consumer.handlers.InvocationDispatcher;
import org.gatein.wsrp.consumer.handlers.ProducerSessionInformation;
import org.gatein.wsrp.consumer.handlers.SessionHandler;
+import org.gatein.wsrp.consumer.handlers.session.SessionRegistry;
import org.gatein.wsrp.consumer.migration.ExportInfo;
import org.gatein.wsrp.consumer.migration.ImportInfo;
-import org.gatein.wsrp.consumer.migration.InMemoryMigrationService;
import org.gatein.wsrp.consumer.migration.MigrationService;
import org.gatein.wsrp.consumer.portlet.WSRPPortlet;
import org.gatein.wsrp.consumer.portlet.info.WSRPPortletInfo;
+import org.gatein.wsrp.consumer.spi.ConsumerRegistrySPI;
import org.gatein.wsrp.consumer.spi.WSRPConsumerSPI;
import org.gatein.wsrp.services.MarkupService;
import org.gatein.wsrp.services.PortletManagementService;
@@ -95,7 +96,6 @@
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
-import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.SortedMap;
@@ -115,8 +115,6 @@
private ProducerInfo producerInfo;
- private transient MigrationService migrationService;
-
/** A registration data element used to indicate when no registration was required by
the producer */
private final static RegistrationData REGISTRATION_NOT_NEEDED =
WSRPTypeFactory.createDefaultRegistrationData();
@@ -143,20 +141,13 @@
private Set supportedUserScopes = WSRP_DEFAULT_USER_SCOPE; // todo: make it possible
to support different user scopes
private transient boolean started;
- public WSRPConsumerImpl()
+ public WSRPConsumerImpl(ProducerInfo info)
{
- this(new ProducerInfo(), new InMemoryMigrationService());
- }
-
- public WSRPConsumerImpl(ProducerInfo info, MigrationService migrationService)
- {
ParameterValidation.throwIllegalArgExceptionIfNull(info,
"ProducerInfo");
producerInfo = info;
sessionHandler = new SessionHandler(this);
dispatcher = new InvocationDispatcher(this);
-
- this.migrationService = migrationService;
}
public ProducerInfo getProducerInfo()
@@ -836,7 +827,7 @@
}
ExportInfo exportInfo = new ExportInfo(System.currentTimeMillis(),
errorCodeToHandle, handleToState, exportContextHolder.value);
- migrationService.add(exportInfo);
+ getConsumerRegistry().getMigrationService().add(exportInfo);
return exportInfo;
}
catch (OperationNotSupported operationNotSupported)
@@ -896,6 +887,11 @@
}
}
+ private ConsumerRegistrySPI getConsumerRegistry()
+ {
+ return producerInfo.getRegistry();
+ }
+
public void releaseExport(ExportInfo exportInfo) throws PortletInvokerException
{
ParameterValidation.throwIllegalArgExceptionIfNull(exportInfo, "ExportInfo to
release");
@@ -1023,11 +1019,16 @@
public MigrationService getMigrationService()
{
- return migrationService;
+ return getConsumerRegistry().getMigrationService();
}
public Version getWSRPVersion()
{
return producerInfo.getEndpointConfigurationInfo().getWSRPVersion();
}
+
+ public SessionRegistry getSessionRegistry()
+ {
+ return getConsumerRegistry().getSessionRegistry();
+ }
}
Modified:
components/wsrp/branches/clustering/consumer/src/main/java/org/gatein/wsrp/consumer/handlers/SessionHandler.java
===================================================================
---
components/wsrp/branches/clustering/consumer/src/main/java/org/gatein/wsrp/consumer/handlers/SessionHandler.java 2011-09-06
11:41:54 UTC (rev 7314)
+++
components/wsrp/branches/clustering/consumer/src/main/java/org/gatein/wsrp/consumer/handlers/SessionHandler.java 2011-09-06
20:55:01 UTC (rev 7315)
@@ -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.
@@ -45,11 +45,9 @@
import javax.servlet.http.HttpSession;
import java.util.ArrayList;
-import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
/**
* Manages session informations on behalf of a consumer.
@@ -66,9 +64,6 @@
/** The prefix used to isolate WSRP-related session information in the actual session
object. */
private static final String SESSION_ID_PREFIX = "org.gatein.wsrp.session.";
- /** session id -> ProducerSessionInformation */
- private Map<String, ProducerSessionInformation> sessionInfos = new
ConcurrentHashMap<String, ProducerSessionInformation>(); // todo: thread-safe?
-
/**
* Constructs a new SessionHandler.
*
@@ -316,7 +311,7 @@
{
List<String> idsToRelease = new ArrayList<String>();
- Set<ProducerSessionInformation> uniqueInfos = new
HashSet<ProducerSessionInformation>(sessionInfos.values());
+ Set<ProducerSessionInformation> uniqueInfos =
consumer.getSessionRegistry().getAll();
for (ProducerSessionInformation info : uniqueInfos)
{
@@ -339,7 +334,7 @@
for (String sessionId : sessionIds)
{
- ProducerSessionInformation info = sessionInfos.get(sessionId);
+ ProducerSessionInformation info =
consumer.getSessionRegistry().get(sessionId);
sessionId = info.removeSession(sessionId);
if (sessionId != null)
{
@@ -383,7 +378,7 @@
*/
void removeSessionId(String id)
{
- sessionInfos.remove(id);
+ consumer.getSessionRegistry().remove(id);
}
/**
@@ -395,7 +390,7 @@
*/
void addSessionMapping(String sessionID, ProducerSessionInformation
producerSessionInformation)
{
- sessionInfos.put(sessionID, producerSessionInformation);
+ consumer.getSessionRegistry().put(sessionID, producerSessionInformation);
}
// End ProducerSessionInformation callbacks
Added:
components/wsrp/branches/clustering/consumer/src/main/java/org/gatein/wsrp/consumer/handlers/session/InMemorySessionRegistry.java
===================================================================
---
components/wsrp/branches/clustering/consumer/src/main/java/org/gatein/wsrp/consumer/handlers/session/InMemorySessionRegistry.java
(rev 0)
+++
components/wsrp/branches/clustering/consumer/src/main/java/org/gatein/wsrp/consumer/handlers/session/InMemorySessionRegistry.java 2011-09-06
20:55:01 UTC (rev 7315)
@@ -0,0 +1,57 @@
+/*
+ * 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.handlers.session;
+
+import org.gatein.wsrp.consumer.handlers.ProducerSessionInformation;
+
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+
+/** @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a> */
+public class InMemorySessionRegistry implements SessionRegistry
+{
+ private Map<String, ProducerSessionInformation> sessionInfos = new
ConcurrentHashMap<String, ProducerSessionInformation>(); // todo: thread-safe?
+
+ public Set<ProducerSessionInformation> getAll()
+ {
+ return new HashSet<ProducerSessionInformation>(sessionInfos.values());
+ }
+
+ public ProducerSessionInformation get(String sessionId)
+ {
+ return sessionInfos.get(sessionId);
+ }
+
+ public ProducerSessionInformation remove(String sessionId)
+ {
+ return sessionInfos.remove(sessionId);
+ }
+
+ public void put(String sessionId, ProducerSessionInformation sessionInformation)
+ {
+ sessionInfos.put(sessionId, sessionInformation);
+ }
+}
Added:
components/wsrp/branches/clustering/consumer/src/main/java/org/gatein/wsrp/consumer/handlers/session/SessionRegistry.java
===================================================================
---
components/wsrp/branches/clustering/consumer/src/main/java/org/gatein/wsrp/consumer/handlers/session/SessionRegistry.java
(rev 0)
+++
components/wsrp/branches/clustering/consumer/src/main/java/org/gatein/wsrp/consumer/handlers/session/SessionRegistry.java 2011-09-06
20:55:01 UTC (rev 7315)
@@ -0,0 +1,40 @@
+/*
+ * 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.handlers.session;
+
+import org.gatein.wsrp.consumer.handlers.ProducerSessionInformation;
+
+import java.util.Set;
+
+/** @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a> */
+public interface SessionRegistry
+{
+ Set<ProducerSessionInformation> getAll();
+
+ ProducerSessionInformation get(String sessionId);
+
+ ProducerSessionInformation remove(String sessionId);
+
+ void put(String sessionId, ProducerSessionInformation sessionInformation);
+}
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-06
11:41:54 UTC (rev 7314)
+++
components/wsrp/branches/clustering/consumer/src/main/java/org/gatein/wsrp/consumer/registry/AbstractConsumerRegistry.java 2011-09-06
20:55:01 UTC (rev 7315)
@@ -33,7 +33,11 @@
import org.gatein.wsrp.consumer.ConsumerException;
import org.gatein.wsrp.consumer.ProducerInfo;
import org.gatein.wsrp.consumer.WSRPConsumerImpl;
+import org.gatein.wsrp.consumer.handlers.session.InMemorySessionRegistry;
+import org.gatein.wsrp.consumer.handlers.session.SessionRegistry;
+import org.gatein.wsrp.consumer.migration.InMemoryMigrationService;
import org.gatein.wsrp.consumer.migration.MigrationService;
+import org.gatein.wsrp.consumer.spi.ConsumerRegistrySPI;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -50,13 +54,14 @@
* @version $Revision: 12693 $
* @since 2.6
*/
-public abstract class AbstractConsumerRegistry implements ConsumerRegistry
+public abstract class AbstractConsumerRegistry implements ConsumerRegistrySPI
{
/** Gives access to the Portal's portlet invokers */
private FederatingPortletInvoker federatingPortletInvoker;
private SessionEventBroadcaster sessionEventBroadcaster =
SessionEventBroadcaster.NO_OP_BROADCASTER;
- private MigrationService migrationService;
+ private MigrationService migrationService = new InMemoryMigrationService();
+ private SessionRegistry sessionRegistry = new InMemorySessionRegistry();
private static final String CONSUMER_WITH_ID = "Consumer with id '";
private static final String RELEASE_SESSIONS_LISTENER =
"release_sessions_listener_";
@@ -67,9 +72,27 @@
public void setConsumerCache(ConsumerCache consumers)
{
+ if (consumers == null)
+ {
+ consumers = new InMemoryConsumerCache();
+ }
this.consumers = consumers;
}
+ public void setSessionRegistry(SessionRegistry sessionRegistry)
+ {
+ if (sessionRegistry == null)
+ {
+ sessionRegistry = new InMemorySessionRegistry();
+ }
+ this.sessionRegistry = sessionRegistry;
+ }
+
+ public SessionRegistry getSessionRegistry()
+ {
+ return sessionRegistry;
+ }
+
public FederatingPortletInvoker getFederatingPortletInvoker()
{
return federatingPortletInvoker;
@@ -77,6 +100,10 @@
public void setSessionEventBroadcaster(SessionEventBroadcaster
sessionEventBroadcaster)
{
+ if (sessionEventBroadcaster == null)
+ {
+ sessionEventBroadcaster = SessionEventBroadcaster.NO_OP_BROADCASTER;
+ }
this.sessionEventBroadcaster = sessionEventBroadcaster;
}
@@ -87,6 +114,10 @@
public void setMigrationService(MigrationService migrationService)
{
+ if (migrationService == null)
+ {
+ migrationService = new InMemoryMigrationService();
+ }
this.migrationService = migrationService;
}
@@ -100,7 +131,7 @@
}
- ProducerInfo info = new ProducerInfo();
+ ProducerInfo info = new ProducerInfo(this);
info.setId(id);
info.setExpirationCacheSeconds(expirationCacheSeconds);
info.getEndpointConfigurationInfo().setWsdlDefinitionURL(wsdlURL);
@@ -169,9 +200,9 @@
protected WSRPConsumer createConsumerFrom(ProducerInfo producerInfo)
{
// make sure we set the registry after loading from DB since registry is not
persisted.
- producerInfo.setRegistry(this);
+// producerInfo.setRegistry(this);
- final WSRPConsumerImpl consumer = new WSRPConsumerImpl(producerInfo,
migrationService);
+ final WSRPConsumerImpl consumer = new WSRPConsumerImpl(producerInfo);
// cache consumer
consumers.putConsumer(producerInfo.getId(), consumer);
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-06
11:41:54 UTC (rev 7314)
+++
components/wsrp/branches/clustering/consumer/src/main/java/org/gatein/wsrp/consumer/registry/ConsumerRegistry.java 2011-09-06
20:55:01 UTC (rev 7315)
@@ -25,10 +25,8 @@
import org.gatein.pc.federation.FederatingPortletInvoker;
import org.gatein.wsrp.WSRPConsumer;
-import org.gatein.wsrp.api.session.SessionEventBroadcaster;
import org.gatein.wsrp.consumer.ConsumerException;
import org.gatein.wsrp.consumer.ProducerInfo;
-import org.gatein.wsrp.consumer.migration.MigrationService;
import java.util.Collection;
import java.util.List;
@@ -75,18 +73,6 @@
void reloadConsumers();
- void start() throws Exception;
-
- void stop() throws Exception;
-
- void setSessionEventBroadcaster(SessionEventBroadcaster sessionEventBroadcaster);
-
- void setFederatingPortletInvoker(FederatingPortletInvoker federatingPortletInvoker);
-
- MigrationService getMigrationService();
-
- void setMigrationService(MigrationService migrationService);
-
boolean containsConsumer(String id);
Collection<String> getConfiguredConsumersIds();
Added:
components/wsrp/branches/clustering/consumer/src/main/java/org/gatein/wsrp/consumer/spi/ConsumerRegistrySPI.java
===================================================================
---
components/wsrp/branches/clustering/consumer/src/main/java/org/gatein/wsrp/consumer/spi/ConsumerRegistrySPI.java
(rev 0)
+++
components/wsrp/branches/clustering/consumer/src/main/java/org/gatein/wsrp/consumer/spi/ConsumerRegistrySPI.java 2011-09-06
20:55:01 UTC (rev 7315)
@@ -0,0 +1,50 @@
+/*
+ * 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.spi;
+
+import org.gatein.pc.federation.FederatingPortletInvoker;
+import org.gatein.wsrp.api.session.SessionEventBroadcaster;
+import org.gatein.wsrp.consumer.handlers.session.SessionRegistry;
+import org.gatein.wsrp.consumer.migration.MigrationService;
+import org.gatein.wsrp.consumer.registry.ConsumerRegistry;
+
+/** @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a> */
+public interface ConsumerRegistrySPI extends ConsumerRegistry
+{
+ void setSessionEventBroadcaster(SessionEventBroadcaster sessionEventBroadcaster);
+
+ void setFederatingPortletInvoker(FederatingPortletInvoker federatingPortletInvoker);
+
+ MigrationService getMigrationService();
+
+ void setMigrationService(MigrationService migrationService);
+
+ SessionRegistry getSessionRegistry();
+
+ void setSessionRegistry(SessionRegistry sessionRegistry);
+
+ void start() throws Exception;
+
+ void stop() throws Exception;
+}
Modified:
components/wsrp/branches/clustering/consumer/src/main/java/org/gatein/wsrp/consumer/spi/WSRPConsumerSPI.java
===================================================================
---
components/wsrp/branches/clustering/consumer/src/main/java/org/gatein/wsrp/consumer/spi/WSRPConsumerSPI.java 2011-09-06
11:41:54 UTC (rev 7314)
+++
components/wsrp/branches/clustering/consumer/src/main/java/org/gatein/wsrp/consumer/spi/WSRPConsumerSPI.java 2011-09-06
20:55:01 UTC (rev 7315)
@@ -28,6 +28,7 @@
import org.gatein.wsrp.WSRPConsumer;
import org.gatein.wsrp.consumer.ProducerInfo;
import org.gatein.wsrp.consumer.handlers.SessionHandler;
+import org.gatein.wsrp.consumer.handlers.session.SessionRegistry;
import org.gatein.wsrp.consumer.portlet.info.WSRPPortletInfo;
import org.gatein.wsrp.services.MarkupService;
import org.oasis.wsrp.v2.RegistrationContext;
@@ -65,4 +66,6 @@
boolean supportsUserScope(String userScope);
WSRPPortletInfo getPortletInfo(PortletInvocation invocation) throws
PortletInvokerException;
+
+ SessionRegistry getSessionRegistry();
}
Modified:
components/wsrp/branches/clustering/consumer/src/test/java/org/gatein/wsrp/consumer/ProducerInfoTestCase.java
===================================================================
---
components/wsrp/branches/clustering/consumer/src/test/java/org/gatein/wsrp/consumer/ProducerInfoTestCase.java 2011-09-06
11:41:54 UTC (rev 7314)
+++
components/wsrp/branches/clustering/consumer/src/test/java/org/gatein/wsrp/consumer/ProducerInfoTestCase.java 2011-09-06
20:55:01 UTC (rev 7315)
@@ -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.
@@ -72,15 +72,13 @@
protected void setUp() throws Exception
{
- info = new ProducerInfo();
+ info = new ProducerInfo(new MockConsumerRegistry());
info.setId("test");
info.setKey("key");
serviceFactory = new BehaviorBackedServiceFactory();
EndpointConfigurationInfo eci = new EndpointConfigurationInfo(serviceFactory);
info.setEndpointConfigurationInfo(eci);
-
- info.setRegistry(new MockConsumerRegistry());
}
public void testSetRegistrationInfo()
Modified:
components/wsrp/branches/clustering/consumer/src/test/java/org/gatein/wsrp/consumer/RegistrationInfoTestCase.java
===================================================================
---
components/wsrp/branches/clustering/consumer/src/test/java/org/gatein/wsrp/consumer/RegistrationInfoTestCase.java 2011-09-06
11:41:54 UTC (rev 7314)
+++
components/wsrp/branches/clustering/consumer/src/test/java/org/gatein/wsrp/consumer/RegistrationInfoTestCase.java 2011-09-06
20:55:01 UTC (rev 7315)
@@ -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.
@@ -50,7 +50,7 @@
protected void setUp() throws Exception
{
- ProducerInfo pi = new ProducerInfo();
+ ProducerInfo pi = new ProducerInfo(null);
info = pi.getRegistrationInfo();
}
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-06
11:41:54 UTC (rev 7314)
+++
components/wsrp/branches/clustering/consumer/src/test/java/org/gatein/wsrp/consumer/registry/ConsumerRegistryTestCase.java 2011-09-06
20:55:01 UTC (rev 7315)
@@ -165,16 +165,16 @@
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);
+ AbstractConsumerRegistry registrySpy = Mockito.spy(registry);
Mockito.doReturn(consumer).when(registrySpy).getConsumer("foo");
-
Mockito.doReturn(Collections.singletonList(consumer)).when((AbstractConsumerRegistry)registrySpy).getConsumers(false);
+
Mockito.doReturn(Collections.singletonList(consumer)).when(registrySpy).getConsumers(false);
WSRPConsumer foo = registrySpy.getConsumer("foo");
assertTrue(foo.getProducerInfo().isActive());
assertEquals(consumer, foo);
// start consumer and check that it's properly added to the
FederatingPortletInvoker
- ((AbstractConsumerRegistry)registrySpy).activateConsumer(foo);
+ registrySpy.activateConsumer(foo);
assertEquals(consumer,
registrySpy.getFederatingPortletInvoker().getFederatedInvoker("foo").getPortletInvoker());
// stop the consumer and then the registry and check that consumer.start has only
been called once
Modified:
components/wsrp/branches/clustering/consumer/src/test/java/org/gatein/wsrp/protocol/v1/WSRP1ConsumerBaseTest.java
===================================================================
---
components/wsrp/branches/clustering/consumer/src/test/java/org/gatein/wsrp/protocol/v1/WSRP1ConsumerBaseTest.java 2011-09-06
11:41:54 UTC (rev 7314)
+++
components/wsrp/branches/clustering/consumer/src/test/java/org/gatein/wsrp/protocol/v1/WSRP1ConsumerBaseTest.java 2011-09-06
20:55:01 UTC (rev 7315)
@@ -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.
@@ -68,7 +68,7 @@
protected TestWSRPProducer producer = new TestWSRPProducerImpl();
/** . */
- protected WSRPConsumerImpl consumer = new WSRPConsumerImpl();
+ protected WSRPConsumerImpl consumer = new WSRPConsumerImpl(new ProducerInfo(new
MockConsumerRegistry()));
private boolean strict = true;
@@ -88,9 +88,6 @@
setRegistrationBehavior(null);
registerAdditionalMarkupBehaviors(registry);
- // use a fresh ConsumerRegistry
- producerInfo.setRegistry(new MockConsumerRegistry());
-
// use a fresh endpoint using a behavior-backed service factory
producerInfo.setEndpointConfigurationInfo(new EndpointConfigurationInfo(new
BehaviorBackedServiceFactory(registry)));
Modified:
components/wsrp/branches/clustering/consumer/src/test/java/org/gatein/wsrp/protocol/v2/WSRP2ConsumerBaseTest.java
===================================================================
---
components/wsrp/branches/clustering/consumer/src/test/java/org/gatein/wsrp/protocol/v2/WSRP2ConsumerBaseTest.java 2011-09-06
11:41:54 UTC (rev 7314)
+++
components/wsrp/branches/clustering/consumer/src/test/java/org/gatein/wsrp/protocol/v2/WSRP2ConsumerBaseTest.java 2011-09-06
20:55:01 UTC (rev 7315)
@@ -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.
@@ -68,7 +68,7 @@
protected TestWSRPProducer producer = new TestWSRPProducerImpl();
/** . */
- protected WSRPConsumerImpl consumer = new WSRPConsumerImpl();
+ protected WSRPConsumerImpl consumer = new WSRPConsumerImpl(new ProducerInfo(new
MockConsumerRegistry()));
private boolean strict = true;
@@ -88,9 +88,6 @@
setRegistrationBehavior(null);
registerAdditionalMarkupBehaviors(registry);
- // use a fresh ConsumerRegistry
- producerInfo.setRegistry(new MockConsumerRegistry());
-
// use a fresh endpoint using a behavior-backed service factory
producerInfo.setEndpointConfigurationInfo(new EndpointConfigurationInfo(new
BehaviorBackedServiceFactory(registry)));
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-06
11:41:54 UTC (rev 7314)
+++
components/wsrp/branches/clustering/consumer/src/test/java/org/gatein/wsrp/test/support/MockConsumerRegistry.java 2011-09-06
20:55:01 UTC (rev 7315)
@@ -30,8 +30,11 @@
import org.gatein.wsrp.consumer.ConsumerException;
import org.gatein.wsrp.consumer.EndpointConfigurationInfo;
import org.gatein.wsrp.consumer.ProducerInfo;
+import org.gatein.wsrp.consumer.handlers.session.InMemorySessionRegistry;
+import org.gatein.wsrp.consumer.handlers.session.SessionRegistry;
+import org.gatein.wsrp.consumer.migration.InMemoryMigrationService;
import org.gatein.wsrp.consumer.migration.MigrationService;
-import org.gatein.wsrp.consumer.registry.ConsumerRegistry;
+import org.gatein.wsrp.consumer.spi.ConsumerRegistrySPI;
import java.util.ArrayList;
import java.util.Collection;
@@ -44,13 +47,15 @@
* @version $Revision: 12693 $
* @since 2.6
*/
-public class MockConsumerRegistry implements ConsumerRegistry
+public class MockConsumerRegistry implements ConsumerRegistrySPI
{
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";
public static final String CONSUMER2 = "inDB2";
+ private InMemorySessionRegistry sessionRegistry = new InMemorySessionRegistry();
+ private InMemoryMigrationService migrationService = new InMemoryMigrationService();
/**
* Creates a ConsumerRegistry containing 2 consumers with id '{@link
#CONSUMER1}' and '{@link #CONSUMER2}'
@@ -156,14 +161,24 @@
public MigrationService getMigrationService()
{
- return null; //To change body of implemented methods use File | Settings | File
Templates.
+ return migrationService;
}
public void setMigrationService(MigrationService migrationService)
{
- //To change body of implemented methods use File | Settings | File Templates.
+ throw new UnsupportedOperationException();
}
+ public SessionRegistry getSessionRegistry()
+ {
+ return sessionRegistry;
+ }
+
+ public void setSessionRegistry(SessionRegistry sessionRegistry)
+ {
+ throw new UnsupportedOperationException();
+ }
+
public boolean containsConsumer(String id)
{
return consumers.containsKey(id);
Modified:
components/wsrp/branches/clustering/consumer/src/test/java/org/gatein/wsrp/test/support/MockWSRPConsumer.java
===================================================================
---
components/wsrp/branches/clustering/consumer/src/test/java/org/gatein/wsrp/test/support/MockWSRPConsumer.java 2011-09-06
11:41:54 UTC (rev 7314)
+++
components/wsrp/branches/clustering/consumer/src/test/java/org/gatein/wsrp/test/support/MockWSRPConsumer.java 2011-09-06
20:55:01 UTC (rev 7315)
@@ -39,6 +39,7 @@
import org.gatein.wsrp.consumer.RefreshResult;
import org.gatein.wsrp.consumer.handlers.ProducerSessionInformation;
import org.gatein.wsrp.consumer.handlers.SessionHandler;
+import org.gatein.wsrp.consumer.handlers.session.SessionRegistry;
import org.gatein.wsrp.consumer.migration.ExportInfo;
import org.gatein.wsrp.consumer.migration.ImportInfo;
import org.gatein.wsrp.consumer.migration.MigrationService;
@@ -65,7 +66,7 @@
public MockWSRPConsumer(String id)
{
- producerInfo = new ProducerInfo();
+ producerInfo = new ProducerInfo(null);
producerInfo.setId(id);
producerInfo.setEndpointConfigurationInfo(new MockEndpointConfigurationInfo());
}
@@ -105,6 +106,16 @@
throw new NotYetImplemented();
}
+ public SessionRegistry getSessionRegistry()
+ {
+ throw new NotYetImplemented();
+ }
+
+ public void setSessionRegistry(SessionRegistry sessionInfos)
+ {
+ throw new NotYetImplemented();
+ }
+
public RegistrationContext getRegistrationContext() throws PortletInvokerException
{
throw new NotYetImplemented();
Modified:
components/wsrp/branches/clustering/jcr-impl/src/main/java/org/gatein/wsrp/consumer/migration/JCRMigrationService.java
===================================================================
---
components/wsrp/branches/clustering/jcr-impl/src/main/java/org/gatein/wsrp/consumer/migration/JCRMigrationService.java 2011-09-06
11:41:54 UTC (rev 7314)
+++
components/wsrp/branches/clustering/jcr-impl/src/main/java/org/gatein/wsrp/consumer/migration/JCRMigrationService.java 2011-09-06
20:55:01 UTC (rev 7315)
@@ -83,7 +83,7 @@
List<ExportInfo> exportInfos = new
ArrayList<ExportInfo>(exportInfoMappings.size());
for (ExportInfoMapping eim : exportInfoMappings)
{
- exportInfos.add(eim.toModel(null));
+ exportInfos.add(eim.toModel(null, null));
}
persister.closeSession(false);
@@ -115,7 +115,7 @@
{
if (eim != null)
{
- return eim.toModel(null);
+ return eim.toModel(null, null);
}
else
{
Modified:
components/wsrp/branches/clustering/jcr-impl/src/main/java/org/gatein/wsrp/consumer/migration/mapping/ExportInfoMapping.java
===================================================================
---
components/wsrp/branches/clustering/jcr-impl/src/main/java/org/gatein/wsrp/consumer/migration/mapping/ExportInfoMapping.java 2011-09-06
11:41:54 UTC (rev 7314)
+++
components/wsrp/branches/clustering/jcr-impl/src/main/java/org/gatein/wsrp/consumer/migration/mapping/ExportInfoMapping.java 2011-09-06
20:55:01 UTC (rev 7315)
@@ -45,7 +45,7 @@
* @version $Revision$
*/
@PrimaryType(name = ExportInfoMapping.NODE_NAME)
-public abstract class ExportInfoMapping implements BaseMapping<ExportInfo>
+public abstract class ExportInfoMapping implements BaseMapping<ExportInfo, Object>
{
public static final String NODE_NAME = "wsrp:exportinfo";
@@ -122,7 +122,7 @@
}
}
- public ExportInfo toModel(ExportInfo initial)
+ public ExportInfo toModel(ExportInfo initial, Object registry)
{
List<ExportedStateMapping> exportedStates = getExportedStates();
SortedMap<String, byte[]> states = new TreeMap<String, byte[]>();
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-06
11:41:54 UTC (rev 7314)
+++
components/wsrp/branches/clustering/jcr-impl/src/main/java/org/gatein/wsrp/consumer/registry/JCRConsumerRegistry.java 2011-09-06
20:55:01 UTC (rev 7315)
@@ -194,7 +194,7 @@
persister.closeSession(true);
- return new MappingToProducerInfoIterator(mappings.iterator());
+ return new MappingToProducerInfoIterator(mappings.iterator(), this);
}
@Override
@@ -207,7 +207,7 @@
if (pim != null)
{
- return pim.toModel(null);
+ return pim.toModel(null, this);
}
else
{
@@ -381,10 +381,12 @@
private static class MappingToProducerInfoIterator implements
Iterator<ProducerInfo>
{
private Iterator<ProducerInfoMapping> mappings;
+ private final JCRConsumerRegistry registry;
- public MappingToProducerInfoIterator(Iterator<ProducerInfoMapping>
infoMappingIterator)
+ public MappingToProducerInfoIterator(Iterator<ProducerInfoMapping>
infoMappingIterator, JCRConsumerRegistry jcrConsumerRegistry)
{
this.mappings = infoMappingIterator;
+ this.registry = jcrConsumerRegistry;
}
public boolean hasNext()
@@ -394,7 +396,7 @@
public ProducerInfo next()
{
- return mappings.next().toModel(null);
+ return mappings.next().toModel(null, registry);
}
public void remove()
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-09-06
11:41:54 UTC (rev 7314)
+++
components/wsrp/branches/clustering/jcr-impl/src/main/java/org/gatein/wsrp/consumer/registry/mapping/ProducerInfoMapping.java 2011-09-06
20:55:01 UTC (rev 7315)
@@ -33,6 +33,7 @@
import org.gatein.wsrp.consumer.EndpointConfigurationInfo;
import org.gatein.wsrp.consumer.ProducerInfo;
import org.gatein.wsrp.consumer.RegistrationInfo;
+import org.gatein.wsrp.consumer.spi.ConsumerRegistrySPI;
import org.gatein.wsrp.jcr.mapping.BaseMapping;
/**
@@ -40,7 +41,7 @@
* @version $Revision$
*/
@PrimaryType(name = ProducerInfoMapping.NODE_NAME)
-public abstract class ProducerInfoMapping implements BaseMapping<ProducerInfo>
+public abstract class ProducerInfoMapping implements BaseMapping<ProducerInfo,
ConsumerRegistrySPI>
{
public static final String NODE_NAME = "wsrp:producerinfo";
@@ -92,13 +93,13 @@
rim.initFrom(regInfo);
}
- public ProducerInfo toModel(ProducerInfo initial)
+ public ProducerInfo toModel(ProducerInfo initial, ConsumerRegistrySPI registry)
{
// todo: should probably use a ProducerInfo implementation backed by mapping at
some point
ProducerInfo info = initial;
if (initial == null)
{
- info = new ProducerInfo();
+ info = new ProducerInfo(registry);
}
// basic properties
Modified:
components/wsrp/branches/clustering/jcr-impl/src/main/java/org/gatein/wsrp/jcr/mapping/BaseMapping.java
===================================================================
---
components/wsrp/branches/clustering/jcr-impl/src/main/java/org/gatein/wsrp/jcr/mapping/BaseMapping.java 2011-09-06
11:41:54 UTC (rev 7314)
+++
components/wsrp/branches/clustering/jcr-impl/src/main/java/org/gatein/wsrp/jcr/mapping/BaseMapping.java 2011-09-06
20:55:01 UTC (rev 7315)
@@ -27,9 +27,9 @@
* @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
* @version $Revision$
*/
-public interface BaseMapping<T>
+public interface BaseMapping<T, R>
{
void initFrom(T model);
- T toModel(T initial);
+ T toModel(T initial, R registry);
}