Thunk.java :  » Web-Framework » anvil » anvil » script » Java Open Source

Java Open Source » Web Framework » anvil 
anvil » anvil » script » Thunk.java
/*
 * $Id: Thunk.java,v 1.3 2002/09/16 08:05:03 jkl Exp $
 *
 * Copyright (c) 2002 Njet Communications Ltd. All Rights Reserved.
 *
 * Use is subject to license terms, as defined in
 * Anvil Sofware License, Version 1.1. See LICENSE 
 * file, or http://njet.org/license-1.1.txt
 */
package anvil.script;
import java.io.IOException;
import anvil.core.Any;
import anvil.core.AnyRef;
import anvil.core.Serializer;

public class Thunk extends AnyRef
{

  protected StackFrame _escape;
  protected Function _function;
  protected Any _self = null;
  protected Any _result = null;
  

  public Thunk(StackFrame escape, Function function)
  {
    _escape = escape; 
    _function = function;
  }  
  
  
  public Thunk(StackFrame escape, Function function, Any self)
  {
    _escape = escape; 
    _function = function;
    _self = self;
  }
  
  
  public void setRef(Any value)
  {
  }
  
  
  public Any getRef()
  {
    Any result = _result;
    if (result == null) { 
      synchronized(this) {
        if ((result = _result) != null) {
          return result;
        }
        Context context = Context.getInstance();
        context.setEscape(_escape);
        return (_result = _function.execute(context, _self, Any.ARRAY0));
      }
    }
    return result;
  }


  public void serialize(Serializer serializer) throws IOException 
  {
    throw new IOException("Cannot serialize thunks");
  }

  
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.