// Path: AMQPPerfHarness/src/com/ibm/uk/hursley/perfharness/amqp/utils/BlockingJavaClient.java
// public static enum AUTO_CONFIRM {
// 	NONE("none","none", false), 
// 	AUTO("auto","auto", false), 
// 	MANUAL("manual","manual", true), 
// 	CONFIRM_AFTER_SENT("confirmaftersent","confirm-after-sent", true);
// 		
// 	private final String match;
// 	private final String perferred;
// 	private final boolean requireConfirmation;
// 		
// 	/**
// 	 * @param match
// 	 * @param perferred
// 	 */
// 	private AUTO_CONFIRM(final String match, final String perferred, final boolean requireConfirmation) {
// 		this.match = match;
// 		this.perferred = perferred;
// 		this.requireConfirmation = requireConfirmation;
// 	}
// 		
// 	/**
// 	 * @return <String> listing the possible options.
// 	 */
// 	public static String options () {
// 		StringBuilder sb = new StringBuilder ();
// 		String separator = "";
// 		for (AUTO_CONFIRM autoConfirm : AUTO_CONFIRM.values()) {
// 			sb.append(separator); separator=",";
// 			sb.append(autoConfirm.perferred);
// 		}
// 		return sb.toString();
// 	}
// 		
// 	/**
// 	 * @return
// 	 */
// 	public boolean doesRequireConfirmation () {
// 		return requireConfirmation;
// 	}
// 		
// 	/**
// 	 * @param text
// 	 * @return
// 	 */
// 	public static AUTO_CONFIRM getValue(final String text) {
// 		String searchValue = text.toLowerCase().replaceAll("-|_", "");
// 		for (AUTO_CONFIRM autoConfirm : AUTO_CONFIRM.values()) {
// 			if (autoConfirm.match.equals(searchValue)) {
// 				return autoConfirm;
// 			}
// 		}
// 		return null;
// 	}
// }
// 
// Path: AMQPPerfHarness/src/com/ibm/uk/hursley/perfharness/amqp/utils/EmbeddedActionContainer.java
// public class EmbeddedActionContainer {
// 	
// 	private final EmbeddedAction embeddedAction;
// 	
// 	/**
// 	 * @param delivery
// 	 */
// 	public EmbeddedActionContainer (final Delivery delivery) {
// 		byte[] data;
// 		if (delivery != null) {
// 			if (delivery instanceof StringDelivery) {
// 				data = ((StringDelivery) delivery).getData().getBytes();
// 				embeddedAction = EmbeddedAction.createEmbeddedAction(data);
// 			}
// 			else if (delivery instanceof BytesDelivery) {
// 				ByteBuffer buffer = ((BytesDelivery) delivery).getData();
// 				embeddedAction = EmbeddedAction.createEmbeddedAction(buffer.array());
// 			}
// 			else {
// 				embeddedAction = null;
// 			}
// 		}
// 		else {
// 			embeddedAction = null;
// 		}
// 	}
// 
// 	
// 	/**
// 	 * @param key
// 	 * @param defaultValue
// 	 * @return
// 	 */
// 	public String getValue(final String key, final String defaultValue) {
// 		String value = defaultValue;
// 		if (embeddedAction != null) value = embeddedAction.getCommand(key, defaultValue);
// 		return value;
// 	}
// 	
// 	/**
// 	 * @param key
// 	 * @return
// 	 */
// 	public String getValue(final String key) {
// 		return getValue(key, null);
// 	}
// 
// 
// 	@Override
// 	public String toString() {
// 		return "EmbeddedActionContainer [embeddedAction=" + embeddedAction + "]";
// 	}
// 	
// 	
// }


import java.nio.ByteBuffer;
import java.util.logging.Level;
import com.ibm.mqlight.api.BytesDelivery;
import com.ibm.mqlight.api.Delivery;
import com.ibm.mqlight.api.StringDelivery;
import com.ibm.uk.hursley.perfharness.Config;
import com.ibm.uk.hursley.perfharness.WorkerThread;
import com.ibm.uk.hursley.perfharness.amqp.utils.BlockingJavaClient.AUTO_CONFIRM;
import com.ibm.uk.hursley.perfharness.amqp.utils.EmbeddedActionContainer;
	/* (non-Javadoc)
	 * @see com.ibm.uk.hursley.perfharness.WorkerThread.Paceable#oneIteration()
	 */
	public boolean oneIteration() throws Exception {

		Delivery delivery = client.receiveMessage();
		if (delivery == null && !shutdown) {
			log(Level.SEVERE, "({0}) has lost its connection.", getName());
			if (failureOnLostConnection) {
				throw new AMQPException("Connection to AMQP Server has been lost.");
			}
		} else {
			// collect embedded key/values from within the message being transferred
			EmbeddedActionContainer eac = new EmbeddedActionContainer(delivery);
			String reference = eac.getValue("Reference");
			String reply2Topic = eac.getValue("Reply2Topic", inboundTopic);
			
			if (delivery != null) {
				if (client.getAutoConfirm() == AUTO_CONFIRM.MANUAL) {
					delivery.confirm();
				}
				if (delivery instanceof StringDelivery) {
					String message = ((StringDelivery) delivery).getData();
					client.sendMessage(reference, reply2Topic, message);
				} else if (delivery instanceof BytesDelivery) {
					ByteBuffer message = ((BytesDelivery) delivery).getData();
					client.sendMessage(reference, reply2Topic, message);
				} else {
					throw new ResponderException("Received unsupport message type of " + delivery.getClass().getName());
				}
// Path: AMQPPerfHarness/src/com/ibm/uk/hursley/perfharness/amqp/utils/BlockingJavaClient.java
// public static enum AUTO_CONFIRM {
// 	NONE("none","none", false), 
// 	AUTO("auto","auto", false), 
// 	MANUAL("manual","manual", true), 
// 	CONFIRM_AFTER_SENT("confirmaftersent","confirm-after-sent", true);
// 		
// 	private final String match;
// 	private final String perferred;
// 	private final boolean requireConfirmation;
// 		
// 	/**
// 	 * @param match
// 	 * @param perferred
// 	 */
// 	private AUTO_CONFIRM(final String match, final String perferred, final boolean requireConfirmation) {
// 		this.match = match;
// 		this.perferred = perferred;
// 		this.requireConfirmation = requireConfirmation;
// 	}
// 		
// 	/**
// 	 * @return <String> listing the possible options.
// 	 */
// 	public static String options () {
// 		StringBuilder sb = new StringBuilder ();
// 		String separator = "";
// 		for (AUTO_CONFIRM autoConfirm : AUTO_CONFIRM.values()) {
// 			sb.append(separator); separator=",";
// 			sb.append(autoConfirm.perferred);
// 		}
// 		return sb.toString();
// 	}
// 		
// 	/**
// 	 * @return
// 	 */
// 	public boolean doesRequireConfirmation () {
// 		return requireConfirmation;
// 	}
// 		
// 	/**
// 	 * @param text
// 	 * @return
// 	 */
// 	public static AUTO_CONFIRM getValue(final String text) {
// 		String searchValue = text.toLowerCase().replaceAll("-|_", "");
// 		for (AUTO_CONFIRM autoConfirm : AUTO_CONFIRM.values()) {
// 			if (autoConfirm.match.equals(searchValue)) {
// 				return autoConfirm;
// 			}
// 		}
// 		return null;
// 	}
// }
// 
// Path: AMQPPerfHarness/src/com/ibm/uk/hursley/perfharness/amqp/utils/EmbeddedActionContainer.java
// public class EmbeddedActionContainer {
// 	
// 	private final EmbeddedAction embeddedAction;
// 	
// 	/**
// 	 * @param delivery
// 	 */
// 	public EmbeddedActionContainer (final Delivery delivery) {
// 		byte[] data;
// 		if (delivery != null) {
// 			if (delivery instanceof StringDelivery) {
// 				data = ((StringDelivery) delivery).getData().getBytes();
// 				embeddedAction = EmbeddedAction.createEmbeddedAction(data);
// 			}
// 			else if (delivery instanceof BytesDelivery) {
// 				ByteBuffer buffer = ((BytesDelivery) delivery).getData();
// 				embeddedAction = EmbeddedAction.createEmbeddedAction(buffer.array());
// 			}
// 			else {
// 				embeddedAction = null;
// 			}
// 		}
// 		else {
// 			embeddedAction = null;
// 		}
// 	}
// 
// 	
// 	/**
// 	 * @param key
// 	 * @param defaultValue
// 	 * @return
// 	 */
// 	public String getValue(final String key, final String defaultValue) {
// 		String value = defaultValue;
// 		if (embeddedAction != null) value = embeddedAction.getCommand(key, defaultValue);
// 		return value;
// 	}
// 	
// 	/**
// 	 * @param key
// 	 * @return
// 	 */
// 	public String getValue(final String key) {
// 		return getValue(key, null);
// 	}
// 
// 
// 	@Override
// 	public String toString() {
// 		return "EmbeddedActionContainer [embeddedAction=" + embeddedAction + "]";
// 	}
// 	
// 	
// }


// Path: AMQPPerfHarness/src/com/ibm/uk/hursley/perfharness/amqp/Responder.java
import java.nio.ByteBuffer;
import java.util.logging.Level;
import com.ibm.mqlight.api.BytesDelivery;
import com.ibm.mqlight.api.Delivery;
import com.ibm.mqlight.api.StringDelivery;
import com.ibm.uk.hursley.perfharness.Config;
import com.ibm.uk.hursley.perfharness.WorkerThread;
import com.ibm.uk.hursley.perfharness.amqp.utils.BlockingJavaClient.AUTO_CONFIRM;
import com.ibm.uk.hursley.perfharness.amqp.utils.EmbeddedActionContainer;

	/* (non-Javadoc)
	 * @see com.ibm.uk.hursley.perfharness.WorkerThread.Paceable#oneIteration()
	 */
	public boolean oneIteration() throws Exception {

		Delivery delivery = client.receiveMessage();
		if (delivery == null && !shutdown) {
			log(Level.SEVERE, "({0}) has lost its connection.", getName());
			if (failureOnLostConnection) {
				throw new AMQPException("Connection to AMQP Server has been lost.");
			}
		} else {
			// collect embedded key/values from within the message being transferred
			EmbeddedActionContainer eac = new EmbeddedActionContainer(delivery);
			String reference = eac.getValue("Reference");
			String reply2Topic = eac.getValue("Reply2Topic", inboundTopic);
			
			if (delivery != null) {
				if (client.getAutoConfirm() == AUTO_CONFIRM.MANUAL) {
					delivery.confirm();
				}
				if (delivery instanceof StringDelivery) {
					String message = ((StringDelivery) delivery).getData();
					client.sendMessage(reference, reply2Topic, message);
				} else if (delivery instanceof BytesDelivery) {
					ByteBuffer message = ((BytesDelivery) delivery).getData();
					client.sendMessage(reference, reply2Topic, message);
				} else {
					throw new ResponderException("Received unsupport message type of " + delivery.getClass().getName());
				}
				if (client.getAutoConfirm() == AUTO_CONFIRM.CONFIRM_AFTER_SENT)