guarana.toolkit.task.timers
Class Delayer

java.lang.Object
  extended by guarana.util.observer.smart.SmartObservable
      extended by guarana.framework.task.Task
          extended by guarana.toolkit.task.timers.Timer
              extended by guarana.toolkit.task.timers.Delayer
All Implemented Interfaces:
ISource, guarana.util.observer.smart.ISmartObserver

public abstract class Delayer
extends Timer

Delays an inbound message for a while before publishing it to the output gateway. The outbound and inbound messages are exactly the same, so MESSAGE_ID is the same too! This task must be used carefully since the associated thread that is executing this task sleeps the necessary amount of time the message must be delayed.

Graphical notation:


This is an Integration Pattern implementation

Problem: How do we delay a message inside the integration flow that connects source(s) and target(s) applications?

Solution: Use a Delayer that takes away from the integration flow a message for a while, and then publishes it back after the delay time had expired.

Details:

Since:
Guaranį SDK 1.0.0
Author:
Rafael Z. Frantz

Field Summary
 
Fields inherited from class guarana.framework.task.Task
input, output
 
Constructor Summary
Delayer(String name, int numberOfInputs, int numberOfOutputs, long delayTime)
          Constructs a new delayer task.
Delayer(String name, long delayTime)
          Constructs a new delayer task.
 
Method Summary
 void doWork(Exchange exchange)
          This method implements the business logic of this task.
 long getDelayTime()
          Returns the time this task have to delay the message.
 void setDelayTime(long delayTime)
          Sets the time this task have to delay the message.
 void update(guarana.util.observer.smart.SmartObservable slot, Object arg)
          This method is automatically called by the observable slot to notify the slot has received a message.
 
Methods inherited from class guarana.framework.task.Task
execute, getName, getTriggerInterval, isTriggerTask, setName, setTriggerInterval
 
Methods inherited from class guarana.util.observer.smart.SmartObservable
addSmartObserver, containsSmartObserver, containsSmartObserver, countSmartObservers, deleteSmartObserver, deleteSmartObservers, hasChanged, notifySmartObservers, notifySmartObservers
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Delayer

public Delayer(String name,
               long delayTime)
Constructs a new delayer task.

Parameters:
name - The name of this task.
delayTime - The time this task have to delay the message.

Delayer

public Delayer(String name,
               int numberOfInputs,
               int numberOfOutputs,
               long delayTime)
Constructs a new delayer task.

Parameters:
name - The name of this task.
numberOfInputs - The number of input gateways this task must have.
numberOfOutputs - The number of output gateways this task must have.
delayTime - The time this task have to delay the message.
Method Detail

doWork

public void doWork(Exchange exchange)
            throws TaskExecutionException
This method implements the business logic of this task.
Delays the inbound message.

Overrides:
doWork in class Task
Parameters:
exchange - An exchange object that holds the inbound messages of this task.
Throws:
TaskExecutionException - to report any exception that has occurred during the execution of this method.

update

public void update(guarana.util.observer.smart.SmartObservable slot,
                   Object arg)
This method is automatically called by the observable slot to notify the slot has received a message. For all those tasks that can execute with one or more messages in its input slots, this method will add the task to the executable task reporter, so it can be executed. In this case the task execution will consume messages from all input slots.
Please, do not call this method by yourself. Overrides the implementation at Task for performance reasons.

Specified by:
update in interface guarana.util.observer.smart.ISmartObserver
Overrides:
update in class Task
Parameters:
slot - The Slot associated with this task.
arg - THIS PARAMETHER IS NOT USED.

setDelayTime

public void setDelayTime(long delayTime)
Sets the time this task have to delay the message.

Parameters:
delayTime - The delayTime to set.

getDelayTime

public long getDelayTime()
Returns the time this task have to delay the message.

Returns:
the delay time.


Guaranį DSL Home