org.pf.util
Class Trigger

java.lang.Object
  extended by org.pf.util.Trigger
All Implemented Interfaces:
java.lang.Runnable

public class Trigger
extends java.lang.Object
implements java.lang.Runnable

A trigger is an object that runs in a separate thread and waits for a specified time until it calls a specific method of a trigger client (see TriggerClient). Before it actually calls the client's triggerdBy() method it checks the client's canBeTriggered() method that allows it or not. After the client's triggerdBy() method was called the trigger waits again until the end of its waiting period.

Version:
1.1
Author:
Manfred Duchrow

Method Summary
 java.lang.String getName()
          Returns the name of the trigger
static Trigger launch(java.lang.String name, TriggerClient client, long intervalInMs)
          Launch a new trigger with the given name for the given client, that calls the triggeredBy method of the client every intervalInMs milliseconds.
 void run()
          Implementation of Runnable.
 void terminate()
          Terminates the trigger.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getName

public java.lang.String getName()
Returns the name of the trigger


launch

public static Trigger launch(java.lang.String name,
                             TriggerClient client,
                             long intervalInMs)
Launch a new trigger with the given name for the given client, that calls the triggeredBy method of the client every intervalInMs milliseconds.
The ne trigger will be created and immediately started in a separate thread.

Parameters:
name - The name of the trigger (must not be null)
client - The client that gets triggered (must not be null)
intervalInMs - The interval after that the client regularily gets triggered (must be greater than 0)
Returns:
The newly created trigger
Throws:
java.lang.IllegalArgumentException - if any of the given arguments is null
See Also:
TriggerClient

terminate

public void terminate()
Terminates the trigger. That means the thread the trigger used internally will be stopped when it awakes the next time (depends on interval)


run

public void run()
Implementation of Runnable.

Must not be called directly!

Specified by:
run in interface java.lang.Runnable