KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > prevayler > implementation > clock > PausableClock


1 //Prevayler(TM) - The Free-Software Prevalence Layer.
2
//Copyright (C) 2001-2003 Klaus Wuestefeld
3
//This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
4

5 package org.prevayler.implementation.clock;
6
7 import java.util.Date JavaDoc;
8
9 import org.prevayler.Clock;
10
11 public class PausableClock implements Clock {
12
13     private final Clock _realClock;
14     private final BrokenClock _brokenClock = new BrokenClock();
15     private Clock _activeClock;
16
17
18     public PausableClock(Clock realClock) {
19         _realClock = realClock;
20         resume();
21     }
22
23     public Date JavaDoc time() { return _activeClock.time(); }
24
25     public void pause() {
26         advanceTo(_realClock.time());
27         _activeClock = _brokenClock;
28     }
29
30     public void advanceTo(Date JavaDoc time) {
31         _brokenClock.advanceTo(time);
32     }
33
34     public void resume() { _activeClock = _realClock; }
35
36     public Date JavaDoc realTime() { return _realClock.time(); }
37 }
38
Popular Tags