Implementing execution for error handling

Events that require error handling at run time must have an associated errorBehavior action. Extend the RPTEventGenerator class to specify event behaviors.

KAction objects handle events by implementing the IRPTEventHandler method. When an event such as a verification-point failure or connection failure occurs, make the following call to the KAction object that is the parent of the event:

KAction.registerEvent(eventType, eventBehavior);

In the previous example, the eventType parameter is the type of failure. The eventBehavior parameter is the action to take when the failure occurs.

During the KAction.finish() procedure, all registered event behaviors are processed. Behaviors that are registered for a specific event are processed. Applicable behaviors that are specified at a higher level in the event hierarchy are processed.

The following code implements the RPTEventGenerator class:

public abstract class RPTEventGenerator implements IRPTEventGenerator{
	RPTEvent behavior = null;
	boolean behaviorSet = false;
	IKAction act = null;
	RPTEvent eventType;
	

	public void setEventBehavior(IKAction act, RPTEvent eventType, RPTEvent behavior){
		behaviorSet = true;
		this.behavior = behavior;
		this.act = act;
		this.eventType = eventType;
	}
	
	public RPTEvent getEventBehavior(){
		return behavior;
	}
	
	public RPTEvent getEventType(){
		return eventType;
	}

	public KAction getAction(){
		return act;
	}
}

The following code examples demonstrate how to implement error handling at run time for the ServerConnection class.

public class ServerConnection extends RPTEventGenerator implements IServerConnection {

public ServerConnection(String name, int port, ISSLInfo sslInfo,
			INtlmAuthenticationContext ntlmContext,
			IProxyServerInfo proxyServerInfo,
			boolean closeWhenTestCompletes, RPTEvent behav) {
		this.serverAddr = new InetAddressInfo(name, port);
		this.sslInfo = sslInfo;
		this.ntlmCxt = ntlmContext;
		this.proxyInfo = proxyServerInfo;
		this.inUse = true;
		this.closeWhenTestCompletes = closeWhenTestCompletes;
		setEventBehavior(null, new RPTConnectEvent(), behav);
	}
}

The behavior for a server connection failure now includes the following code:

	registerEvent(((IRPTEventGenerator)m_Request.getServerConnection()).getEventType(), ((IRPTEventGenerator)m_Request.getServerConnection()).getEventBehavior());
Feedback