Author: chris.laprun(a)jboss.com
Date: 2007-02-19 13:09:29 -0500 (Mon, 19 Feb 2007)
New Revision: 6343
Modified:
trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/ProducerInfo.java
trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/RegistrationInfo.java
Log:
- Improvements to refresh method.
- Started cleaning-up code to move to persistent implementation.
Modified: trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/ProducerInfo.java
===================================================================
--- trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/ProducerInfo.java 2007-02-19
16:08:59 UTC (rev 6342)
+++ trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/ProducerInfo.java 2007-02-19
18:09:29 UTC (rev 6343)
@@ -61,10 +61,26 @@
public class ProducerInfo
{
private final Logger log = Logger.getLogger(getClass());
- private EndpointConfigurationInfo endpointConfigurationInfo;
- private RegistrationInfo registrationInfo;
- private String producerId;
+
+ // Persistent information
+
+ /** Configuration of the remote WS endpoints */
+ private EndpointConfigurationInfo persistentEndpointInfo;
+
+ /** Registration information */
+ private RegistrationInfo persistentRegistrationInfo;
+
+ /** The Producer's identifier */
+ private String persistentId;
+
+ /** The cache expiration duration (in seconds) for cached values */
+ private Integer persitentExpirationCacheSeconds;
+
+ // Transient information
+
+ /** The Cookie handling policy required by the Producer */
private CookieProtocol requiresInitCookie;
+
private boolean isInitialized;
/** The Producer-Offered Portlets (handle -> WSRPPortlet) */
@@ -73,10 +89,7 @@
/** Portlet groups. */
private Map portletGroups;
- /** The cache expiration duration (in seconds) for cached values */
- private Integer expirationCacheSeconds;
-
- /** . */
+ /** Time at which the cache expires */
private long expirationTimeMillis;
/** The service description request sent to producer before registration happens. */
@@ -98,29 +111,29 @@
public ProducerInfo()
{
unregisteredServiceDescriptionRequest =
initUnregisteredServiceDescriptionRequest();
- endpointConfigurationInfo = new EndpointConfigurationInfo(this);
- registrationInfo = RegistrationInfo.REGISTRATION_NOT_NEEDED;
+ persistentEndpointInfo = new EndpointConfigurationInfo(this);
+ persistentRegistrationInfo = RegistrationInfo.REGISTRATION_NOT_NEEDED;
}
public EndpointConfigurationInfo getEndpointConfigurationInfo()
{
- return endpointConfigurationInfo;
+ return persistentEndpointInfo;
}
void setEndpointConfigurationInfo(EndpointConfigurationInfo
endpointConfigurationInfo)
{
- this.endpointConfigurationInfo = endpointConfigurationInfo;
+ this.persistentEndpointInfo = endpointConfigurationInfo;
}
public RegistrationInfo getRegistrationInfo()
{
- return registrationInfo;
+ return persistentRegistrationInfo;
}
void setRegistrationInfo(RegistrationInfo registrationInfo)
{
- this.registrationInfo = registrationInfo;
+ this.persistentRegistrationInfo = registrationInfo;
}
CookieProtocol getRequiresInitCookie()
@@ -128,74 +141,80 @@
return requiresInitCookie;
}
- private boolean isInitialized()
- {
- return isInitialized;
- }
-
+ /**
+ * Refreshes the producer's information from the service description if required.
+ *
+ * @param forceRefresh whether or not to force a refresh regardless of whether one
would have been required based on
+ * cache expiration
+ * @return <code>true</code> if the producer's information just was
refreshed, <code>false</code>
+ * @throws PortletInvokerException
+ */
public boolean refresh(boolean forceRefresh) throws PortletInvokerException
{
ServiceDescription serviceDescription;
// might neeed a different cache value: right now, we cache the whole producer info
but we might want to cache
// POPs and rest of producer info separetely...
- if (forceRefresh || isCacheExpired() || !isInitialized())
+ if (forceRefresh || isCacheExpired())
{
- log.debug("ProducerInfo refresh needed for producer '" +
producerId + "'");
+ log.debug("ProducerInfo refresh needed for producer '" +
persistentId + "'");
serviceDescription = getServiceDescription();
// do we need to call initCookie or not?
requiresInitCookie = serviceDescription.getRequiresInitCookie();
+ // do we need to register?
if (serviceDescription.isRequiresRegistration())
{
-
- if (registrationInfo == null)
+ // only process service description if consumer is not already registered
+ if (!persistentRegistrationInfo.isRegistrationValid())
{
- registrationInfo = new RegistrationInfo(this);
- }
+ // if this producer info was set up without any registration information,
create one
+ if (RegistrationInfo.REGISTRATION_NOT_NEEDED ==
persistentRegistrationInfo)
+ {
+ persistentRegistrationInfo = new RegistrationInfo(this);
+ }
- // only process service description if consumer is not already registered
- if (!registrationInfo.isRegistrationValid())
- {
// check if the configured registration information is correct and if we
can get the service description
- if (registrationInfo.initialize(serviceDescription, getId()))
+ if (persistentRegistrationInfo.initialize(serviceDescription, getId()))
{
try
{
log.debug("Attempting registration");
- RegistrationContext registrationContext =
endpointConfigurationInfo.getRegistrationService()
- .register(registrationInfo.getRegistrationData());
+ RegistrationContext registrationContext =
persistentEndpointInfo.getRegistrationService()
+ .register(persistentRegistrationInfo.getRegistrationData());
if (registrationContext == null)
{
- throw new PortletInvokerException("Received null response
after registration from producer '" + producerId + "'");
+ throw new PortletInvokerException("Received null response
after registration from producer '" + persistentId + "'");
}
//todo: hook to registration subsystem correctly Registration should
deal with state and
// it should be possible to create a RegistrationContext from a
Registration
- registrationInfo.setRegistrationContext(registrationContext);
+
persistentRegistrationInfo.setRegistrationContext(registrationContext);
log.info("Successfully registered with handle: '" +
registrationContext.getRegistrationHandle() + "'");
}
catch (Exception e)
{
- registrationInfo.resetRegistration();
- throw new PortletInvokerException("Couldn't register with
producer '" + producerId + "'", e);
+ persistentRegistrationInfo.resetRegistration();
+ throw new PortletInvokerException("Couldn't register with
producer '" + persistentId + "'", e);
}
log.debug("Requesting service description after
registration");
extractOfferedPortlets(getServiceDescription());
- isInitialized = true;
+ return true;
}
else
{
log.info("Consumer is not ready to be registered with producer
because of missing or invalid registration information.");
- isInitialized = false;
+ throw new PortletInvokerException("Consumer is not ready to be
registered with producer because of missing or invalid registration information.");
}
}
-
- // refresh the offered portlets
- extractOfferedPortlets(serviceDescription);
- isInitialized = true;
+ else
+ {
+ // registration is valid: just refresh the offered portlets
+ extractOfferedPortlets(serviceDescription);
+ return true;
+ }
}
else
{
@@ -203,32 +222,21 @@
setRegistrationInfo(RegistrationInfo.REGISTRATION_NOT_NEEDED);
setServiceDescriptionRequest(getUnregisteredServiceDescriptionRequest());
extractOfferedPortlets(serviceDescription);
- isInitialized = true;
+ return true;
}
-
- //todo: could extract more information here...
-
- if (isInitialized)
- {
- resetCacheTimerIfNeeded();
- }
- else
- {
- log.warn("Producer is NOT initialized.");
- }
}
- return isInitialized;
+ return false;
}
public String getId()
{
- return producerId;
+ return persistentId;
}
public void setId(String id)
{
- this.producerId = id;
+ this.persistentId = id;
}
/**
@@ -269,6 +277,9 @@
popsMap = Collections.EMPTY_MAP;
}
+ //todo: could extract more information here... and rename method more
appropriately
+ resetCacheTimerIfNeeded();
+
return popsMap;
}
@@ -288,7 +299,7 @@
{
log.warn("Portlet '" + portletHandle
+ "' uses the GET method in forms. Since we don't handle this,
this portlet will be excluded from " +
- "the list of offered portlets for producer " + producerId);
+ "the list of offered portlets for producer " + persistentId);
}
else
{
@@ -334,7 +345,7 @@
gpd.setUserContext(null); // todo: deal with user context!!
try
{
- PortletDescriptionResponse response =
endpointConfigurationInfo.getPortletManagementService().getPortletDescription(gpd);
+ PortletDescriptionResponse response =
persistentEndpointInfo.getPortletManagementService().getPortletDescription(gpd);
ParameterValidation.throwIllegalArgExceptionIfNull(response,
"PortletDescriptionResponse");
return
createWSRPPortletFromPortletDescription(response.getPortletDescription());
}
@@ -344,20 +355,20 @@
}
catch (Exception e)
{
- throw new InvokerUnavailableException("Couldn't access remote
producer '" + producerId + "'", e);
+ throw new InvokerUnavailableException("Couldn't access remote
producer '" + persistentId + "'", e);
}
}
}
public Map getPortletGroupMap() throws PortletInvokerException
{
- refreshPOPsIfNeeded();
+ refresh(false);
return portletGroups;
}
public Map getPortletMap() throws PortletInvokerException
{
- refreshPOPsIfNeeded();
+ refresh(false);
return popsMap;
}
@@ -365,26 +376,15 @@
private boolean useCache()
{
- return expirationCacheSeconds != null && expirationCacheSeconds.intValue()
> 0;
+ return persitentExpirationCacheSeconds != null &&
persitentExpirationCacheSeconds.intValue() > 0;
}
- private void refreshPOPsIfNeeded() throws PortletInvokerException
- {
- refresh(false);
- if (isCacheExpired())
- {
- extractOfferedPortlets(getServiceDescription());
-
- resetCacheTimerIfNeeded();
- }
- }
-
private void resetCacheTimerIfNeeded()
{
if (useCache())
{
// reset expiration time
- expirationTimeMillis = System.currentTimeMillis() +
(expirationCacheSeconds.intValue() * 1000);
+ expirationTimeMillis = System.currentTimeMillis() +
(persitentExpirationCacheSeconds.intValue() * 1000);
}
}
@@ -399,12 +399,12 @@
public Integer getExpirationCacheSeconds()
{
- return expirationCacheSeconds;
+ return persitentExpirationCacheSeconds;
}
public void setExpirationCacheSeconds(Integer expirationCacheSeconds)
{
- this.expirationCacheSeconds = expirationCacheSeconds;
+ this.persitentExpirationCacheSeconds = expirationCacheSeconds;
}
private ServiceDescription getServiceDescription() throws PortletInvokerException
@@ -416,7 +416,7 @@
ServiceDescription serviceDescription;
try
{
- serviceDescription =
endpointConfigurationInfo.getServiceDescriptionService().getServiceDescription(request);
+ serviceDescription =
persistentEndpointInfo.getServiceDescriptionService().getServiceDescription(request);
if (serviceDescription != null)
{
@@ -435,7 +435,7 @@
log.debug("Caught Exception in getServiceDescription:\n", e);
Throwable cause = e.getCause();
throw new InvokerUnavailableException("Problem getting service description
for producer "
- + producerId, cause == null ? e : cause);
+ + persistentId, cause == null ? e : cause);
}
}
@@ -475,12 +475,12 @@
private RegistrationContext getRegistrationContext()
{
- return registrationInfo.getRegistrationContext();
+ return persistentRegistrationInfo.getRegistrationContext();
}
public void resetRegistration() throws PortletInvokerException
{
- registrationInfo.resetRegistration();
+ persistentRegistrationInfo.resetRegistration();
refresh(true);
}
@@ -493,7 +493,7 @@
WSRP_v1_PortletManagement_PortType service =
getEndpointConfigurationInfo().getPortletManagementService();
GetPortletPropertyDescription request =
WSRPTypeFactory.createSimpleGetPortletPropertyDescription(portletHandle);
- request.setRegistrationContext(registrationInfo.getRegistrationContext());
+
request.setRegistrationContext(persistentRegistrationInfo.getRegistrationContext());
request.setUserContext(null); // todo: fix me!
return service.getPortletPropertyDescription(request);
Modified: trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/RegistrationInfo.java
===================================================================
--- trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/RegistrationInfo.java 2007-02-19
16:08:59 UTC (rev 6342)
+++ trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/RegistrationInfo.java 2007-02-19
18:09:29 UTC (rev 6343)
@@ -58,10 +58,10 @@
private final Logger log = Logger.getLogger(getClass());
private Registration registration;
private boolean requiresRegistration;
- private Map registrationProperties;
- private RegistrationData registrationData;
- private boolean isRegistrationValid;
- private RegistrationContext registrationContext; // todo: remove
+ private Map registrationProperties; // todo: remove and compute from registration
+ private transient RegistrationData registrationData;
+ private boolean isRegistrationValid; // todo: remove and compute from registration
+ private RegistrationContext registrationContext; // todo: remove and compute from
registration
private String consumerName;
public RegistrationInfo(ProducerInfo producerInfo)
@@ -72,7 +72,6 @@
requiresRegistration = true;
}
-
private RegistrationInfo()
{
consumerName = WSRPConstants.DEFAULT_CONSUMER_NAME;
@@ -160,7 +159,8 @@
public void removeRegistrationProperty(String name)
{
ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(name, "registration
property name", "RegistrationInfo.removeRegistrationProperty");
- if (registrationProperties == null ||
getOrCreateRegistrationPropertiesMap(false).remove(name) == null)
+ Map propertiesMap = getOrCreateRegistrationPropertiesMap(false);
+ if (propertiesMap == null || propertiesMap.remove(name) == null)
{
throw new IllegalArgumentException("Cannot remove inexistent registration
property '" + name + "'");
}
@@ -168,6 +168,7 @@
private Map getOrCreateRegistrationPropertiesMap(boolean forceCreate)
{
+ // todo: get from registration
if (forceCreate && registrationProperties == null)
{
registrationProperties = new HashMap();