SampleSubsystem.java code sample

This is an example of SampleSubsystem.java.

SampleSubsystem.java

package customcode;

import com.ibm.rational.test.lt.kernel.action.IKAction;
import com.ibm.rational.test.lt.kernel.engine.impl.Queue;
import com.ibm.rational.test.lt.kernel.impl.KSubsystem;

/**
 * Sample HOT-PERF Engine Subsystem
 */

public class SampleSubsystem extends KSubsystem {
	private Queue sampleSubsystemQueue;
	private boolean stopRequested = false;
	private SampleAction client;

	public SampleSubsystem(String name) {
		super(name);
		sampleSubsystemQueue = new Queue();
		sampleSubsystemQueue.setBlocking(true);			// Allows for waiting for something to appear on the queue
	}

	/*
	 * Actions enter the subsystem for service via a call to enqueue().
	 * An action can get a reference to the subystem using the IKAction
	 * getSubsystem() method.
	 * 
	 * @see com.ibm.rational.test.lt.kernel.IKSubsystem#enqueue(com.ibm.rational.test.lt.kernel.action.IKAction)
	 */
	public void enqueue(IKAction action) {
		sampleSubsystemQueue.enqueue(action);
	}

	/*
	 * Message to the subsystem to stop.
	 * 
	 * @see com.ibm.rational.test.lt.kernel.IKSubsystem#shutdown()
	 */
	public void shutdown() {
		stopRequested = true;
	}

	/*
	 * @see java.lang.Thread#run()
	 */
	public void run() {
		while(!stopRequested) {
			ringIn();				// Informs engine subsystem is healthy
			client = null;
			
			// If nothing to do wait for work
			updateJob("Idle");
			client = (SampleAction)sampleSubsystemQueue.dequeue(pingTime);

			// This subsystem's work will be to touch an attribute of the action
			if (client != null) {
				updateJob("Servicing " + client.getName());	// Good for debugging
				
				client.setServiced();
				dispatch(client);		// Serviced action leaves subsystem
			}
		}
	}
}
Feedback