com.threerings.util
Class ChangeBlock

java.lang.Object
  extended by com.threerings.util.ChangeBlock

public class ChangeBlock
extends Object

A simple mechanism for preventing infinite recursion when one change listener responds to an event by making another change, which in turns notifies another (or the same) listener, which makes another change, and so on. The following example demonstrates the pattern:

 public void stateChanged (ChangeEvent event)
 {
     if (!_block.enter()) {
         return;
     }
     try {
         // do something that may cause another state change
     } finally {
         _block.leave();
     }
 }
 


Field Summary
protected  boolean _changing
          If true, the current thread is in the change block.
 
Constructor Summary
ChangeBlock()
           
 
Method Summary
 boolean enter()
          Attempts to enter the change block.
 void leave()
          Leaves the change block.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_changing

protected boolean _changing
If true, the current thread is in the change block.

Constructor Detail

ChangeBlock

public ChangeBlock()
Method Detail

enter

public boolean enter()
Attempts to enter the change block.

Returns:
true if the change block was successfully entered, false if already in the change block.

leave

public void leave()
Leaves the change block.