Package jfun.yan.xml.nuts

Source Code of jfun.yan.xml.nuts.SynchronizedNut

package jfun.yan.xml.nuts;

import jfun.yan.Binder;
import jfun.yan.Creator;

/**
* Decorate a Binder by putting operations on the bound variable
* in a synchronized block. The pseudo code is:
* <pre>
*   bind(Object v){
*     synchronized(v){
*       do operation on v.
*     }
*   }
* </pre>
* <p>
* @author Ben Yu
* Nov 12, 2005 7:09:29 PM
*/
public class SynchronizedNut extends DelegatingBinderNut {

  public Binder eval() throws Exception {
    final Binder binder = getMandatory();
    return new Binder(){
      public Creator bind(Object v)
      throws Throwable{
       synchronized(v){
         return binder.bind(v);
       }
      }
      public String toString(){
        return binder.toString();
      }
    };
  }

}
TOP

Related Classes of jfun.yan.xml.nuts.SynchronizedNut

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.