SampleSubsystem.java code sample

 

+

Search Tips   |   Advanced Search

 

This is an example of SampleSubsystem.java.


SampleSubsystem.java

package test;

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 RPT 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();

    // Allow for waiting for something to appear on the queue
    sampleSubsystemQueue.setBlocking(true);      
  }

  /*
   * 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) 
    {
      // Informs engine subsystem is healthy
      ringIn();        
      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) 
      {
        // Good for debugging
        updateJob("Servicing " + client.getName());  
        
        client.setServiced();

        // Serviced action leaves subsystem
        dispatch(client);    
      }
    }
  }
}