Author: chris.laprun(a)jboss.com
Date: 2009-12-03 17:53:18 -0500 (Thu, 03 Dec 2009)
New Revision: 918
Modified:
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/Consumer.java
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/ConsumerGroup.java
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/Registration.java
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/impl/ConsumerGroupImpl.java
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/impl/ConsumerImpl.java
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/impl/RegistrationImpl.java
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/impl/RegistrationManagerImpl.java
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/impl/RegistrationPersistenceManagerImpl.java
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/spi/ConsumerGroupSPI.java
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/spi/ConsumerSPI.java
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/RegistrationHandler.java
components/wsrp/trunk/producer/src/test/java/org/gatein/registration/AbstractRegistrationPersistenceManagerTestCase.java
components/wsrp/trunk/producer/src/test/java/org/gatein/registration/RegistrationManagerTestCase.java
components/wsrp/trunk/producer/src/test/java/org/gatein/wsrp/protocol/v1/RegistrationTestCase.java
Log:
- Renamed Registration.getId to getPersistentKey to be consistent and avoid confusion with
Consumer.getId
- Added factory methods on RegistrationPersistenceManagerImpl to allow retrieval of new
objects without triggering creation of associations and persistence.
- Fixed improper RegistrationContext in RegistrationHandler (which should have been using
Registration.getRegistrationHandle instead of getPersistentKey)
and added associated test case. Note that the case would have passed before but it was
just an implementation coincidence.
- Added persistent key concept on both ConsumerSPI and ConsumerGroupSPI to be able to deal
with persistence better.
Modified:
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/Consumer.java
===================================================================
---
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/Consumer.java 2009-12-03
13:12:31 UTC (rev 917)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/Consumer.java 2009-12-03
22:53:18 UTC (rev 918)
@@ -90,4 +90,11 @@
String getConsumerAgent();
void setConsumerAgent(String consumerAgent) throws IllegalArgumentException,
IllegalStateException;
+
+ /**
+ * Retrieves this Consumer's internal persistent key which would correspond to a
primary key in a database.
+ *
+ * @return
+ */
+ String getPersistentKey();
}
Modified:
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/ConsumerGroup.java
===================================================================
---
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/ConsumerGroup.java 2009-12-03
13:12:31 UTC (rev 917)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/ConsumerGroup.java 2009-12-03
22:53:18 UTC (rev 918)
@@ -43,6 +43,13 @@
String getName();
/**
+ * Return this ConsumerGroup's persistent identifier.
+ *
+ * @return this ConsumerGroup's persistent identifier
+ */
+ String getPersistentKey();
+
+ /**
* Return a collection of associated consumers.
*
* @return the consumer collection
Modified:
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/Registration.java
===================================================================
---
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/Registration.java 2009-12-03
13:12:31 UTC (rev 917)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/Registration.java 2009-12-03
22:53:18 UTC (rev 918)
@@ -42,7 +42,7 @@
*
* @return this Registration's internal identifier.
*/
- String getId();
+ String getPersistentKey();
/**
* Sets the handle for this Registration.
Modified:
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/impl/ConsumerGroupImpl.java
===================================================================
---
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/impl/ConsumerGroupImpl.java 2009-12-03
13:12:31 UTC (rev 917)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/impl/ConsumerGroupImpl.java 2009-12-03
22:53:18 UTC (rev 918)
@@ -40,7 +40,7 @@
*/
public class ConsumerGroupImpl implements ConsumerGroupSPI
{
-
+ private String key;
private String name;
private Map<String, Consumer> consumers;
private RegistrationStatus status;
@@ -68,7 +68,16 @@
return name;
}
+ public String getPersistentKey()
+ {
+ return key;
+ }
+ public void setPersistentKey(String id)
+ {
+ this.key = id;
+ }
+
public boolean equals(Object o)
{
if (this == o)
Modified:
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/impl/ConsumerImpl.java
===================================================================
---
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/impl/ConsumerImpl.java 2009-12-03
13:12:31 UTC (rev 917)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/impl/ConsumerImpl.java 2009-12-03
22:53:18 UTC (rev 918)
@@ -53,6 +53,7 @@
private RegistrationStatus status;
private ConsumerGroup group;
private ConsumerCapabilities capabilities;
+ private String key;
private ConsumerImpl()
@@ -124,6 +125,11 @@
}
}
+ public String getPersistentKey()
+ {
+ return key;
+ }
+
public ConsumerCapabilities getCapabilities()
{
return capabilities;
@@ -162,6 +168,11 @@
registrations.add(registration);
}
+ public void setPersistentKey(String key)
+ {
+ this.key = key;
+ }
+
public void removeRegistration(RegistrationSPI registration) throws
RegistrationException
{
ParameterValidation.throwIllegalArgExceptionIfNull(registration,
"Registration");
Modified:
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/impl/RegistrationImpl.java
===================================================================
---
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/impl/RegistrationImpl.java 2009-12-03
13:12:31 UTC (rev 917)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/impl/RegistrationImpl.java 2009-12-03
22:53:18 UTC (rev 918)
@@ -42,24 +42,24 @@
public class RegistrationImpl implements RegistrationSPI
{
- private final String id;
+ private final String key;
private ConsumerSPI consumer;
private RegistrationStatus status;
private Map<QName, Object> properties;
private String registrationHandle;
- public RegistrationImpl(String id, ConsumerSPI consumer, RegistrationStatus status,
Map properties)
+ public RegistrationImpl(String key, ConsumerSPI consumer, RegistrationStatus status,
Map properties)
{
- this.id = id;
+ this.key = key;
this.consumer = consumer;
this.status = status;
this.properties = new HashMap<QName, Object>(properties);
}
- public String getId()
+ public String getPersistentKey()
{
- return id;
+ return key;
}
public void setRegistrationHandle(String handle)
Modified:
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/impl/RegistrationManagerImpl.java
===================================================================
---
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/impl/RegistrationManagerImpl.java 2009-12-03
13:12:31 UTC (rev 917)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/impl/RegistrationManagerImpl.java 2009-12-03
22:53:18 UTC (rev 918)
@@ -28,13 +28,13 @@
import org.gatein.registration.ConsumerGroup;
import org.gatein.registration.InvalidConsumerDataException;
import org.gatein.registration.NoSuchRegistrationException;
-import org.gatein.wsrp.registration.PropertyDescription;
import org.gatein.registration.Registration;
import org.gatein.registration.RegistrationException;
import org.gatein.registration.RegistrationManager;
import org.gatein.registration.RegistrationPersistenceManager;
import org.gatein.registration.RegistrationPolicy;
import org.gatein.registration.RegistrationStatus;
+import org.gatein.wsrp.registration.PropertyDescription;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -97,7 +97,7 @@
Registration registration = persistenceManager.addRegistrationFor(identity,
registrationProperties);
// let the policy decide what the handle should be
- String handle = policy.createRegistrationHandleFor(registration.getId());
+ String handle =
policy.createRegistrationHandleFor(registration.getPersistentKey());
registration.setRegistrationHandle(handle);
return registration;
@@ -236,7 +236,7 @@
registration.setStatus(RegistrationStatus.INVALID); // just in case...
// registration.clearAssociatedState(); // todo: do we need to clear associated
state?
- persistenceManager.removeRegistration(registration.getId());
+ persistenceManager.removeRegistration(registration.getPersistentKey());
}
public ConsumerGroup getConsumerGroup(String groupName) throws RegistrationException
Modified:
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/impl/RegistrationPersistenceManagerImpl.java
===================================================================
---
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/impl/RegistrationPersistenceManagerImpl.java 2009-12-03
13:12:31 UTC (rev 917)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/impl/RegistrationPersistenceManagerImpl.java 2009-12-03
22:53:18 UTC (rev 918)
@@ -90,7 +90,7 @@
@Override
protected void internalAddRegistration(RegistrationSPI registration)
{
- registrations.put(registration.getId(), registration);
+ registrations.put(registration.getPersistentKey(), registration);
}
@Override
@@ -102,9 +102,14 @@
@Override
protected RegistrationSPI internalCreateRegistration(ConsumerSPI consumer, Map
registrationProperties)
{
- return new RegistrationImpl("" + lastRegistrationId++, consumer,
RegistrationStatus.PENDING, registrationProperties);
+ return newRegistrationSPI(consumer, registrationProperties, "" +
lastRegistrationId++);
}
+ public RegistrationSPI newRegistrationSPI(ConsumerSPI consumer, Map
registrationProperties, String registrationKey)
+ {
+ return new RegistrationImpl(registrationKey, consumer, RegistrationStatus.PENDING,
registrationProperties);
+ }
+
@Override
protected void internalAddConsumer(ConsumerSPI consumer)
{
@@ -120,6 +125,11 @@
@Override
protected ConsumerSPI internalCreateConsumer(String consumerId, String consumerName)
{
+ return newConsumerSPI(consumerId, consumerName);
+ }
+
+ public ConsumerSPI newConsumerSPI(String consumerId, String consumerName)
+ {
return new ConsumerImpl(consumerId, consumerName);
}
@@ -138,6 +148,11 @@
@Override
protected ConsumerGroupSPI internalCreateConsumerGroup(String name)
{
+ return newConsumerGroupSPI(name);
+ }
+
+ public ConsumerGroupSPI newConsumerGroupSPI(String name)
+ {
return new ConsumerGroupImpl(name);
}
Modified:
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/spi/ConsumerGroupSPI.java
===================================================================
---
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/spi/ConsumerGroupSPI.java 2009-12-03
13:12:31 UTC (rev 917)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/spi/ConsumerGroupSPI.java 2009-12-03
22:53:18 UTC (rev 918)
@@ -30,4 +30,6 @@
*/
public interface ConsumerGroupSPI extends ConsumerGroup
{
+
+ void setPersistentKey(String id);
}
Modified:
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/spi/ConsumerSPI.java
===================================================================
---
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/spi/ConsumerSPI.java 2009-12-03
13:12:31 UTC (rev 917)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/spi/ConsumerSPI.java 2009-12-03
22:53:18 UTC (rev 918)
@@ -34,4 +34,6 @@
void removeRegistration(RegistrationSPI registration) throws RegistrationException;
void addRegistration(RegistrationSPI registration);
+
+ void setPersistentKey(String key);
}
Modified:
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/RegistrationHandler.java
===================================================================
---
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/RegistrationHandler.java 2009-12-03
13:12:31 UTC (rev 917)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/RegistrationHandler.java 2009-12-03
22:53:18 UTC (rev 918)
@@ -23,9 +23,9 @@
package org.gatein.wsrp.producer;
+import org.gatein.common.util.ParameterValidation;
import org.gatein.pc.api.Mode;
import org.gatein.pc.api.WindowState;
-import org.gatein.common.util.ParameterValidation;
import org.gatein.registration.Consumer;
import org.gatein.registration.ConsumerCapabilities;
import org.gatein.registration.NoSuchRegistrationException;
@@ -99,7 +99,7 @@
msg, e);
}
- RegistrationContext registrationContext =
WSRPTypeFactory.createRegistrationContext(registration.getId());
+ RegistrationContext registrationContext =
WSRPTypeFactory.createRegistrationContext(registration.getRegistrationHandle());
log.debug("Registration completed without error.");
return registrationContext;
}
Modified:
components/wsrp/trunk/producer/src/test/java/org/gatein/registration/AbstractRegistrationPersistenceManagerTestCase.java
===================================================================
---
components/wsrp/trunk/producer/src/test/java/org/gatein/registration/AbstractRegistrationPersistenceManagerTestCase.java 2009-12-03
13:12:31 UTC (rev 917)
+++
components/wsrp/trunk/producer/src/test/java/org/gatein/registration/AbstractRegistrationPersistenceManagerTestCase.java 2009-12-03
22:53:18 UTC (rev 918)
@@ -302,7 +302,7 @@
consumer = getManager().getConsumerById("Bar");
Registration reg1 = getManager().addRegistrationFor("Bar",
registrationProperties);
assertNotNull(reg1);
- String regId = reg1.getId();
+ String regId = reg1.getPersistentKey();
assertNotNull(regId);
assertEquals(consumer, reg1.getConsumer());
Map expectedProps = new HashMap();
@@ -318,7 +318,7 @@
assertNotNull(registrations);
assertEquals(1, registrations.size());
Registration reg3 = (Registration)registrations.iterator().next();
- assertEquals(regId, reg3.getId());
+ assertEquals(regId, reg3.getPersistentKey());
assertEquals(consumer, reg3.getConsumer());
assertEquals(expectedProps, reg3.getProperties());
stopInteraction();
@@ -328,7 +328,7 @@
Registration reg2 = getManager().getRegistration(regId);
consumer = getManager().getConsumerById("Bar");
assertNotNull(reg2);
- assertEquals(regId, reg2.getId());
+ assertEquals(regId, reg2.getPersistentKey());
assertEquals(consumer, reg2.getConsumer());
assertEquals(expectedProps, reg2.getProperties());
stopInteraction();
@@ -373,7 +373,7 @@
Consumer consumer = getManager().createConsumer("Bar", "Bar");
group.addConsumer(consumer);
Registration reg = getManager().addRegistrationFor("Bar",
registrationProperties);
- String regId = reg.getId();
+ String regId = reg.getPersistentKey();
getManager().removeRegistration(regId);
stopInteraction();
Modified:
components/wsrp/trunk/producer/src/test/java/org/gatein/registration/RegistrationManagerTestCase.java
===================================================================
---
components/wsrp/trunk/producer/src/test/java/org/gatein/registration/RegistrationManagerTestCase.java 2009-12-03
13:12:31 UTC (rev 917)
+++
components/wsrp/trunk/producer/src/test/java/org/gatein/registration/RegistrationManagerTestCase.java 2009-12-03
22:53:18 UTC (rev 918)
@@ -70,7 +70,7 @@
{
Registration registration = manager.addRegistrationTo("consumerName",
registrationProperties, true);
assertNotNull(registration);
- assertNotNull(registration.getId());
+ assertNotNull(registration.getPersistentKey());
Consumer consumer = manager.getConsumerByIdentity("consumerName");
assertNotNull(consumer); // default policy: name == identity
Modified:
components/wsrp/trunk/producer/src/test/java/org/gatein/wsrp/protocol/v1/RegistrationTestCase.java
===================================================================
---
components/wsrp/trunk/producer/src/test/java/org/gatein/wsrp/protocol/v1/RegistrationTestCase.java 2009-12-03
13:12:31 UTC (rev 917)
+++
components/wsrp/trunk/producer/src/test/java/org/gatein/wsrp/protocol/v1/RegistrationTestCase.java 2009-12-03
22:53:18 UTC (rev 918)
@@ -23,6 +23,9 @@
package org.gatein.wsrp.protocol.v1;
+import org.gatein.registration.Registration;
+import org.gatein.registration.RegistrationException;
+import org.gatein.registration.RegistrationManager;
import org.gatein.wsrp.WSRPConstants;
import org.gatein.wsrp.WSRPTypeFactory;
import org.gatein.wsrp.WSRPUtils;
@@ -31,6 +34,7 @@
import org.oasis.wsrp.v1.GetMarkup;
import org.oasis.wsrp.v1.GetServiceDescription;
import org.oasis.wsrp.v1.InvalidRegistration;
+import org.oasis.wsrp.v1.MissingParameters;
import org.oasis.wsrp.v1.ModifyRegistration;
import org.oasis.wsrp.v1.OperationFailed;
import org.oasis.wsrp.v1.PropertyDescription;
@@ -93,6 +97,27 @@
registrationService.register(regData);
}
+ public void testRegistrationHandle() throws OperationFailed, MissingParameters,
RegistrationException
+ {
+ // check that a registration handle was created
+ RegistrationContext rc = registerConsumer();
+ String registrationHandle = rc.getRegistrationHandle();
+ assertNotNull(registrationHandle);
+
+ // check that a registration was created with that handle
+ RegistrationManager registrationManager = producer.getRegistrationManager();
+ Registration registration =
registrationManager.getRegistration(registrationHandle);
+ assertNotNull(registration);
+
+ // check that the registration was persisted...
+ String key = registration.getPersistentKey();
+ assertNotNull(key);
+
+ // ... and that the handle was created by the policy based on the registration key
+ String expectedHandle =
registrationManager.getPolicy().createRegistrationHandleFor(key);
+ assertEquals(expectedHandle, registrationHandle);
+ }
+
public void testDeregister() throws Exception
{
// initiate registration