Author: chris.laprun(a)jboss.com
Date: 2007-07-16 22:48:08 -0400 (Mon, 16 Jul 2007)
New Revision: 7791
Modified:
trunk/core-wsrp/src/main/org/jboss/portal/wsrp/admin/ui/ConsumerBean.java
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/consumer/ProducerInfoTestCase.java
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/consumer/RegistrationInfoTestCase.java
trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/ProducerInfo.java
trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/RegistrationInfo.java
Log:
- JBPORTAL-1585: modifyRegistration and deregister now properly invalidate
ProducerInfo's cache.
- JBPORTAL-1587: Added RegistrationInfo.setModified to be able to properly refresh
RegistrationData as we cannot currently make it dirty from ConsumerBean.regPropListener.
- Fixed an issue where update and refreshConsumer in ConsumerBean would not properly
detect that a refresh is needed.
- Added test cases.
Modified: trunk/core-wsrp/src/main/org/jboss/portal/wsrp/admin/ui/ConsumerBean.java
===================================================================
--- trunk/core-wsrp/src/main/org/jboss/portal/wsrp/admin/ui/ConsumerBean.java 2007-07-17
02:23:34 UTC (rev 7790)
+++ trunk/core-wsrp/src/main/org/jboss/portal/wsrp/admin/ui/ConsumerBean.java 2007-07-17
02:48:08 UTC (rev 7791)
@@ -250,31 +250,32 @@
public String update()
{
- if (consumer != null && modified)
+ if (consumer != null)
{
- try
+ if (isModified())
{
- // update values
- ProducerInfo prodInfo = getProducerInfo();
- EndpointConfigurationInfo endpointInfo =
prodInfo.getEndpointConfigurationInfo();
- endpointInfo.setMarkupURL(markup);
- endpointInfo.setServiceDescriptionURL(serviceDescription);
- endpointInfo.setPortletManagementURL(portletManagement);
- endpointInfo.setRegistrationURL(registration);
- if (isUseWSDL())
+ try
{
- internalSetWsdl(wsdl);
+ // update values
+ ProducerInfo prodInfo = getProducerInfo();
+ EndpointConfigurationInfo endpointInfo =
prodInfo.getEndpointConfigurationInfo();
+ endpointInfo.setMarkupURL(markup);
+ endpointInfo.setServiceDescriptionURL(serviceDescription);
+ endpointInfo.setPortletManagementURL(portletManagement);
+ endpointInfo.setRegistrationURL(registration);
+ if (isUseWSDL())
+ {
+ internalSetWsdl(wsdl);
+ }
+
+ saveToRegistry(prodInfo);
}
-
- registry.updateProducerInfo(prodInfo);
- modified = false;
- registrationModified = false;
+ catch (Exception e)
+ {
+ beanContext.createErrorMessageFrom(e);
+ return null;
+ }
}
- catch (Exception e)
- {
- beanContext.createErrorMessageFrom(e);
- return null;
- }
return manager.listConsumers();
}
@@ -283,9 +284,16 @@
return null;
}
+ private void saveToRegistry(ProducerInfo prodInfo)
+ {
+ registry.updateProducerInfo(prodInfo);
+ modified = false;
+ registrationModified = false;
+ }
+
public String refreshConsumer()
{
- if (modified)
+ if (isModified())
{
String updateResult = update();
if (updateResult == null)
@@ -333,18 +341,32 @@
{
if (consumer != null)
{
- try
+ if (registrationModified)
{
- getProducerInfo().modifyRegistration();
- beanContext.createInfoMessage(null, "Successfully modified
Registration!");
- registrationModified = false;
+ try
+ {
+ ProducerInfo info = getProducerInfo();
+ saveToRegistry(info); // make sure we save any modified registration
properties
+
+ // todo: this should be done better cf regPropListener
+ getProducerInfo().getRegistrationInfo().setModified(true); // mark as
modified to force refresh of RegistrationData
+ info.modifyRegistration();
+ getProducerInfo().getRegistrationInfo().setModified(false);
+
+ beanContext.createInfoMessage(null, "Successfully modified
Registration!");
+ registrationModified = false;
+ }
+ catch (Exception e)
+ {
+ beanContext.createErrorMessageFrom(e);
+ return null;
+ }
+ return null;
}
- catch (Exception e)
+ else
{
- beanContext.createErrorMessageFrom(e);
- return null;
+ beanContext.createErrorMessage("Invalid attempt to modify a Registration
that hasn't been locally modified!");
}
- return null;
}
beanContext.createErrorMessage("Couldn't modify Registration!");
@@ -387,9 +409,11 @@
public void regPropListener(ValueChangeEvent event)
{
+ // todo: should use modifyIfNeeded but it might be tricky as the name of the
property that has been changed
+ // cannot be easily retrieved (we cannot use it as an id directly), could use title
but that would be hackish
registrationModified = true;
// bypass the rest of the life cycle and re-display page
FacesContext.getCurrentInstance().renderResponse();
}
-}
\ No newline at end of file
+}
Modified:
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/consumer/ProducerInfoTestCase.java
===================================================================
---
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/consumer/ProducerInfoTestCase.java 2007-07-17
02:23:34 UTC (rev 7790)
+++
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/consumer/ProducerInfoTestCase.java 2007-07-17
02:48:08 UTC (rev 7791)
@@ -274,7 +274,10 @@
info.modifyRegistration();
- assertFalse(info.isRefreshNeeded(false));
+ assertTrue(info.isRefreshNeeded(true)); // cache should have been invalidated
+ assertFalse(info.isRefreshNeeded(false)); // but the rest of the information is
valid so no refresh needed there
+ assertTrue(info.refresh(false)); // however, if we refresh the producer info, it
should have refreshed
+
Boolean invalid = prop.isInvalid();
assertNotNull(invalid);
assertFalse(invalid.booleanValue());
Modified:
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/consumer/RegistrationInfoTestCase.java
===================================================================
---
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/consumer/RegistrationInfoTestCase.java 2007-07-17
02:23:34 UTC (rev 7790)
+++
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/consumer/RegistrationInfoTestCase.java 2007-07-17
02:48:08 UTC (rev 7791)
@@ -29,7 +29,9 @@
import org.jboss.portal.wsrp.consumer.RefreshResult;
import org.jboss.portal.wsrp.consumer.RegistrationInfo;
import org.jboss.portal.wsrp.consumer.RegistrationProperty;
+import org.jboss.portal.wsrp.core.Property;
import org.jboss.portal.wsrp.core.RegistrationContext;
+import org.jboss.portal.wsrp.core.RegistrationData;
import org.jboss.portal.wsrp.core.ServiceDescription;
import java.util.Map;
@@ -284,6 +286,30 @@
assertFalse(info.isRegistrationDeterminedNotRequired());
}
+ public void testGetRegistrationData()
+ {
+ assertNotNull(info.getRegistrationData());
+ assertFalse(info.isModified());
+
+ info.setRegistrationPropertyValue("prop0", "value0");
+ assertTrue(info.isModified());
+ RegistrationData registrationData = info.getRegistrationData();
+ assertNotNull(registrationData);
+ Property[] properties = registrationData.getRegistrationProperties();
+ assertNotNull(properties);
+ assertEquals(1, properties.length);
+ assertEquals("prop0", properties[0].getName());
+ assertEquals("value0", properties[0].getStringValue());
+
+ // check that setRegistrationValidInternalState properly updates RegistrationData
if required
+ info.setRegistrationPropertyValue("prop0", "value1");
+ assertTrue(info.isModified());
+ info.setRegistrationValidInternalState();
+ assertFalse(info.isModified());
+ properties = info.getRegistrationData().getRegistrationProperties();
+ assertEquals("value1", properties[0].getStringValue());
+ }
+
private ServiceDescription createServiceDescription(boolean requiresRegistration, int
numberOfProperties)
{
return ServiceDescriptionBehavior.createServiceDescription(requiresRegistration,
numberOfProperties);
Modified: trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/ProducerInfo.java
===================================================================
--- trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/ProducerInfo.java 2007-07-17
02:23:34 UTC (rev 7790)
+++ trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/ProducerInfo.java 2007-07-17
02:48:08 UTC (rev 7791)
@@ -749,6 +749,8 @@
persistentEndpointInfo.getRegistrationService().deregister(getRegistrationContext());
persistentRegistrationInfo.resetRegistration();
log.info("Consumer with id '" + persistentId + "'
deregistered.");
+
+ invalidateCache();
}
catch (Exception e)
{
@@ -787,6 +789,9 @@
persistentRegistrationInfo.setRegistrationState(state.getRegistrationState());
}
log.info("Consumer with id '" + persistentId + "'
sucessfully modified its registration.");
+
+ // reset cache to be able to see new offered portlets on the next refresh
+ invalidateCache();
}
catch (Exception e)
{
@@ -804,6 +809,14 @@
}
}
+ private void invalidateCache()
+ {
+ if (useCache())
+ {
+ expirationTimeMillis = System.currentTimeMillis();
+ }
+ }
+
public RefreshResult refreshRegistrationInfo(boolean mergeWithLocalInfo) throws
PortletInvokerException
{
return internalRefreshRegistration(getServiceDescription(true), mergeWithLocalInfo,
true);
Modified: trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/RegistrationInfo.java
===================================================================
--- trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/RegistrationInfo.java 2007-07-17
02:23:34 UTC (rev 7790)
+++ trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/RegistrationInfo.java 2007-07-17
02:48:08 UTC (rev 7791)
@@ -214,7 +214,7 @@
}
}
- registrationData.setRegistrationProperties((Property[])properties.toArray(new
Property[0]));
+ registrationData.setRegistrationProperties((Property[])properties.toArray(new
Property[regProps.size()]));
}
}
@@ -530,11 +530,11 @@
setRegistrationValidInternalState();
}
- void setRegistrationValidInternalState()
+ /** todo: revert to package-only once the tests are moved to same package */
+ public void setRegistrationValidInternalState()
{
- consistentWithProducerExpectations = Boolean.TRUE; // since we have a registration
context, we're consistent with the Producer
- requiresRegistration = Boolean.TRUE; // we know we require registration
- dirty = false; // our state is clean :)
+ // update RegistrationData if needed
+ getRegistrationData();
// mark the registration properties as valid
if (persistentRegistrationProperties != null)
@@ -545,6 +545,10 @@
prop.setInvalid(Boolean.FALSE, null);
}
}
+
+ consistentWithProducerExpectations = Boolean.TRUE; // since we have a registration
context, we're consistent with the Producer
+ requiresRegistration = Boolean.TRUE; // we know we require registration
+ dirty = false; // our state is clean :)
}
public RegistrationContext getRegistrationContext()
@@ -566,6 +570,11 @@
return dirty;
}
+ public void setModified(boolean modified)
+ {
+ this.dirty = modified;
+ }
+
public class RegistrationRefreshResult extends RefreshResult
{
public RegistrationRefreshResult()