guarana.framework.task
Class Task

java.lang.Object
  extended by guarana.util.observer.smart.SmartObservable
      extended by guarana.framework.task.Task
All Implemented Interfaces:
ISource, guarana.util.observer.smart.ISmartObserver
Direct Known Subclasses:
Communicator, Mapper, Modifier, Router, StreamDealer, Timer, Transformer

public abstract class Task
extends guarana.util.observer.smart.SmartObservable
implements ISource, guarana.util.observer.smart.ISmartObserver

A generic implementation of task in Guaranį DSL.

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

Field Summary
 Gateway[] input
          Stores all input gateways of this task.
 Gateway[] output
          Stores all output gateways of this task.
 
Constructor Summary
Task(String name)
          Constructs a new task with the specified name.
Task(String name, int numberOfInputs, int numberOfOutputs)
          Creates a task with the specified name and number of input and output gateways.
 
Method Summary
 void doWork(Exchange exchange)
          This method implements the business logic of this task.
 void execute()
          This method executes the business logic of this task.
 String getName()
          Returns the name of this source.
 long getTriggerInterval()
          Returns the trigger interval for this task.
 boolean isTriggerTask()
          Checks if this task is a trigger task.
 void setName(String name)
          Sets the name of this source.
 void setTriggerInterval(long triggerInterval)
          Sets a trigger interval to this task.
 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.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
 

Field Detail

input

public Gateway[] input
Stores all input gateways of this task.
The first input gateway is accessed with input[0], the second input[1], and so on...


output

public Gateway[] output
Stores all output gateways of this task.
The first output gateway is accessed with output[0], the second output[1], and so on...

Constructor Detail

Task

public Task(String name)
Constructs a new task with the specified name. By default this task is not a trigger task. To turn it into a trigger task you must set the trigger interval.

Parameters:
name - The name of the task.

Task

public Task(String name,
            int numberOfInputs,
            int numberOfOutputs)
Creates a task with the specified name and number of input and output gateways. By default this task is not a trigger task. To turn it into a trigger task you must set the trigger interval.

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.
Method Detail

execute

public void execute()
             throws TaskExecutionException
This method executes the business logic of this task. It is automatically invoked by workers.

Throws:
TaskExecutionException - to report any exception that has occurred during the execution of this method.
See Also:
TaskExecutionException

doWork

public void doWork(Exchange exchange)
            throws TaskExecutionException
This method implements the business logic of this 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.

isTriggerTask

public boolean isTriggerTask()
Checks if this task is a trigger task.

Returns:
True if this is a trigger task; otherwise, False.

setName

public void setName(String name)
Sets the name of this source.

Specified by:
setName in interface ISource
Specified by:
setName in interface guarana.util.observer.smart.ISmartObserver
Parameters:
name - The name of this source.

getName

public String getName()
Returns the name of this source.

Specified by:
getName in interface ISource
Specified by:
getName in interface guarana.util.observer.smart.ISmartObserver
Returns:
the name of this source.

setTriggerInterval

public void setTriggerInterval(long triggerInterval)
Sets a trigger interval to this task. Having a trigger interval means that this task must be executed every trigger interval time. Setting the value of trigger interval to -1 means the task is not a trigger task.

Parameters:
triggerInterval - The interval in milliseconds that this task must be executed.

getTriggerInterval

public long getTriggerInterval()
Returns the trigger interval for this task.

Returns:
-1 if the task is not a trigger task; otherwise a positive value in milliseconds which define the trigger interval.

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.

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


Guaranį DSL Home