01: /*
02: * Copyright 2005 Joe Walker
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: package org.directwebremoting.impl;
17:
18: import org.directwebremoting.extend.Alarm;
19: import org.directwebremoting.extend.Sleeper;
20:
21: /**
22: * An Alarm that goes off 'manually', that is to say by the calling of
23: * {@link #raiseAlarm()}.
24: * @author Joe Walker [joe at getahead dot ltd dot uk]
25: */
26: public class BasicAlarm implements Alarm {
27: /**
28: * It's all gone wrong - inform the Sleeper
29: */
30: public void raiseAlarm() {
31: synchronized (sleeperLock) {
32: if (sleeper != null) {
33: sleeper.wakeUp();
34: }
35: }
36: }
37:
38: /* (non-Javadoc)
39: * @see org.directwebremoting.dwrp.Alarm#cancel()
40: */
41: public void cancel() {
42: synchronized (sleeperLock) {
43: sleeper = null;
44: }
45: }
46:
47: /* (non-Javadoc)
48: * @see org.directwebremoting.dwrp.Alarm#setAlarmAction(org.directwebremoting.dwrp.Sleeper)
49: */
50: public void setAlarmAction(Sleeper sleeper) {
51: // I think the life-cycle dictates that we don't need to synchronize here
52: // however it's probably simpler to synchronize and be sure
53: synchronized (sleeperLock) {
54: this .sleeper = sleeper;
55: }
56: }
57:
58: /**
59: * The protection for the sleeper
60: */
61: private Object sleeperLock = new Object();
62:
63: /**
64: * The thread that needs to know about shutdown
65: * @protectedBy(sleeperLock)
66: */
67: private Sleeper sleeper;
68: }
|