api
Class Task

java.lang.Object
  extended by api.Task
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
ChatRouterTask, DistributedChatServerTask

public abstract class Task
extends java.lang.Object
implements java.io.Serializable

Interface for a Task object.

Author:
Sean Ford, Nick Childers
See Also:
Serialized Form

Constructor Summary
Task()
           
 
Method Summary
 void broadcastMessage(java.lang.String message)
          Broadcast a message to other Tasks.
 java.lang.Long getComputerId()
           
 java.lang.Long getId()
          Get Task Id
 java.lang.Integer getListenPort()
           
 NetworkMessage getMessage()
          Attempt to read a NetworkMessage from the router.
 java.nio.channels.SocketChannel getRouterSocketChannel()
          Return the SocketChannel to the Router
abstract  java.lang.Object run()
          Method to run the task.
 void setComputer(Computer computer)
          Set the computer that is running this task.
 void setId(java.lang.Long id)
          Set task id.
 void setListenPort(java.lang.Integer listenPort)
           
 void unicastMessage(java.lang.Long destinationAddress, java.lang.String message)
          Send a unicast message to a specific Task.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Task

public Task()
Method Detail

run

public abstract java.lang.Object run()
Method to run the task.

Returns:
Object result, pretty much anything

getId

public java.lang.Long getId()
Get Task Id

Returns:

setId

public void setId(java.lang.Long id)
Set task id. Only Space should call this.

Parameters:
id -

setComputer

public void setComputer(Computer computer)
Set the computer that is running this task. This should never be called by the Task itself. Its only purpose is to give setShared() method access to the computer to share the Shared object.

Parameters:
computer -

getComputerId

public java.lang.Long getComputerId()

getMessage

public NetworkMessage getMessage()
                          throws java.io.IOException
Attempt to read a NetworkMessage from the router. Returns NULL if no messages are waiting to be read.

Returns:
Throws:
java.io.IOException

broadcastMessage

public void broadcastMessage(java.lang.String message)
                      throws java.io.IOException
Broadcast a message to other Tasks.

Parameters:
message -
Throws:
java.io.IOException

unicastMessage

public void unicastMessage(java.lang.Long destinationAddress,
                           java.lang.String message)
                    throws java.io.IOException
Send a unicast message to a specific Task.

Parameters:
destinationAddress -
message -
Throws:
java.io.IOException

getRouterSocketChannel

public java.nio.channels.SocketChannel getRouterSocketChannel()
Return the SocketChannel to the Router

Returns:

getListenPort

public java.lang.Integer getListenPort()

setListenPort

public void setListenPort(java.lang.Integer listenPort)