Class Clock

java.lang.Object
java.lang.Thread
org.cesilko.rachota.core.Clock
All Implemented Interfaces:
Runnable

public class Clock extends Thread
System clock ticking every second by default.
  • Field Details

    • tick

      private long tick
      Clock period i.e. time gap between two ticks.
    • listeners

      private Vector listeners
      Set of clock listeners that want to be notified at each tick.
    • ticking

      private boolean ticking
      True if clock is ticking.
    • clock

      private static Clock clock
      The only instance of clock object in the system.
  • Constructor Details

    • Clock

      private Clock(long tick)
      Clock constructor.
      Parameters:
      tick - Required clock tick in milliseconds.
  • Method Details

    • getDefault

      public static Clock getDefault()
      Returns default instance of Clock object. Tick period is initially set to 1000 ms.
      Returns:
      The only instance of clock in the system.
    • setTick

      public void setTick(long tick)
      Sets period of one clock tick.
      Parameters:
      tick - Clock period i.e. time between two notifications to listeners.
    • addListener

      public void addListener(ClockListener listener)
      Adds new clock listener.
      Parameters:
      listener - Object who whats to be notified after each tick.
    • removeListener

      public void removeListener(ClockListener listener)
      Removes already registered clock listener.
      Parameters:
      listener - Object who no longer whats to be notified after each tick.
    • run

      public void run()
      Main clock loop. Nothing happens for given tick period and then all listeners are notified about that fact.
      Specified by:
      run in interface Runnable
      Overrides:
      run in class Thread
    • suspendClock

      public void suspendClock()
      Temporarily stops clock.
    • resumeClock

      public void resumeClock()
      Starts clock again.
    • isTicking

      public boolean isTicking()
      Returns whether clock is ticking or not.
      Returns:
      True if clock is ticking or false otherwise.