/** * The given object wants to be notified of this event * * @param observer */ public static synchronized void subscribe(Observer observer) { if (houseKeeper == null) { houseKeeper = new CacheHouseKeeper(); } houseKeeper.addObserver(observer); houseKeeper.checkTimerThread(); }
/** * The given object no longer wants to be notified of this event * * <p>The timer will shutdown if it is no longer being observed * * @param observer */ public static synchronized void unSubscribe(Observer observer) { if (houseKeeper != null) { houseKeeper.deleteObserver(observer); if (houseKeeper.countObservers() == 0) { stop(); } } }
/** Stop timer thread */ public static synchronized void stop() { if (houseKeeper != null && houseKeeper.houseKeeperThread.running) { houseKeeper.houseKeeperThread.running = false; houseKeeper.deleteObservers(); houseKeeper.houseKeeperThread.interrupt(); try { houseKeeper.houseKeeperThread.join(); } catch (InterruptedException e) { } houseKeeper.houseKeeperThread = null; houseKeeper = null; } }
/** Trigger for the housekeeping event (can be called directly as a manual trigger) */ public static synchronized void triggerEvent() { if (houseKeeper != null) { houseKeeper.setChanged(); houseKeeper.notifyObservers(TICK); } }