CTimer

The CTimer class is a helper class for using timers.

Constructor

The constructor expects the same arguments as the method to start a timer, plus the reference to the timer manager.

These are

  • a record ID to identify the message
  • a target address for which target the message is to be received
  • a timeout in milliseconds (when does the message arrive)
  • a flag whether the message should be repeated
  • an optional record for payload data
public CTimer(@NotNull final ITimerManager aManager,
              @NotNull final IId aId,
              @NotNull final CTargetAddress aAddress,
              final long aDelay,
              final boolean aRepeat,
              @Nullable final CRecord aTemplate)

This does not start the timer yet, it only saves the timer data.

Starting the timer

The timer is started if it has not yet been started.

public void startIf();

Another method started the timer as before. However, if the timer has already been started, it will be reset and then restarted.

public void startIfElseReset();

Dismissing a timer

The timer can be stopped at any time. A timer that is not to be repeated is automatically deleted after the message is sent. However, it can be restarted at any time.

public void dismiss();

Message arrived

For the use of one-time timers it is useful to let the timer class know that the message has arrived. This resets the internal handle and the timer can be restarted later.

public void notifyTriggerOccurred();

Delay

The value for the timeout can be fetched and changed. However, the change only comes into effect when the startIfElseReset() method is called. The unit of time used is milliseconds.

public long getDelay();
public void setDelay(final long aDelay);

Counter

The class keeps a counter that counts each restart.

public int getCounter();
public void resetCounter();

nyssr.net - Innovative Distributed System