You are viewing a plain text version of this content. The canonical link for it is here.
Posted to sandesha-dev@ws.apache.org by ga...@apache.org on 2007/01/08 14:25:50 UTC

svn commit: r494063 - in /webservices/sandesha/trunk/java: src/org/apache/sandesha2/ src/org/apache/sandesha2/msgprocessors/ src/org/apache/sandesha2/storage/beans/ test/src/org/apache/sandesha2/workers/

Author: gatfora
Date: Mon Jan  8 05:25:49 2007
New Revision: 494063

URL: http://svn.apache.org/viewvc?view=rev&rev=494063
Log:
Move the nextMessageNumber to the RMSBean

Modified:
    webservices/sandesha/trunk/java/src/org/apache/sandesha2/Sandesha2Constants.java
    webservices/sandesha/trunk/java/src/org/apache/sandesha2/msgprocessors/ApplicationMsgProcessor.java
    webservices/sandesha/trunk/java/src/org/apache/sandesha2/storage/beans/RMSBean.java
    webservices/sandesha/trunk/java/test/src/org/apache/sandesha2/workers/ForceInboundDispatchTest.java

Modified: webservices/sandesha/trunk/java/src/org/apache/sandesha2/Sandesha2Constants.java
URL: http://svn.apache.org/viewvc/webservices/sandesha/trunk/java/src/org/apache/sandesha2/Sandesha2Constants.java?view=diff&rev=494063&r1=494062&r2=494063
==============================================================================
--- webservices/sandesha/trunk/java/src/org/apache/sandesha2/Sandesha2Constants.java (original)
+++ webservices/sandesha/trunk/java/src/org/apache/sandesha2/Sandesha2Constants.java Mon Jan  8 05:25:49 2007
@@ -276,8 +276,6 @@
 
 		String OUT_CREATE_SEQUENCE_SENT = "OutCreateSeqSent";
 
-		String NEXT_MESSAGE_NUMBER = "NextMsgNo";
-
 		String INCOMING_SEQUENCE_LIST = "IncomingSequenceList";
 
 		String OFFERED_SEQUENCE = "OfferedSequence";

Modified: webservices/sandesha/trunk/java/src/org/apache/sandesha2/msgprocessors/ApplicationMsgProcessor.java
URL: http://svn.apache.org/viewvc/webservices/sandesha/trunk/java/src/org/apache/sandesha2/msgprocessors/ApplicationMsgProcessor.java?view=diff&rev=494063&r1=494062&r2=494063
==============================================================================
--- webservices/sandesha/trunk/java/src/org/apache/sandesha2/msgprocessors/ApplicationMsgProcessor.java (original)
+++ webservices/sandesha/trunk/java/src/org/apache/sandesha2/msgprocessors/ApplicationMsgProcessor.java Mon Jan  8 05:25:49 2007
@@ -187,30 +187,6 @@
 			}
 		}
 
-		// the message number that was last used.
-		long systemMessageNumber = getPreviousMsgNo(configContext, sequencePropertyKey, storageManager);
-
-		// The number given by the user has to be larger than the last stored
-		// number.
-		if (givenMessageNumber > 0 && givenMessageNumber <= systemMessageNumber) {
-			String message = SandeshaMessageHelper.getMessage(SandeshaMessageKeys.msgNumberNotLargerThanLastMsg, Long
-					.toString(givenMessageNumber));
-			throw new SandeshaException(message);
-		}
-
-		// Finding the correct message number.
-		long messageNumber = -1;
-		if (givenMessageNumber > 0) // if given message number is valid use it.
-									// (this is larger than the last stored due
-									// to the last check)
-			messageNumber = givenMessageNumber;
-		else if (systemMessageNumber > 0) { // if system message number is valid
-											// use it.
-			messageNumber = systemMessageNumber + 1;
-		} else { // This is the first message (systemMessageNumber = -1)
-			messageNumber = 1;
-		}
-
 		// A dummy message is a one which will not be processed as a actual
 		// application message.
 		// The RM handlers will simply let these go.
@@ -237,10 +213,6 @@
 			throw new SandeshaException(SandeshaMessageHelper.getMessage(SandeshaMessageKeys.cannotSendMsgAsSequenceTimedout, internalSequenceId));
 		}
 
-		// saving the used message number
-		if (!dummyMessage)
-			setNextMsgNo(configContext, sequencePropertyKey, messageNumber, storageManager);
-
 		boolean sendCreateSequence = false;
 
 		String outSequenceID = SandeshaUtil.getSequenceIDFromInternalSequenceID(internalSequenceId, storageManager);
@@ -298,25 +270,15 @@
 		}
 
 		if (specVersion == null)
-			specVersion = SpecSpecificConstants.getDefaultSpecVersion(); // TODO
-																			// change
-																			// the
-																			// default
-																			// to
-																			// v1_1.
-
-		if (messageNumber == 1) {
-			if (outSequenceID == null) { // out sequence will be set for the
+			// TODO change the default to v1_1
+			specVersion = SpecSpecificConstants.getDefaultSpecVersion(); 
+		
+		if (outSequenceID == null) { // out sequence will be set for the
 										// server side, in the case of an offer.
-				sendCreateSequence = true; // message number being one and not
+			sendCreateSequence = true; // message number being one and not
 											// having an out sequence, implies
 											// that a create sequence has to be
 											// send.
-			}
-
-			// if first message - setup the sending side sequence - both for the
-			// server and the client sides
-			SequenceManager.setupNewClientSequence(msgContext, sequencePropertyKey, specVersion, storageManager);
 		}
 
 		ServiceContext serviceContext = msgContext.getServiceContext();
@@ -326,6 +288,11 @@
 		
 		// SENDING THE CREATE SEQUENCE.
 		if (sendCreateSequence) {
+
+			// if first message - setup the sending side sequence - both for the
+			// server and the client sides
+			SequenceManager.setupNewClientSequence(msgContext, sequencePropertyKey, specVersion, storageManager);
+			
 			EndpointReference acksToEPR = null;
 			SequencePropertyBean responseCreateSeqAdded = seqPropMgr.retrieve(sequencePropertyKey,
 					Sandesha2Constants.SequenceProperties.OUT_CREATE_SEQUENCE_SENT);
@@ -408,6 +375,30 @@
 			rmsBean = storageManager.getRMSBeanMgr().findUnique(findBean);
 		}
 		
+		// the message number that was last used.
+		long systemMessageNumber = rmsBean.getNextMessageNumber();
+
+		// The number given by the user has to be larger than the last stored
+		// number.
+		if (givenMessageNumber > 0 && givenMessageNumber <= systemMessageNumber) {
+			String message = SandeshaMessageHelper.getMessage(SandeshaMessageKeys.msgNumberNotLargerThanLastMsg, Long
+					.toString(givenMessageNumber));
+			throw new SandeshaException(message);
+		}
+
+		// Finding the correct message number.
+		long messageNumber = -1;
+		if (givenMessageNumber > 0) // if given message number is valid use it.
+									// (this is larger than the last stored due
+									// to the last check)
+			messageNumber = givenMessageNumber;
+		else if (systemMessageNumber > 0) { // if system message number is valid
+											// use it.
+			messageNumber = systemMessageNumber + 1;
+		} else { // This is the first message (systemMessageNumber = -1)
+			messageNumber = 1;
+		}
+		
 		if (lastMessage) {
 			rmsBean.setLastOutMessage(messageNumber);
 			// Update the rmsBean
@@ -417,6 +408,16 @@
 		// set this as the response highest message.
 		rmsBean.setHighestOutMessageNumber(messageNumber);
 		
+		// saving the used message number
+		if (!dummyMessage)
+			rmsBean.setNextMessageNumber(messageNumber);
+		
+		if (messageNumber == 1 && !sendCreateSequence) {
+			// if first message - setup the sending side sequence - both for the
+			// server and the client sides
+			SequenceManager.setupNewClientSequence(msgContext, sequencePropertyKey, specVersion, storageManager);
+		}
+
 		RelatesTo relatesTo = msgContext.getRelatesTo();
 		if(relatesTo != null) {
 			rmsBean.setHighestOutRelatesTo(relatesTo.getValue());
@@ -747,62 +748,4 @@
 		if (log.isDebugEnabled())
 			log.debug("Exit: ApplicationMsgProcessor::processResponseMessage");
 	}
-
-	private long getPreviousMsgNo(ConfigurationContext context, String sequencePropertyKey, StorageManager storageManager)
-			throws SandeshaException {
-		if (log.isDebugEnabled())
-			log.debug("Enter: ApplicationMsgProcessor::getPreviousMsgNo, " + sequencePropertyKey);
-
-		SequencePropertyBeanMgr seqPropMgr = storageManager.getSequencePropertyBeanMgr();
-
-		SequencePropertyBean nextMsgNoBean = seqPropMgr.retrieve(sequencePropertyKey,
-				Sandesha2Constants.SequenceProperties.NEXT_MESSAGE_NUMBER);
-
-		long nextMsgNo = -1;
-		if (nextMsgNoBean != null) {
-			Long nextMsgNoLng = new Long(nextMsgNoBean.getValue());
-			nextMsgNo = nextMsgNoLng.longValue();
-		}
-
-		if (log.isDebugEnabled())
-			log.debug("Exit: ApplicationMsgProcessor::getPreviousMsgNo, " + nextMsgNo);
-
-		return nextMsgNo;
-	}
-
-	private void setNextMsgNo(ConfigurationContext context, String sequencePropertyKey, long msgNo,
-			StorageManager storageManager) throws SandeshaException {
-
-		if (log.isDebugEnabled())
-			log.debug("Enter: ApplicationMsgProcessor::setNextMsgNo, " + sequencePropertyKey + ", " + msgNo);
-
-		if (msgNo <= 0) {
-			String message = SandeshaMessageHelper.getMessage(SandeshaMessageKeys.msgNumberMustBeLargerThanZero, Long
-					.toString(msgNo));
-			throw new SandeshaException(message);
-		}
-
-		SequencePropertyBeanMgr seqPropMgr = storageManager.getSequencePropertyBeanMgr();
-
-		SequencePropertyBean nextMsgNoBean = seqPropMgr.retrieve(sequencePropertyKey,
-				Sandesha2Constants.SequenceProperties.NEXT_MESSAGE_NUMBER);
-
-		boolean update = true;
-		if (nextMsgNoBean == null) {
-			update = false;
-			nextMsgNoBean = new SequencePropertyBean();
-			nextMsgNoBean.setSequencePropertyKey(sequencePropertyKey);
-			nextMsgNoBean.setName(Sandesha2Constants.SequenceProperties.NEXT_MESSAGE_NUMBER);
-		}
-
-		nextMsgNoBean.setValue(new Long(msgNo).toString());
-		if (update)
-			seqPropMgr.update(nextMsgNoBean);
-		else
-			seqPropMgr.insert(nextMsgNoBean);
-
-		if (log.isDebugEnabled())
-			log.debug("Exit: ApplicationMsgProcessor::setNextMsgNo");
-	}
-	
 }

Modified: webservices/sandesha/trunk/java/src/org/apache/sandesha2/storage/beans/RMSBean.java
URL: http://svn.apache.org/viewvc/webservices/sandesha/trunk/java/src/org/apache/sandesha2/storage/beans/RMSBean.java?view=diff&rev=494063&r1=494062&r2=494063
==============================================================================
--- webservices/sandesha/trunk/java/src/org/apache/sandesha2/storage/beans/RMSBean.java (original)
+++ webservices/sandesha/trunk/java/src/org/apache/sandesha2/storage/beans/RMSBean.java Mon Jan  8 05:25:49 2007
@@ -95,6 +95,11 @@
 	 * Keeps track of the highest transmitted message
 	 */
   private String highestOutRelatesTo = null;
+  
+  /**
+   * The next sequence number to apply to the message
+   */
+  private long nextMessageNumber = -1;
 	
 	public RMSBean() {
 	}
@@ -195,6 +200,15 @@
   	this.highestOutRelatesTo = highestOutRelatesTo;
   }
 
+	public long getNextMessageNumber() {
+  	return nextMessageNumber;
+  }
+
+
+	public void setNextMessageNumber(long nextMessageNumber) {
+  	this.nextMessageNumber = nextMessageNumber;
+  }
+
 	public String toString() {
 		StringBuffer result = new StringBuffer();
 		result.append(this.getClass().getName());
@@ -208,7 +222,7 @@
 		result.append("\nLastOutMessageNumber: "); result.append(lastOutMessage);
 		result.append("\nHighestOutMessage: "); result.append(highestOutMessageNumber);
 		result.append("\nHighestOutRelatesTo: ");result.append(highestOutRelatesTo);
+		result.append("\nNextMessageNumber: "); result.append(nextMessageNumber);
 		return result.toString();
 	}
-
 }

Modified: webservices/sandesha/trunk/java/test/src/org/apache/sandesha2/workers/ForceInboundDispatchTest.java
URL: http://svn.apache.org/viewvc/webservices/sandesha/trunk/java/test/src/org/apache/sandesha2/workers/ForceInboundDispatchTest.java?view=diff&rev=494063&r1=494062&r2=494063
==============================================================================
--- webservices/sandesha/trunk/java/test/src/org/apache/sandesha2/workers/ForceInboundDispatchTest.java (original)
+++ webservices/sandesha/trunk/java/test/src/org/apache/sandesha2/workers/ForceInboundDispatchTest.java Mon Jan  8 05:25:49 2007
@@ -97,12 +97,12 @@
 			
 			//we deliver msg 2
 			//set highest out msg number to 1
+			String internalSequenceId = SandeshaUtil.getInternalSequenceID(to, sequenceKey);
 			t = mgr.getTransaction();
-			SequencePropertyBean nextMsgNoBean = 
-					mgr.getSequencePropertyBeanMgr().
-					retrieve(SandeshaUtil.getInternalSequenceID(to, sequenceKey),
-					Sandesha2Constants.SequenceProperties.NEXT_MESSAGE_NUMBER);
-			nextMsgNoBean.setValue("1");
+			RMSBean rmsBean = SandeshaUtil.getRMSBeanFromInternalSequenceId(mgr, internalSequenceId);
+			rmsBean.setNextMessageNumber(1);
+			// Update the bean
+			mgr.getRMSBeanMgr().update(rmsBean);
 			t.commit();
 			
 			clientOptions.setProperty(SandeshaClientConstants.MESSAGE_NUMBER,new Long(2));



---------------------------------------------------------------------
To unsubscribe, e-mail: sandesha-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: sandesha-dev-help@ws.apache.org