Author: chris.laprun(a)jboss.com
Date: 2010-01-06 10:29:57 -0500 (Wed, 06 Jan 2010)
New Revision: 1176
Modified:
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/AbstractRegistrationPersistenceManager.java
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/Consumer.java
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/impl/ConsumerImpl.java
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/RegistrationHandler.java
components/wsrp/trunk/producer/src/test/java/org/gatein/registration/ConsumerTestCase.java
components/wsrp/trunk/producer/src/test/java/org/gatein/registration/RegistrationManagerTestCase.java
Log:
- Consumer status is now computed from registrations' status.
Modified:
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/AbstractRegistrationPersistenceManager.java
===================================================================
---
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/AbstractRegistrationPersistenceManager.java 2010-01-06
15:27:28 UTC (rev 1175)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/AbstractRegistrationPersistenceManager.java 2010-01-06
15:29:57 UTC (rev 1176)
@@ -42,7 +42,6 @@
ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(consumerName,
"Consumer name", null);
ConsumerSPI consumer = internalCreateConsumer(consumerId, consumerName);
- consumer.setStatus(RegistrationStatus.PENDING);
internalAddConsumer(consumer);
return consumer;
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 2010-01-06
15:27:28 UTC (rev 1175)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/Consumer.java 2010-01-06
15:29:57 UTC (rev 1176)
@@ -51,13 +51,6 @@
RegistrationStatus getStatus();
/**
- * Set the registration status of the consumer entity.
- *
- * @param status the registration status
- */
- void setStatus(RegistrationStatus status);
-
- /**
* Return all the registrations for the specified consumer.
*
* @return the consumer registrations
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 2010-01-06
15:27:28 UTC (rev 1175)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/impl/ConsumerImpl.java 2010-01-06
15:29:57 UTC (rev 1176)
@@ -50,7 +50,6 @@
private String identity;
private String consumerAgent;
private Set<Registration> registrations;
- private RegistrationStatus status;
private ConsumerGroup group;
private ConsumerCapabilities capabilities;
private String key;
@@ -74,7 +73,6 @@
private void init()
{
registrations = new HashSet<Registration>(7);
- status = RegistrationStatus.PENDING;
capabilities = new ConsumerCapabilitiesImpl();
}
@@ -142,13 +140,27 @@
public RegistrationStatus getStatus()
{
- return status;
- }
+ if (ParameterValidation.existsAndIsNotEmpty(registrations))
+ {
+ RegistrationStatus result = RegistrationStatus.VALID;
+ for (Registration registration : registrations)
+ {
+ RegistrationStatus status = registration.getStatus();
- public void setStatus(RegistrationStatus status)
- {
- ParameterValidation.throwIllegalArgExceptionIfNull(status,
"RegistrationStatus");
- this.status = status;
+ // anytime an invalid registration is found, that makes the consumer invalid
as well, no need for further processing
+ if (RegistrationStatus.INVALID == status)
+ {
+ return RegistrationStatus.INVALID;
+ }
+ else if (RegistrationStatus.PENDING == status)
+ {
+ result = status;
+ }
+ }
+
+ return result;
+ }
+ return RegistrationStatus.PENDING;
}
public Collection<Registration> getRegistrations() throws RegistrationException
@@ -178,12 +190,6 @@
ParameterValidation.throwIllegalArgExceptionIfNull(registration,
"Registration");
registrations.remove(registration);
-
- // status should become pending if there are no registrations
- if (registrations.isEmpty())
- {
- setStatus(RegistrationStatus.PENDING);
- }
}
public void setGroup(ConsumerGroup group) throws RegistrationException
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 2010-01-06
15:27:28 UTC (rev 1175)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/RegistrationHandler.java 2010-01-06
15:29:57 UTC (rev 1176)
@@ -113,7 +113,6 @@
registration.setStatus(RegistrationStatus.VALID);
Consumer consumer = registration.getConsumer();
consumer.setConsumerAgent(registrationData.getConsumerAgent());
- consumer.setStatus(RegistrationStatus.VALID);
ConsumerCapabilities capabilities = consumer.getCapabilities();
List<String> modeStrings = registrationData.getConsumerModes();
Modified:
components/wsrp/trunk/producer/src/test/java/org/gatein/registration/ConsumerTestCase.java
===================================================================
---
components/wsrp/trunk/producer/src/test/java/org/gatein/registration/ConsumerTestCase.java 2010-01-06
15:27:28 UTC (rev 1175)
+++
components/wsrp/trunk/producer/src/test/java/org/gatein/registration/ConsumerTestCase.java 2010-01-06
15:29:57 UTC (rev 1176)
@@ -28,6 +28,11 @@
import org.gatein.registration.impl.RegistrationPersistenceManagerImpl;
import org.gatein.registration.policies.DefaultRegistrationPolicy;
+import javax.xml.namespace.QName;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
/**
* @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
* @version $Revision: 8784 $
@@ -53,24 +58,39 @@
assertEquals("name", consumer.getName());
}
- public void testStatus()
+ public void testStatus() throws RegistrationException
{
assertEquals(RegistrationStatus.PENDING, consumer.getStatus());
- consumer.setStatus(RegistrationStatus.VALID);
+ String name = consumer.getName();
+
+ // adding a registration that isn't validated doesn't change the status
+ Registration registration = manager.addRegistrationTo(name, Collections.<QName,
Object>emptyMap(), false);
+ assertEquals(RegistrationStatus.PENDING, consumer.getStatus());
+
+ // but the consumer's status should become valid if the registration becomes so
as well
+ registration.setStatus(RegistrationStatus.VALID);
assertEquals(RegistrationStatus.VALID, consumer.getStatus());
- }
- public void testIllegalStatus()
- {
- try
- {
- consumer.setStatus(null);
- fail("Was expecting an IllegalArgumentException to be thrown on
setStatus(null)");
- }
- catch (IllegalArgumentException expected)
- {
- }
+ // adding a new registration makes the consumer's status pending
+ // need to change the registration props to register this consumer again
+ Map<QName, Object> props = new HashMap<QName, Object>(1);
+ props.put(new QName("prop"), "value");
+ registration = manager.addRegistrationTo(name, props, false);
+ assertEquals(2, consumer.getRegistrations().size());
+ assertEquals(RegistrationStatus.PENDING, consumer.getStatus());
+
+ // and if the new registration is marked as invalid, so does the consumer's
status
+ registration.setStatus(RegistrationStatus.INVALID);
+ assertEquals(RegistrationStatus.INVALID, consumer.getStatus());
+
+ // if the registration is returned to pending, then so is the consumer
+ registration.setStatus(RegistrationStatus.PENDING);
+ assertEquals(RegistrationStatus.PENDING, consumer.getStatus());
+
+ // if all the registrations are valid, then so is the consumer
+ registration.setStatus(RegistrationStatus.VALID);
+ assertEquals(RegistrationStatus.VALID, consumer.getStatus());
}
public void testSetGroup() throws Exception
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 2010-01-06
15:27:28 UTC (rev 1175)
+++
components/wsrp/trunk/producer/src/test/java/org/gatein/registration/RegistrationManagerTestCase.java 2010-01-06
15:29:57 UTC (rev 1176)
@@ -320,9 +320,6 @@
assertTrue(consumer.getRegistrations().contains(reg));
- // set the consumer status to valid
- consumer.setStatus(RegistrationStatus.VALID);
-
manager.removeRegistration(handle);
assertTrue(!consumer.getRegistrations().contains(reg));
assertNull(manager.getRegistration(handle));