View Javadoc
1 package com.bonevich.util.dependency; 2 3 import java.util.List; 4 import java.util.LinkedList; 5 6 public abstract class Sentry 7 { 8 protected static DependentProxy _activeDependent; 9 private List _dependents = new LinkedList(); 10 private SentryProxy _this = new SentryProxy() 11 { 12 public void removeDependent(DependentProxy dependent) 13 { 14 Sentry.this.removeDependent(dependent); 15 } 16 }; 17 18 public void cleanup() 19 { 20 invalidateDependents(); 21 } 22 23 protected final void recordDependent() 24 { 25 // Verify that a link does not already exist 26 if (_activeDependent != null && 27 !_dependents.contains(_activeDependent)) 28 { 29 // Establish a two-way link 30 _activeDependent.addSentry(_this); 31 _dependents.add(_activeDependent); 32 //System.err.println("Recorded dependency: " + this + "<==>" + _activeDependent); 33 //com.bonevich.util.StackDump.print(this); 34 } 35 } 36 37 protected final void invalidateDependents() 38 { 39 // Calling invalidate on a dependent will eventually call 40 // removeDependent, thereby removing it from the list 41 while (!_dependents.isEmpty()) 42 { 43 ((DependentProxy)_dependents.get(0)).invalidate(); 44 } 45 } 46 47 private void removeDependent(DependentProxy dependent) 48 { 49 _dependents.remove(dependent); 50 } 51 52 } /*** end class Sentry */

This page was automatically generated by Maven