You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fx-dev@ws.apache.org by ga...@apache.org on 2006/12/22 14:39:44 UTC
svn commit: r489651 - in /webservices/sandesha/trunk/java:
src/org/apache/sandesha2/client/SandeshaClient.java
src/org/apache/sandesha2/util/MessageRetransmissionAdjuster.java
test/src/org/apache/sandesha2/SandeshaClientTest.java
Author: gatfora
Date: Fri Dec 22 05:39:43 2006
New Revision: 489651
URL: http://svn.apache.org/viewvc?view=rev&rev=489651
Log:
Allow client to create a sequence over a sequence that was previously terminated
Modified:
webservices/sandesha/trunk/java/src/org/apache/sandesha2/client/SandeshaClient.java
webservices/sandesha/trunk/java/src/org/apache/sandesha2/util/MessageRetransmissionAdjuster.java
webservices/sandesha/trunk/java/test/src/org/apache/sandesha2/SandeshaClientTest.java
Modified: webservices/sandesha/trunk/java/src/org/apache/sandesha2/client/SandeshaClient.java
URL: http://svn.apache.org/viewvc/webservices/sandesha/trunk/java/src/org/apache/sandesha2/client/SandeshaClient.java?view=diff&rev=489651&r1=489650&r2=489651
==============================================================================
--- webservices/sandesha/trunk/java/src/org/apache/sandesha2/client/SandeshaClient.java (original)
+++ webservices/sandesha/trunk/java/src/org/apache/sandesha2/client/SandeshaClient.java Fri Dec 22 05:39:43 2006
@@ -19,6 +19,7 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
+import java.util.List;
import java.util.MissingResourceException;
import javax.xml.namespace.QName;
@@ -45,6 +46,7 @@
import org.apache.sandesha2.SandeshaException;
import org.apache.sandesha2.i18n.SandeshaMessageHelper;
import org.apache.sandesha2.i18n.SandeshaMessageKeys;
+import org.apache.sandesha2.storage.SandeshaStorageException;
import org.apache.sandesha2.storage.StorageManager;
import org.apache.sandesha2.storage.Transaction;
import org.apache.sandesha2.storage.beanmanagers.RMSBeanMgr;
@@ -324,22 +326,108 @@
String oldAction = options.getAction();
options.setAction(SpecSpecificConstants.getCreateSequenceAction(rmSpecVersion));
+ ServiceContext serviceContext = serviceClient.getServiceContext();
+ if (serviceContext == null)
+ throw new SandeshaException(SandeshaMessageHelper.getMessage(
+ SandeshaMessageKeys.serviceContextNotSet));
+
+ ConfigurationContext configurationContext = serviceContext.getConfigurationContext();
+
+ // cleanup previous sequence
+ cleanupTerminatedSequence(to, oldSequenceKey, SandeshaUtil.getSandeshaStorageManager(configurationContext, configurationContext.getAxisConfiguration()));
+
try {
//just to inform the sender.
serviceClient.fireAndForget (null);
} catch (AxisFault e) {
throw new SandeshaException(e);
}
-
- options.setAction(oldAction);
-
- options.setProperty(SandeshaClientConstants.DUMMY_MESSAGE, Sandesha2Constants.VALUE_FALSE);
- options.setProperty(SandeshaClientConstants.SEQUENCE_KEY, oldSequenceKey);
+ finally {
+ options.setAction(oldAction);
+
+ options.setProperty(SandeshaClientConstants.DUMMY_MESSAGE, Sandesha2Constants.VALUE_FALSE);
+ options.setProperty(SandeshaClientConstants.SEQUENCE_KEY, oldSequenceKey);
+ }
if (log.isDebugEnabled())
log.debug("Exit: SandeshaClient::createSequence");
}
+ /**
+ * If a user has requested to create a new sequence which was previously terminated, we need to clean up
+ * any previous properties that might have been stored.
+ * @param to
+ * @param sequenceKey
+ * @throws SandeshaStorageException
+ */
+ private static final void cleanupTerminatedSequence(String to, String sequenceKey, StorageManager storageManager) throws SandeshaException {
+ String internalSequenceId = SandeshaUtil.getInternalSequenceID(to, sequenceKey);
+
+ if (log.isTraceEnabled())
+ log.trace("Checking if sequence " + internalSequenceId + " previously terminated");
+
+ Transaction tran = storageManager.getTransaction();
+
+ try {
+
+ SequencePropertyBeanMgr seqPropMgr = storageManager.getSequencePropertyBeanMgr();
+
+ boolean terminatedSequence = false;
+
+ //see if the sequence is terminated
+ SequencePropertyBean sequenceTerminated = seqPropMgr.retrieve(internalSequenceId, Sandesha2Constants.SequenceProperties.TERMINATE_ADDED);
+ if(sequenceTerminated!=null){
+ terminatedSequence = true;
+ }
+
+ //see if the sequence is timed out
+ SequencePropertyBean sequenceTimedout = seqPropMgr.retrieve(internalSequenceId, Sandesha2Constants.SequenceProperties.SEQUENCE_TIMED_OUT);
+ if(sequenceTimedout!=null){
+ terminatedSequence = true;
+ }
+
+ if (terminatedSequence) {
+ // We need to find out the original sequence id for this sequence by doing a backwards lookup
+ SequencePropertyBean bean = new SequencePropertyBean();
+ bean.setName(Sandesha2Constants.SequenceProperties.INTERNAL_SEQUENCE_ID);
+ bean.setValue(internalSequenceId);
+ bean = seqPropMgr.findUnique(bean);
+
+ String sequenceId = null;
+ if (bean != null)
+ sequenceId = bean.getSequencePropertyKey();
+
+ // Find all properties which have a matching internal sequence id
+ removeBeans(sequenceId, seqPropMgr);
+ removeBeans(internalSequenceId, seqPropMgr);
+ }
+
+ } catch (SandeshaException e) {
+ tran.rollback();
+ tran = null;
+
+ throw e;
+ }
+
+ tran.commit();
+ }
+
+ private static final void removeBeans(String sequenceId, SequencePropertyBeanMgr seqPropMgr) throws SandeshaStorageException {
+ // Find all properties which have a matching sequence id
+ SequencePropertyBean bean = new SequencePropertyBean();
+ bean.setSequencePropertyKey(sequenceId);
+ List beans = seqPropMgr.find(bean);
+
+ Iterator iterator = beans.iterator();
+
+ while (iterator.hasNext()) {
+ bean = (SequencePropertyBean)iterator.next();
+
+ seqPropMgr.delete(bean.getSequencePropertyKey(), bean.getName());
+ }
+
+ }
+
/**
* Clients can use this to create a sequence sequence.
*
Modified: webservices/sandesha/trunk/java/src/org/apache/sandesha2/util/MessageRetransmissionAdjuster.java
URL: http://svn.apache.org/viewvc/webservices/sandesha/trunk/java/src/org/apache/sandesha2/util/MessageRetransmissionAdjuster.java?view=diff&rev=489651&r1=489650&r2=489651
==============================================================================
--- webservices/sandesha/trunk/java/src/org/apache/sandesha2/util/MessageRetransmissionAdjuster.java (original)
+++ webservices/sandesha/trunk/java/src/org/apache/sandesha2/util/MessageRetransmissionAdjuster.java Fri Dec 22 05:39:43 2006
@@ -74,6 +74,9 @@
boolean continueSending = true;
if (timeOutSequence) {
+ // Warn the user that the sequence has timed out
+ //if (log.isWarnEnabled())
+ // log.warn();
stopRetransmission(retransmitterBean);
// Only messages of outgoing sequences get retransmitted. So named
Modified: webservices/sandesha/trunk/java/test/src/org/apache/sandesha2/SandeshaClientTest.java
URL: http://svn.apache.org/viewvc/webservices/sandesha/trunk/java/test/src/org/apache/sandesha2/SandeshaClientTest.java?view=diff&rev=489651&r1=489650&r2=489651
==============================================================================
--- webservices/sandesha/trunk/java/test/src/org/apache/sandesha2/SandeshaClientTest.java (original)
+++ webservices/sandesha/trunk/java/test/src/org/apache/sandesha2/SandeshaClientTest.java Fri Dec 22 05:39:43 2006
@@ -454,9 +454,81 @@
finally {
configContext.getListenerManager().stop();
serviceClient.cleanup();
- }
+ }
+ }
+
+ /**
+ * Checks the following scenario
+ *
+ * 1) send an application message (will generate the create sequence)
+ * 2) terminate the sequence
+ * 3) Issue wait until sequence completed (with a wait time)
+ * 4) Create a new sequence
+ * 5) send another application message
+ * 6) terminate the sequence
+ * 7) Ensure that the sequence was terminated
+ *
+ */
+ public void testTerminateCreateWithWait () throws Exception {
+
+ startServer(server_repoPath, server_axis2_xml);
+
+ String to = "http://127.0.0.1:" + 9999 + "/axis2/services/RMSampleService";
+
+ String repoPath = "target" + File.separator + "repos" + File.separator + "client";
+ String axis2_xml = "target" + File.separator + "repos" + File.separator + "client" + File.separator + "client_axis2.xml";
+
+ ConfigurationContext configContext = ConfigurationContextFactory.createConfigurationContextFromFileSystem(repoPath,axis2_xml);
+ Options clientOptions = new Options ();
+ clientOptions.setAction(pingAction);
+ clientOptions.setSoapVersionURI(SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI);
+ clientOptions.setProperty(SandeshaClientConstants.RM_SPEC_VERSION,
+ Sandesha2Constants.SPEC_VERSIONS.v1_1);
+ clientOptions.setTo(new EndpointReference (to));
+
+ ServiceClient serviceClient = new ServiceClient (configContext,null);
+
+ String acksTo = serviceClient.getMyEPR(Constants.TRANSPORT_HTTP).getAddress();
+ clientOptions.setProperty(SandeshaClientConstants.AcksTo,acksTo);
+ clientOptions.setTransportInProtocol(Constants.TRANSPORT_HTTP);
+ //serviceClient.
+ serviceClient.setOptions(clientOptions);
+
+ try{
+ // 1) Send the application message
+ serviceClient.fireAndForget(getPingOMBlock("ping1"));
+
+ // 2) Terminate the sequence
+ SandeshaClient.terminateSequence(serviceClient);
+
+ // 3) wait for the sequence completion (30 second wait)
+ SandeshaClient.waitUntilSequenceCompleted(serviceClient, 30000);
+
+ // 4) Create a new Sequence to the same endpoint
+ SandeshaClient.createSequence(serviceClient, false, null);
+
+ // 5) Send the second application message (this should use a new sequence)
+ serviceClient.fireAndForget(getPingOMBlock("ping2"));
+
+ // 6) Terminate the sequence
+ SandeshaClient.terminateSequence(serviceClient);
+
+ // 7) wait for the sequence completion (30 second wait)
+ SandeshaClient.waitUntilSequenceCompleted(serviceClient, 30000);
+
+ // 8) Check that the sequence has terminated
+ SequenceReport report = SandeshaClient.getOutgoingSequenceReport(serviceClient);
+ assertNotNull(report);
+ assertEquals(SequenceReport.SEQUENCE_STATUS_TERMINATED, report.getSequenceStatus());
+
+ }
+ finally {
+ configContext.getListenerManager().stop();
+ serviceClient.cleanup();
+ }
}
+
//
// public void testCloseSequence () {
//
---------------------------------------------------------------------
To unsubscribe, e-mail: sandesha-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: sandesha-dev-help@ws.apache.org