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.extend;
17:
18: import java.io.Serializable;
19:
20: /**
21: * A Sleeper allows the request to halt and cease execution for some time,
22: * while still allowing output.
23: * <p>There are 3 envisaged implementations</p>
24: * <ul>
25: * <li>Old servlet stacks where the only option is to call
26: * {@link Object#wait(long)} and {@link Object#notify()} to resume.</li>
27: * <li>Jetty, where an Ajax Continuation causes an exception</li>
28: * <li>Newer async servlets where the implementation will probably continue
29: * with the servlet engine able to detect that it should not complete the
30: * request.</li>
31: * </ul>
32: * <p>All implementations of Sleeper must be {@link Serializable} so we can
33: * store Sleepers in the session and therefore have other connections wake them
34: * up.
35: * @author Joe Walker [joe at getahead dot ltd dot uk]
36: */
37: public interface Sleeper extends Serializable {
38: /**
39: * 'halt' the current execution in some way.
40: * This method should be the last meaningful thing that is done on a
41: * request, and work that needs to be done before completion should be
42: * done in a {@link Runnable} so the system can schedule it at an
43: * appropriate time.
44: * @param onAwakening The action to take when {@link #wakeUp()} is called
45: */
46: void goToSleep(Runnable onAwakening);
47:
48: /**
49: * This method should attempt to resume the execution.
50: * It is possible that this method will be called more than once at the
51: * same time so Sleepers should be prepared take steps to be woken only
52: * once.
53: */
54: void wakeUp();
55: }
|