orca.shirako.kernel
Class ConcurrentTick

java.lang.Object
  extended by orca.shirako.kernel.ConcurrentTick
All Implemented Interfaces:
IInitialize, ITicker

public class ConcurrentTick
extends java.lang.Object
implements IInitialize, ITicker


Nested Class Summary
protected  class ConcurrentTick.Ticker
          This is the main timer thread.
 
Field Summary
protected  long beginningOfTime
          Cycle offset in milliseconds.
protected  ActorClock clockFactory
          The clock factory.
protected  java.lang.Object clockLock
          Lock controlling the access to cycle.
protected  long cycle
          The current clock value.
protected  long cycleMillis
          Cycle length in milliseconds.
protected  LoggingTool logger
          The logger.
protected  boolean manual
           
protected  boolean stopped
          Are we active?
protected  java.util.Hashtable<ITick,orca.shirako.kernel.ConcurrentTick.ItemTicker> tickers
          All tickable items.
protected  ConcurrentTick.Ticker timer
          The timer thread.
 
Constructor Summary
ConcurrentTick(LoggingTool logger)
           
 
Method Summary
 void addTickable(ITick tickable)
           
 void clear()
          Stops the ticker and unregisters all registered items.
 long getBeginnigOfTime()
          Returns the cycle offset.
 long getCurrentCycle()
          Returns the current time
 long getCycleMillis()
          Returns the cyle length.
 void initialize()
          Initializes the object.
 boolean isManual()
           
 void removeTickable(ITick tickable)
           
 void setBeginningOfTime(long value)
          Sets the cycle offset.
 void setCurrentCycle(long cycle)
          Sets the current cycle.
 void setCycleMillis(long cycleMillis)
          Sets the cycle length.
 void setLogger(LoggingTool logger)
          Attaches the logger.
 void setManual(boolean value)
           
 void startThread()
           
 void stop()
           
 void tick()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

timer

protected ConcurrentTick.Ticker timer
The timer thread.


tickers

protected java.util.Hashtable<ITick,orca.shirako.kernel.ConcurrentTick.ItemTicker> tickers
All tickable items.


logger

protected LoggingTool logger
The logger.


stopped

protected boolean stopped
Are we active?


cycleMillis

protected long cycleMillis
Cycle length in milliseconds.


beginningOfTime

protected long beginningOfTime
Cycle offset in milliseconds.


cycle

protected long cycle
The current clock value. Read/write to the clock should be done through the clockLock.


clockLock

protected java.lang.Object clockLock
Lock controlling the access to cycle.


clockFactory

protected ActorClock clockFactory
The clock factory.


manual

protected boolean manual
Constructor Detail

ConcurrentTick

public ConcurrentTick(LoggingTool logger)
Method Detail

initialize

public void initialize()
                throws java.lang.Exception
Description copied from interface: IInitialize
Initializes the object.

Specified by:
initialize in interface IInitialize
Specified by:
initialize in interface ITicker
Throws:
java.lang.Exception

tick

public void tick()
Specified by:
tick in interface ITicker

startThread

public void startThread()
Specified by:
startThread in interface ITicker

addTickable

public void addTickable(ITick tickable)
Specified by:
addTickable in interface ITicker

removeTickable

public void removeTickable(ITick tickable)
Specified by:
removeTickable in interface ITicker

stop

public void stop()
          throws java.lang.Exception
Specified by:
stop in interface ITicker
Throws:
java.lang.Exception

clear

public void clear()
           throws java.lang.Exception
Description copied from interface: ITicker
Stops the ticker and unregisters all registered items.

Specified by:
clear in interface ITicker
Throws:
java.lang.Exception

getCurrentCycle

public long getCurrentCycle()
Description copied from interface: ITicker
Returns the current time

Specified by:
getCurrentCycle in interface ITicker
Returns:

setLogger

public void setLogger(LoggingTool logger)
Description copied from interface: ITicker
Attaches the logger.

Specified by:
setLogger in interface ITicker
Parameters:
logger - logger to use

setBeginningOfTime

public void setBeginningOfTime(long value)
Description copied from interface: ITicker
Sets the cycle offset.

Specified by:
setBeginningOfTime in interface ITicker
Parameters:
value - cycle offset in milliseconds

getBeginnigOfTime

public long getBeginnigOfTime()
Description copied from interface: ITicker
Returns the cycle offset.

Specified by:
getBeginnigOfTime in interface ITicker
Returns:
cycle offset in milliseconds

getCycleMillis

public long getCycleMillis()
Description copied from interface: ITicker
Returns the cyle length.

Specified by:
getCycleMillis in interface ITicker
Returns:
cycle length in milliseconds

setCycleMillis

public void setCycleMillis(long cycleMillis)
Description copied from interface: ITicker
Sets the cycle length.

Specified by:
setCycleMillis in interface ITicker
Parameters:
cycleMillis - cycle length in milliseconds

setCurrentCycle

public void setCurrentCycle(long cycle)
Description copied from interface: ITicker
Sets the current cycle. The first cycle to be generated by the ticket is cycle+1.

Specified by:
setCurrentCycle in interface ITicker
Parameters:
cycle - current cycle

isManual

public boolean isManual()
Specified by:
isManual in interface ITicker

setManual

public void setManual(boolean value)
Specified by:
setManual in interface ITicker


Copyright © 2007 Network/Internet Computing Lab. All Rights Reserved.