guarana.framework.port
Class Port

java.lang.Object
  extended by guarana.util.observer.smart.SmartObservable
      extended by guarana.framework.port.Port
All Implemented Interfaces:
ISource, ITaskContainer, guarana.util.observer.smart.ISmartObserver
Direct Known Subclasses:
OneWayPort, TwoWayPort

public abstract class Port
extends guarana.util.observer.smart.SmartObservable
implements ITaskContainer, ISource

A generic communication port. A port is to abstract away from the details required to interact with an application or with a process. Note that an application is usually composed of several layers, and that usually one or more of them are available, e.g., data layer, data access layer, business logic layer, or user interface layer. Ports can be either entry, exit, solicitor or responder ports, depending on whether they were designed to read messages from a process or an application, or to write messages to them, and to respond or query an application for data.
Note that ports usually need to transform the messages they transfer, which implies that they are composed of tasks, as well. This implies that they also need slots to help their tasks work as much asynchronously as possible. Another subtle implication is that there must be a slot to communicate a task in a port to a task in the process to which the port belongs. We refer to such slots interslots.

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

Constructor Summary
Port(String name)
          Constructs a new port with the given name.
Port(String name, Process process)
          Constructs a port with the given name and associates it with the given process.
 
Method Summary
 void addPreScheduledTask(Task task)
          Adds a trigger task as a pre-scheduled task to this task reporter.
 Task addTask(Task task)
          Adds a given task to this task container.
 boolean containsPreScheduledTasks()
          Checks if this object contains a pre-scheduled task.
 boolean containsTask(String name)
          Searches for a given task name inside this task container.
 int countTask()
          Counts the tasks inside this task container.
 Collection<Task> getAllTasks()
          Returns all tasks inside this task container.
 Task getCommunicator()
          Returns the communicator for this port.
 String getName()
          Returns the name of this source.
 Process getProcess()
          Return this process to which belongs this port.
 Task getTask(String name)
          Searches for a task with a given name inside this task container.
 void initialise()
          A syntactic sugar method to create anonymous classes for this port.
 List<Task> pollPreScheduledTasks()
          Polls all pre-scheduled tasks from this object.
 Task removeTask(String name)
          Removes a given task from this task container.
 void setCommunicator(Task communicator)
          Sets the communicator for this port.
 void setName(String name)
          Sets the name of this source.
 void setProcess(Process process)
          Sets this process to which belongs this port.
 void update(guarana.util.observer.smart.SmartObservable obj, Object task)
          This method is automatically called by the observable task to notify the task is ready to be executed.
 
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

Port

public Port(String name)
Constructs a new port with the given name.

Parameters:
name - The name of this new port.

Port

public Port(String name,
            Process process)
Constructs a port with the given name and associates it with the given process.

Parameters:
name - The name of this new port.
process - The process to which the port will belong.
Method Detail

initialise

public void initialise()
A syntactic sugar method to create anonymous classes for this port. This method is automatically called by the port's constructor.


addPreScheduledTask

public void addPreScheduledTask(Task task)
Adds a trigger task as a pre-scheduled task to this task reporter.

Parameters:
task - The trigger task to pre-schedule

containsPreScheduledTasks

public boolean containsPreScheduledTasks()
Checks if this object contains a pre-scheduled task.

Returns:
True if there is at least one pre-scheduled task; otherwise, False.

pollPreScheduledTasks

public List<Task> pollPreScheduledTasks()
Polls all pre-scheduled tasks from this object.

Returns:
a list that contains all pre-scheduled tasks.

getProcess

public Process getProcess()
Return this process to which belongs this port.

Returns:
the process.

setProcess

public void setProcess(Process process)
Sets this process to which belongs this port.

Parameters:
process - The process.

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.

addTask

public Task addTask(Task task)
             throws InvalidParameterException
Adds a given task to this task container.

Specified by:
addTask in interface ITaskContainer
Parameters:
task - The task to be added.
Returns:
the previous task already in the container if the new one has the same name or null if there is no previous task.
Throws:
InvalidParameterException - if the task parameter is null.

containsTask

public boolean containsTask(String name)
Searches for a given task name inside this task container.

Specified by:
containsTask in interface ITaskContainer
Parameters:
name - The task name to be searched.
Returns:
True if there is a corresponding task to the given name; otherwise, False.

countTask

public int countTask()
Counts the tasks inside this task container.

Specified by:
countTask in interface ITaskContainer
Returns:
the number of tasks.

getAllTasks

public Collection<Task> getAllTasks()
Returns all tasks inside this task container.

Specified by:
getAllTasks in interface ITaskContainer
Returns:
a collection with all tasks.

getTask

public Task getTask(String name)
Searches for a task with a given name inside this task container.

Specified by:
getTask in interface ITaskContainer
Parameters:
name - The task name.
Returns:
the task associated with the given name or null if none.

removeTask

public Task removeTask(String name)
Removes a given task from this task container.

Specified by:
removeTask in interface ITaskContainer
Parameters:
name - The name of the task to remove.
Returns:
the removed task or null if there is no task associated with this name.

setCommunicator

public void setCommunicator(Task communicator)
                     throws InvalidParameterException
Sets the communicator for this port.

Parameters:
communicator - The communicator task.
Throws:
InvalidParameterException - if the communicator parameter is null.

getCommunicator

public Task getCommunicator()
Returns the communicator for this port.

Returns:
the communicator task.

update

public void update(guarana.util.observer.smart.SmartObservable obj,
                   Object task)
            throws IllegalStateException
This method is automatically called by the observable task to notify the task is ready to be executed. Please, do not call this method by yourself.

Specified by:
update in interface guarana.util.observer.smart.ISmartObserver
Parameters:
obj - THIS PARAMETHER IS NOT USED.
task - The observable task.
Throws:
IllegalStateException


Guaranį DSL Home