public void fire( DependentSubjectListener subject, Integer event, DependentSubjectListener listener) { // update the listener boolean incremented = listener.latestRevision < event.intValue(); listener.latestRevision = event.intValue(); // make sure the listener's dependencies were notified first listener.assertDependenciesSatisfiedRecursively(listener); // send the event forward if (incremented) { listener.increment(0); } }
/** * Dependencies are satisfied if the latestRevision is at least the latestRevision of all * upstream {@link DependentSubjectListener}s. */ public void assertDependenciesSatisfiedRecursively(DependentSubjectListener notified) { final Iterator<DependentSubjectListener> iter = upstreamSubjects.iterator(); while (iter.hasNext()) { final DependentSubjectListener upstream = iter.next(); upstream.assertDependenciesSatisfiedRecursively(notified); if (latestRevision < upstream.latestRevision) throw new IllegalStateException( "Dependencies not satisfied for " + notified + ", dependency " + this + " not updated by " + upstream + "!"); } }