IBM Support

Using timers in stubs

Question & Answer


Question

How do you use timer callbacks in a stub in IBM Rational Integration Tester (RIT)?

Cause

You wish to design a stub that has a continuous stream of events on a given time interval.
For example you wish to periodically check a directory for a file.
Stubs have a timer event that can be configured to trigger.
This technote adds to the documentation in the product Knowledge Center and provides a sample project to demonstrate the feature.

Answer

Refer to the Modifying message-based stubs section in the Rational Integration Tester Knowledge Center in conjunction with this technote.

TIMER DETAIL:

There are three functions to invoke Timer behavior:

  1. Single timer event after specified elapsed time.

    timer.scheduleTimerEvent (timerTaskId, parameter, delay, delayTimeUnit)

    timerTaskId is an identifier you give to the timer event such that you can cancel it specifically if you wish later.
    parameter is any object that you wish to be presented back at the point the timer event fires (a place to record some state).
    delay is a number which in combination with the delayTimeUnit defines how long into the future the timer event will fire.

    delayTimeUnit is the unit type, for example seconds or hours:

    java.util.concurrent.TimeUnit.SECONDS
    java.util.concurrent.TimeUnit.MILLISECONDS
    java.util.concurrent.TimeUnit.MINUTES

    See the Java Enum TimeUnit page for full details.

  2. Repeating timer event, started after a given time and repeating.

    timer.scheduleRepeatingTimerEvent(timerTaskId, parameter, delay, period, delayTimeUnit)

    timerTaskId is an identifier you give to the timer event such that you can cancel it specifically if you wish later.
    parameter is any object that you wish to be presented back at the point the timer event fires (a place to stash some state).
    delay is a number which in combination with the delayTimeUnit says how long into the future the timer event will initially fire.
    period is a number which in combination with the delayTimeUnit defines how long into the future the timer event will repeatedly fire.
    delayTimeUnit - see single timer above.

  3. Cancel a previously scheduled timer event

    timer.cancelTimerEvent(timerTaskId).

    timerTaskId is an identifier you gave to a previously scheduled timer event.


You can use the stub filtering to take action only when a specified timer has fired.

In this example the timer event is only triggered for the timer named "myTimer ".
You can tag the parameter object and re-use it in further actions.


REPEATING TIMER WORKED EXAMPLE:

In order to use repeating timers you need to add a Lifecycle and Timer to the stub Behavior before adding lifecycle and timer events to the Events. The Lifecycle is used to initialise the timer when the stub starts and the Timer is used to trigger an action and re-trigger it.

A sample project containing this stub is attached to this technote.

Consider the following steps.

  1. Create an empty stub from an operation that has no transport configured.



    Right click the operation in Test Factory and click New > Stubs > Stub.

  2. Open the stub and click the Behavior tab.

  3. Click Add and select Lifecycle and Timer.



  4. Click the Events tab and click and add:

    lifecycle.onStart
    timer.onTimerEvent

  5. Click the lifecycle.onStart event and click its Activity or Business Logic tab. Add a Function action to initialise the timer as shown:

    timer.scheduleRepeatingTimerEvent("id","param",0, 10, java.util.concurrent.TimeUnit.SECONDS)

    This example gives the timer ID of "id" and parameter of "param". It starts after zero seconds and uses a repeat interval of 10 seconds.

  6. Click the timer.onTimerEvent event and click the Activity or Business Logic tab. Add whatever actions you need to run when the timer triggers.

    The timer.onTimerEvent event has an Input tab that enables you to filter on different timer events.
    In this example you only have one timer so there is no need to configure any filter.

 
Disclaimer

All source code and/or binaries attached to this document are referred to here as "the Program". IBM is not providing program services of any kind for the Program. IBM is providing the Program on an "AS IS" basis without warranty of any kind. IBM WILL NOT BE LIABLE FOR ANY ACTUAL, DIRECT, SPECIAL, INCIDENTAL, OR INDIRECT DAMAGES OR FOR ANY ECONOMIC CONSEQUENTIAL DAMAGES (INCLUDING LOST PROFITS OR SAVINGS), EVEN IF IBM, OR ITS RESELLER, HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.

[{"Product":{"code":"SSBLQQ","label":"Rational Test Workbench"},"Business Unit":{"code":"BU004","label":"Hybrid Cloud"},"Component":"Rational Integration Tester","Platform":[{"code":"PF002","label":"AIX"},{"code":"PF016","label":"Linux"},{"code":"PF022","label":"OS X"},{"code":"PF027","label":"Solaris"},{"code":"PF033","label":"Windows"}],"Version":"8.5;8.6","Edition":""}]

Document Information

Modified date:
29 September 2018

UID

swg21682876