Author: chris.laprun(a)jboss.com
Date: 2007-03-06 13:15:10 -0500 (Tue, 06 Mar 2007)
New Revision: 6557
Modified:
trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/ConsumerRegistry.java
trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/ConsumerRegistryService.java
trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/ProducerInfo.java
trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/WSRPConsumerImpl.java
trunk/wsrp/src/main/org/jboss/portal/wsrp/deployment/WSRPDeploymentFactory.java
trunk/wsrp/src/main/org/jboss/portal/wsrp/services/RemoteSOAPInvokerServiceFactory.java
Log:
- Better management of consumer activation.
- ConsumerRegistry.activateConsumerWith now only activates the consumer if the associated
ServiceFactory is available.
- Properly set the registry on ProducerInfo after being loaded from DB.
- JBPORTAL-1279: clean up and prepare for extraction of URLStreamOpeningThread to common
to be used in URLTools.exists as well.
Modified: trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/ConsumerRegistry.java
===================================================================
--- trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/ConsumerRegistry.java 2007-03-06
17:04:55 UTC (rev 6556)
+++ trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/ConsumerRegistry.java 2007-03-06
18:15:10 UTC (rev 6557)
@@ -44,6 +44,13 @@
void persistConsumer(WSRPConsumer consumer);
+ /**
+ * Activates the consumer associated with the specified identifier if and only if
access to the remote producer is
+ * properly setup (i.e. the associated service factory MUST be available).
+ *
+ * @param id the identifier of the consumer to be activated
+ * @throws ConsumerException
+ */
void activateConsumerWith(String id) throws ConsumerException;
void updateProducerInfo(ProducerInfo producerInfo);
Modified: trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/ConsumerRegistryService.java
===================================================================
---
trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/ConsumerRegistryService.java 2007-03-06
17:04:55 UTC (rev 6556)
+++
trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/ConsumerRegistryService.java 2007-03-06
18:15:10 UTC (rev 6557)
@@ -130,6 +130,10 @@
while (producerInfos.hasNext())
{
producerInfo = (ProducerInfo)producerInfos.next();
+
+ // need to set the registry after loading from DB since registry is not
persisted.
+ producerInfo.setRegistry(this);
+
createConsumerFrom(producerInfo);
activateConsumerWith(producerInfo.getId());
}
@@ -177,12 +181,8 @@
throw new ConsumerException("Couldn't start Consumer service
'" + id + "'", e);
}
- // mark the consumer as active
- ProducerInfo info = consumer.getProducerInfo();
- info.setActive(true);
-
// update ProducerInfo
- updateProducerInfo(info);
+ updateProducerInfo(service.getConsumer().getProducerInfo());
}
}
Modified: trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/ProducerInfo.java
===================================================================
--- trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/ProducerInfo.java 2007-03-06
17:04:55 UTC (rev 6556)
+++ trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/ProducerInfo.java 2007-03-06
18:15:10 UTC (rev 6557)
@@ -204,6 +204,11 @@
// update DB
if (justRefreshed)
{
+ if (!isActive())
+ {
+ setActive(true);
+ }
+
registry.updateProducerInfo(this);
}
@@ -247,6 +252,7 @@
if (registrationContext == null)
{
+ setActive(false);
throw new PortletInvokerException("Received null response
after registration from producer '" + persistentId + "'");
}
@@ -256,6 +262,7 @@
catch (Exception e)
{
persistentRegistrationInfo.resetRegistration();
+ setActive(false);
throw new PortletInvokerException("Couldn't register with
producer '" + persistentId + "'", e);
}
@@ -266,6 +273,7 @@
else
{
log.info("Consumer is not ready to be registered with producer
because of missing or invalid registration information.");
+ setActive(false);
throw new PortletInvokerException("Consumer is not ready to be
registered with producer because of missing or invalid registration information.");
}
}
@@ -503,6 +511,11 @@
catch (Exception e)
{
log.debug("Caught Exception in getServiceDescription:\n", e);
+
+ // de-activate
+ setActive(false);
+ registry.updateProducerInfo(this);
+
Throwable cause = e.getCause();
throw new InvokerUnavailableException("Problem getting service description
for producer "
+ persistentId, cause == null ? e : cause);
Modified: trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/WSRPConsumerImpl.java
===================================================================
--- trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/WSRPConsumerImpl.java 2007-03-06
17:04:55 UTC (rev 6556)
+++ trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/WSRPConsumerImpl.java 2007-03-06
18:15:10 UTC (rev 6557)
@@ -457,11 +457,14 @@
protected void startService() throws Exception
{
super.startService();
- getServiceFactory().start();
+ ServiceFactory factory = getServiceFactory();
+ factory.start();
+ producerInfo.setActive(factory.isAvailable());
}
protected void stopService() throws Exception
{
+ producerInfo.setActive(false);
getServiceFactory().stop();
super.stopService();
}
Modified: trunk/wsrp/src/main/org/jboss/portal/wsrp/deployment/WSRPDeploymentFactory.java
===================================================================
---
trunk/wsrp/src/main/org/jboss/portal/wsrp/deployment/WSRPDeploymentFactory.java 2007-03-06
17:04:55 UTC (rev 6556)
+++
trunk/wsrp/src/main/org/jboss/portal/wsrp/deployment/WSRPDeploymentFactory.java 2007-03-06
18:15:10 UTC (rev 6557)
@@ -272,6 +272,8 @@
}
+ ProducerInfo info = service.getConsumer().getProducerInfo();
+
String message;
if (service.getConsumer().getServiceFactory().isAvailable())
{
@@ -282,10 +284,11 @@
{
message = "There was a problem initializing the WSRP interface for producer
'"
+ service.getId() + "'. The consumer will NOT be available.";
+ info.setActive(false);
}
// update the producer info once the whole information is known
- consumerRegistry.updateProducerInfo(service.getConsumer().getProducerInfo());
+ consumerRegistry.updateProducerInfo(info);
log.info(message);
}
Modified:
trunk/wsrp/src/main/org/jboss/portal/wsrp/services/RemoteSOAPInvokerServiceFactory.java
===================================================================
---
trunk/wsrp/src/main/org/jboss/portal/wsrp/services/RemoteSOAPInvokerServiceFactory.java 2007-03-06
17:04:55 UTC (rev 6556)
+++
trunk/wsrp/src/main/org/jboss/portal/wsrp/services/RemoteSOAPInvokerServiceFactory.java 2007-03-06
18:15:10 UTC (rev 6557)
@@ -184,32 +184,32 @@
}
- static class URLThread extends Thread
+ static class URLStreamOpeningThread extends Thread
{
volatile private URL url;
- private InputSource inputSource;
+
+ /** */
+ private InputStream inputStream;
+
/** Exception in the event a connection error occurs */
private IOException exception = null;
- // Connect to the specified host and port number
- public URLThread(URL wsdlFile)
+ public URLStreamOpeningThread(URL url)
{
- ParameterValidation.throwIllegalArgExceptionIfNull(wsdlFile, "WSDL
URL");
+ ParameterValidation.throwIllegalArgExceptionIfNull(url, "URL");
- this.url = wsdlFile;
+ this.url = url;
}
public void run()
{
try
{
- InputStream is = Tools.safeBufferedWrapper(url.openStream());
- if (is == null)
+ inputStream = url.openStream();
+ if (inputStream == null)
{
- throw new IllegalArgumentException("Cannot obtain wsdl from [" +
url + "]");
+ throw new IllegalArgumentException("Cannot open stream from [" +
url + "]");
}
-
- inputSource = new InputSource(is);
}
catch (IOException e)
{
@@ -219,32 +219,17 @@
public boolean isConnected()
{
- if (inputSource == null)
- {
- return false;
- }
- else
- {
- return true;
- }
+ return inputStream != null;
}
public boolean isError()
{
- if (exception == null)
- {
- return false;
- }
- else
- {
- return true;
- }
+ return exception != null;
}
-
- public InputSource getInputSource()
+ public InputStream getInputStream()
{
- return inputSource;
+ return inputStream;
}
public IOException getException()
@@ -271,11 +256,10 @@
{
log.info("getBaseInputSource [wsdlUrl=" + wsdlURL + "]");
- URLThread thread = new URLThread(wsdlURL);
+ URLStreamOpeningThread thread = new URLStreamOpeningThread(wsdlURL);
thread.start();
- // Wait for the thread to finish but don't wait longer than a
- // specified time
+ // Wait for the thread to finish but don't wait longer than the specified
time
long delayMillis = 1000;
try
{
@@ -293,7 +277,8 @@
// Finished
if (thread.isConnected() && !thread.isError())
{
- return thread.getInputSource();
+ InputStream is = Tools.safeBufferedWrapper(thread.getInputStream());
+ return new InputSource(is);
}
else
{
@@ -307,38 +292,6 @@
// Thread was interrupted
throw new RuntimeException("Parsing thread was interrupted!", e);
}
-
- /*// use 1 second time outs and remember previous values
- String connectTimeOut =
System.setProperty("sun.net.client.defaultConnectTimeout", "1000");
- String readTimeOut =
System.setProperty("sun.net.client.defaultReadTimeout", "1000");
-
- try
- {
- InputStream is = Tools.safeBufferedWrapper(wsdlURL.openStream());
- if (is == null)
- {
- throw new IllegalArgumentException("Cannot obtain wsdl from [" +
wsdlURL + "]");
- }
-
- return new InputSource(is);
- }
- catch (IOException e)
- {
- throw new RuntimeException("Cannot access wsdl from [" + wsdlURL +
"], " + e.getMessage());
- }
- finally
- {
- // restore time outs
- if (connectTimeOut != null)
- {
- System.setProperty("sun.net.client.defaultConnectTimeout",
connectTimeOut);
- }
-
- if (readTimeOut != null)
- {
- System.setProperty("sun.net.client.defaultReadTimeout",
readTimeOut);
- }
- }*/
}
public String getBaseURI()