/interpreter/tags/reactive-pattern-matching/src/edu/vub/at/signals/SignalListener.java
http://ambienttalk.googlecode.com/ · Java · 127 lines · 10 code · 8 blank · 109 comment · 0 complexity · 6a3239921c3940e0dc0644807625eb4c MD5 · raw file
- /**
- * AmbientTalk/2 Project
- * SignalListener.java created on Jun 29, 2008 at 11:39:06 AM
- * (c) Programming Technology Lab, 2006 - 2007
- * Authors: Tom Van Cutsem & Stijn Mostinckx
- *
- * Permission is hereby granted, free of charge, to any person
- * obtaining a copy of this software and associated documentation
- * files (the "Software"), to deal in the Software without
- * restriction, including without limitation the rights to use,
- * copy, modify, merge, publish, distribute, sublicense, and/or
- * sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following
- * conditions:
- *
- * The above copyright notice and this permission notice shall be
- * included in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
- * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
- * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
- * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- * OTHER DEALINGS IN THE SOFTWARE.
- */
- package edu.vub.at.signals;
- import java.util.EventListener;
- import edu.vub.at.objects.ATMessage;
- /**
- * SignalListener is an interface specifying which messages can be sent to any dependent
- * reactive computation. This interface provides methods to get the dependency height of
- * a dependent computation and update it if necessary.
- *
- * It also provides methods to unhook signal listeners, such that obsolete branches can
- * be removed from the dataflow graph.
- *
- * @author smostinc
- *
- */
- public interface SignalListener extends EventListener {
- /**
- * This method is called when one of the parent signal has been updated. The update
- * is not performed immediately when this method is invoked. There are two important
- * reasons for delaying the update: First of all, the parent signal may not belong
- * to the same event loop as its child. This is typically the case when modelling an
- * external event source such as time, key strokes, etc. In this case, the external
- * process should not be able to perform computation inside another event loop.
- * <p>
- * Even if parent and child signal belong to the same event loop, performing updates
- * of the child signal immediately after having updated the parent is not acceptable
- * since this may introduce update glitches. Consider the following example:
- * <pre><code>
- * (seconds < (seconds + 1))
- * </code></pre>
- * In the above example, both the comparison <code><</code> and the addition have
- * a direct dependency on the seconds signal. If dependent signals were immediately
- * updated, the comparison could be updated first, yielding <code>false</code>.
- * <p>
- * To avoid update glitches updates are not performed immediately, but are scheduled
- * to be performed when the dataflow engine reached the proper dependency height. As
- * such, update glitches can be avoided, since the dependency height of <code><
- * </code> in the example is 2 since it depends on <code>seconds</code> (height: 0)
- * and <code>seconds + 1</code> (height: 1).
- *
- * @param theParent the parent signal that has been updated
- * @param theUpdate the update that was propagated by that parent
- */
- public void scheduleUpdate(ATSignal theParent, ATMessage theUpdate);
- /**
- *
- * @param theParent
- * @param theUpdate
- * @return whether the listener wants to receive subsequent updates
- */
- public boolean performUpdate(ATSignal theParent, ATMessage theUpdate);
-
- /**
- * Every signal is assigned a dependency height, which determines the stratus where
- * the signal is situated in the dataflow graph. Updates are propagated first to the
- * signals with the lowest dependency height to ensure that signals are only updated
- * when the signals they depend on are guaranteed not to contain stale information.
- *
- * @return The dependency height of this signal listener.
- */
- public int dependencyHeight();
-
- /**
- * When the value of a behavior is set to another behavior, this behavior may have a
- * higher dependency height. Updates from the newly assigned value should henceforth
- * be propagated to all dependent computations. However, before these update can be
- * propagated the dependency graph should be stratified anew. There are essentially
- * two solutions: we can keep the strata static and establish a "delayed" dependency
- * between both behaviors, which implies that updates are only propagated during the
- * next turn. The alternative is to reassign the dependency heights of all dependent
- * signals, such that they are strictly greater than those of the new parent signal.
- * <p>
- * The latter approach is adopted in <b>FrTime</b>, as well as in AmbientTalk. This
- * method is used to update the dependency height of a signal listener. It verifies
- * whether the new height is strictly greater than its current dependency height and
- * transitively updates dependent signals if necessary.
- */
- public void updateDependencyHeight(int newDependencyHeight);
-
- /**
- * When constructing parts of the dataflow network inside a method which was invoked
- * with a signal as receiver or parameter, the constructed dataflow will implicitly
- * depend on the signals that were passed to the method as well. When these signals
- * change, the method will be executed anew, and the dataflow network that was built
- * during the previous invocation is no longer valid.
- * <p>
- * This observation is a generalization of the technique in <b>FrTime</b>, where the
- * problem only surfaces when using signals in conditions or in function position.
- * <p>
- * The unhook method is used to deconstruct the dataflow graph, whenever a signal on
- * which the signal listener depended implicitly is changed. The signal listener has
- * to ensure that updates will no longer be propagated to rule out already scheduled
- * update attempts.
- */
- public void unhook();
- }