de.upb.swtpra05.group03.shuttle
Class ShuttleControl

java.lang.Object
  extended byjava.lang.Thread
      extended byde.upb.swtpra.kernel.Agent
          extended byde.upb.swtpra.kernel.ShuttleAgentBase
              extended byde.upb.swtpra05.group03.shuttle.ShuttleControl
All Implemented Interfaces:
Module, java.lang.Runnable, ShuttleControlInterface, ShuttleModule
Direct Known Subclasses:
ICabSShuttle

public abstract class ShuttleControl
extends de.upb.swtpra.kernel.ShuttleAgentBase
implements ShuttleModule, ShuttleControlInterface

Represents the shuttle by extending ShuttleAgentBase, forwards all received messages to all ShuttleModules and controls the states of the orders.

Version:
$Revision: 1.3 $

Field Summary
private  CryptoMessagesHandlerInterface cryptoMsgHandler
          this class encrypts all messages to the company control and decrypts all messages received from them
(package private) static java.util.logging.Logger log
          Define a static logger variable to output logmessages
private  de.upb.swtpra.kernel.id.KernelID myKernelID
          The ID of the kernel
private  boolean running
          Flag to control the shuttles status
private  java.util.LinkedList sendQueue
          Queue of outgoing Messages which coudln't be sent by the time they were supposed to
private  java.util.List sentModules
          A Collection containing all SentModules
private  java.util.List shuttleModules
          A Collection containing all ShuttleModules
 
Fields inherited from class de.upb.swtpra.kernel.ShuttleAgentBase
 
Fields inherited from class de.upb.swtpra.kernel.Agent
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
ShuttleControl(de.upb.swtpra.kernel.id.KernelID id)
          Constructor of ShuttleControl
 
Method Summary
private  void deliverToSentModules(de.upb.swtpra.kernel.message.Message msg)
          Delivers a Message to any SentModule.
private  void deliverToShuttleModules(de.upb.swtpra.kernel.message.Message msg)
          Delivers a Message to any ShuttleModule.
private  void gameConstants(de.upb.swtpra.kernel.message.GameConstantsMessage msg)
          Sets the size of the company the shuttle is member of and gets if needed the associates
 de.upb.swtpra.kernel.id.ID getMyAgentID()
          Forwards the method getAgentID() from ShuttleAgentBase
 de.upb.swtpra.kernel.id.ID getMyBankingAgentID()
          Forwards the method getBankingAgentID() from ShuttleAgentBase
 de.upb.swtpra.kernel.id.ID getMyBrokerAgentID()
          Forwards the method getBrokerID() from ShuttleAgentBase
 de.upb.swtpra.kernel.id.ID getMyKernelID()
          Gets the KernelID attribute of the ShuttleControl object
 void init(ModuleContainerInterface container)
          Initializes this module.
private  java.util.LinkedList makeShuttleReady()
          Initalizes the shuttle so that the shuttle is ready.
 void newMessageReceived(de.upb.swtpra.kernel.message.Message msg)
          Delivers a new Message to ShuttleModule.
 void run()
          Main processing method for the ShuttleControl object which especially inherits from Thread
 void sendMessage(de.upb.swtpra.kernel.message.Message msg)
          helper to send messages out call this instead of sendNextMessage()
private  void sendQueuedMessages()
          Tries to send all Messages which couldn't be sent by the time they were supposed to.
private static void sendToBed(long time)
          Lets the shuttle sleep for the specified period of time or till an InterruptedException is thrown
 
Methods inherited from class de.upb.swtpra.kernel.ShuttleAgentBase
getBankingAgentID, getBrokerID, getCompanyLogin, getCompanyPassword, getTopologyID, receive, register, sendNextMessage
 
Methods inherited from class de.upb.swtpra.kernel.Agent
getAgentID, getNextMessage, isMessageAvailable, send, setAgentID
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setName, setPriority, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

log

static final java.util.logging.Logger log
Define a static logger variable to output logmessages


myKernelID

private de.upb.swtpra.kernel.id.KernelID myKernelID
The ID of the kernel


running

private boolean running
Flag to control the shuttles status


shuttleModules

private java.util.List shuttleModules
A Collection containing all ShuttleModules


sentModules

private java.util.List sentModules
A Collection containing all SentModules


sendQueue

private java.util.LinkedList sendQueue
Queue of outgoing Messages which coudln't be sent by the time they were supposed to


cryptoMsgHandler

private CryptoMessagesHandlerInterface cryptoMsgHandler
this class encrypts all messages to the company control and decrypts all messages received from them

Constructor Detail

ShuttleControl

public ShuttleControl(de.upb.swtpra.kernel.id.KernelID id)
Constructor of ShuttleControl

Parameters:
id - The ID of the Kernel
Method Detail

init

public void init(ModuleContainerInterface container)
Description copied from interface: Module
Initializes this module. References to other modules should be set here to avoid circle dependencies.

Specified by:
init in interface Module
Parameters:
container - The module manager which contain all modules

run

public void run()
Main processing method for the ShuttleControl object which especially inherits from Thread

Specified by:
run in interface java.lang.Runnable

deliverToShuttleModules

private void deliverToShuttleModules(de.upb.swtpra.kernel.message.Message msg)
Delivers a Message to any ShuttleModule.

Parameters:
msg - The Message to deliver

deliverToSentModules

private void deliverToSentModules(de.upb.swtpra.kernel.message.Message msg)
Delivers a Message to any SentModule.

Parameters:
msg - The Message to deliver

newMessageReceived

public void newMessageReceived(de.upb.swtpra.kernel.message.Message msg)
Delivers a new Message to ShuttleModule. An instance will receive any message received by the Shuttle and react whether the received message is of any interest

Specified by:
newMessageReceived in interface ShuttleModule
Parameters:
msg - The Message to deliver

makeShuttleReady

private java.util.LinkedList makeShuttleReady()
Initalizes the shuttle so that the shuttle is ready. The Topology, the GameConstants, the ShuttleStatus, the CurrentAccountBalance and the ShuttleAssociates is requested

Returns:
all not handled messages

sendQueuedMessages

private void sendQueuedMessages()
Tries to send all Messages which couldn't be sent by the time they were supposed to. The method will pause the thread in case of sendQueue holds too many messages


gameConstants

private void gameConstants(de.upb.swtpra.kernel.message.GameConstantsMessage msg)
Sets the size of the company the shuttle is member of and gets if needed the associates

Parameters:
msg - The received GameConstantsMessage

sendToBed

private static void sendToBed(long time)
Lets the shuttle sleep for the specified period of time or till an InterruptedException is thrown

Parameters:
time - The time the shuttle should sleep

sendMessage

public void sendMessage(de.upb.swtpra.kernel.message.Message msg)
helper to send messages out call this instead of sendNextMessage()

Specified by:
sendMessage in interface ShuttleControlInterface
Parameters:
msg - message to send

getMyAgentID

public de.upb.swtpra.kernel.id.ID getMyAgentID()
Forwards the method getAgentID() from ShuttleAgentBase

Specified by:
getMyAgentID in interface ShuttleControlInterface
Returns:
The getAgentID() value

getMyBankingAgentID

public de.upb.swtpra.kernel.id.ID getMyBankingAgentID()
Forwards the method getBankingAgentID() from ShuttleAgentBase

Specified by:
getMyBankingAgentID in interface ShuttleControlInterface
Returns:
The getBankingAgentID() value

getMyBrokerAgentID

public de.upb.swtpra.kernel.id.ID getMyBrokerAgentID()
Forwards the method getBrokerID() from ShuttleAgentBase

Specified by:
getMyBrokerAgentID in interface ShuttleControlInterface
Returns:
The myBrokerID() value

getMyKernelID

public de.upb.swtpra.kernel.id.ID getMyKernelID()
Gets the KernelID attribute of the ShuttleControl object

Specified by:
getMyKernelID in interface ShuttleControlInterface
Returns:
The KernelID value