01: // Copyright 2006 The Apache Software Foundation
02: //
03: // Licensed under the Apache License, Version 2.0 (the "License");
04: // you may not use this file except in compliance with the License.
05: // You may obtain a copy of the License at
06: //
07: // http://www.apache.org/licenses/LICENSE-2.0
08: //
09: // Unless required by applicable law or agreed to in writing, software
10: // distributed under the License is distributed on an "AS IS" BASIS,
11: // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12: // See the License for the specific language governing permissions and
13: // limitations under the License.
14:
15: package org.apache.tapestry.services;
16:
17: /**
18: * Allow for deferred execution of logic, useful when trying to get multiple components to
19: * coordinate behavior. A component may add a command to be executed "{@link #end() at the end of the heartbeat}".
20: * The classic example of this is a Label and the field it labels; since we don't know which order
21: * the two will render, we can't tell if the field's id is correct until after both have rendered.
22: */
23: public interface Heartbeat {
24: /**
25: * Begins a new Heartbeat. Heartbeats nest. Every call to begin() should be matched by a call to
26: * {@link #end()}.
27: */
28: void begin();
29:
30: /** Executes all commands since the most recent {@link #begin()}. */
31: void end();
32:
33: /**
34: * Adds a new command to the current Heartbeat. The command will be executed by {@link #end()}.
35: *
36: * @param command
37: * command to be executed at the end of the heartbeat
38: */
39: void defer(Runnable command);
40: }
|