public static void createSequence()

in modules/core/src/main/java/org/apache/sandesha2/client/SandeshaClient.java [309:411]


	public static void createSequence(ServiceClient serviceClient, boolean offer, String sequenceKey) throws SandeshaException {
		if (log.isDebugEnabled())
			log.debug("Enter: SandeshaClient::createSequence , " + offer + ", " + sequenceKey);
		
		setUpServiceClientAnonymousOperations (serviceClient);
		
		Options options = serviceClient.getOptions();
		if (options == null)
			throw new SandeshaException(SandeshaMessageHelper.getMessage(
					SandeshaMessageKeys.optionsObjectNotSet));

		EndpointReference toEPR = serviceClient.getOptions().getTo();
		if (toEPR == null)
			throw new SandeshaException(SandeshaMessageHelper.getMessage(
					SandeshaMessageKeys.toEPRNotValid, null));

		String to = toEPR.getAddress();
		if (to == null)
			throw new SandeshaException(SandeshaMessageHelper.getMessage(
					SandeshaMessageKeys.toEPRNotValid, null));

		if (offer) {
			String offeredSequenceID = SandeshaUtil.getUUID();
			options.setProperty(SandeshaClientConstants.OFFERED_SEQUENCE_ID, offeredSequenceID);
		}

		// setting a new squenceKey if not already set.
		String oldSequenceKey = (String) options.getProperty(SandeshaClientConstants.SEQUENCE_KEY);

	  options.setProperty(SandeshaClientConstants.SEQUENCE_KEY, sequenceKey);

		String rmSpecVersion = (String) options.getProperty(SandeshaClientConstants.RM_SPEC_VERSION);

		if (rmSpecVersion == null)
			rmSpecVersion = SpecSpecificConstants.getDefaultSpecVersion();

		//When the message is marked as Dummy the application processor will not actually try to send it. 
		//But still the create Sequence will be added.

		options.setProperty(SandeshaClientConstants.DUMMY_MESSAGE, Sandesha2Constants.VALUE_TRUE);

		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()));
		
		// If the client requested async operations, mint a replyTo EPR
		boolean resetReply = false;
		if(options.isUseSeparateListener() && options.getReplyTo() == null) {
			try {
				if(log.isDebugEnabled()) log.debug("Creating replyTo EPR");
				
				// Try to work out which transport to use. If the user didn't choose one
				// then we use the To address to take a guess.
				TransportOutDescription senderTransport = options.getTransportOut();
				String transportName = null;
				if(senderTransport != null) {
					transportName = senderTransport.getName();
				}

				if(transportName == null) {
					int index = to.indexOf(':');
					if(index > 0) transportName = to.substring(0, index);
				}

				EndpointReference replyTo = serviceContext.getMyEPR(transportName);
				if(replyTo != null) {
					options.setReplyTo(replyTo);
					resetReply = true;
				}
				
				if(log.isDebugEnabled()) log.debug("Created replyTo EPR: " + replyTo);

			} catch(AxisFault e) {
				if(log.isDebugEnabled()) log.debug("Caught exception", e);
				throw new SandeshaException(e);
			}
		}
		try {			
			//just to inform the sender.
			serviceClient.fireAndForget (null);
		} catch (AxisFault e) {
			throw new SandeshaException(e);
		}
		finally {
			options.setAction(oldAction);
			if(resetReply) options.setReplyTo(null);
			
			options.setProperty(SandeshaClientConstants.DUMMY_MESSAGE, Sandesha2Constants.VALUE_FALSE);
			options.setProperty(SandeshaClientConstants.SEQUENCE_KEY, oldSequenceKey);
		}
		
		if (log.isDebugEnabled())
			log.debug("Exit: SandeshaClient::createSequence");
	}