/interpreter/tags/reactive-pattern-matching/src/edu/vub/at/signals/eval/EncapsulatingSignal.java
http://ambienttalk.googlecode.com/ · Java · 81 lines · 24 code · 10 blank · 47 comment · 1 complexity · c3e7cbbd1a3973a83b895c9f6f7ddb8f MD5 · raw file
- /**
- * AmbientTalk/2 Project
- * EncapsulatingReactiveComputation.java created on Jun 10, 2008 at 8:48:38 PM
- * (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.eval;
- import java.util.HashSet;
- import java.util.Iterator;
- import edu.vub.at.signals.SignalListener;
- /**
- * When creating a dependency network inside the body of a method, this network may depend implicitly
- * on other reactive computations, for instance if the method was called with another behavior as the
- * receiver or as an argument of that method. EncapsulatingSignal instances are managed in a dynamic
- * variable by the interpreter to keep track of these implicit dependencies.
- *
- * Hence, when the method is triggered due to changes in an argument or the receiver, the dependency
- * network that was constructed in the previous invocation is automatically dismantled.
- *
- * @author smostinc
- */
- public class EncapsulatingSignal {
- private HashSet nestedSignalListeners_ = new HashSet();
- private int dependencyHeight_;
-
- public EncapsulatingSignal(int dependencyHeight) {
- dependencyHeight_ = dependencyHeight;
- }
-
- /**
- * When dependent computations are created within the control flow of this encapsulating
- * signal, their minimal dependency height should be greater than the dependency height
- * of the encapsulating signal.
- */
- public int dependencyHeight() {
- return dependencyHeight_;
- }
-
- /**
- * When the encapsulating reactive computation needs to be performed anew, all dependent
- * computations that were constructed within its dynamic extent need need to be unhooked.
- */
- public synchronized void unhookAllDependencies() {
- for (Iterator nestedSignalIt = nestedSignalListeners_.iterator(); nestedSignalIt.hasNext();) {
- SignalListener currentSignalListener = (SignalListener) nestedSignalIt.next();
-
- currentSignalListener.unhook();
- nestedSignalIt.remove();
- }
- }
-
-
- public synchronized void registerDependency(SignalListener theNestedListener) {
- nestedSignalListeners_.add(theNestedListener);
- }
- }