next up previous contents
Next: The BaleWeavable Interface and Up: The NeedleWeavable Interface and Previous: The NeedleWeavable Interface and

The Promise Class

The data of the Needle is also loaded into memory at the same time as the Needle object, we do not want (for example) a 10Mb+ Postscript file loaded into memory. Instead we create a Promise class. The Promise class holds one function, fulfill() which returns a Reader (a Java stream type). It is the programmers job to implement the details of the fulfill() class for their particular ``promise.''

As an example, consider the case of some user creating a needle.Body that is supposed to hold a large Postscript file. The file resides on disk somewhere. Instead of setting the data field within the needle.Body to the bits of the Postscript file, we can set it to a special Promise class that holds the name of the file location. When getData() is invoked on the needle, the Promise is returned, and when fulfill() is invoked on the Promise the bits of the Postscript file are dynamically loaded from disk.

Some Promises are designed to do ``actual'' work. For example, a Promise held within a needle.Text may actually extract the text from some other location on-the-fly. Re-running the Promise is highly inefficient, so in Haystack we provide the means for caching promises (see Section gif).



Copyright 1998, Eytan Adar (eytan@alum.mit.edu)