All Downloads are FREE. Search and download functionalities are using the official Maven repository.

ca.odell.glazedlists.impl.pmap.BlockingValueCallback Maven / Gradle / Ivy

There is a newer version: 1.9.1
Show newest version
/* Glazed Lists                                                 (c) 2003-2006 */
/* http://publicobject.com/glazedlists/                      publicobject.com,*/
/*                                                     O'Dell Engineering Ltd.*/
package ca.odell.glazedlists.impl.pmap;

// NIO is used for CTP
import ca.odell.glazedlists.impl.nio.*;
import ca.odell.glazedlists.impl.io.*;
import java.util.*;
import java.nio.*;
import java.nio.channels.*;
import java.io.*;
// logging
import java.util.logging.*;

/**
 * A ValueCallback that simply blocks until the value is ready.
 *
 * @author Jesse Wilson
 */
class BlockingValueCallback implements ValueCallback {
    
    /** the value returned */
    private Bufferlo value = null;
    
    /**
     * Gets the value for the specified Chunk.
     */
    public static Bufferlo get(Chunk member) {
        // queue the get
        BlockingValueCallback callback = new BlockingValueCallback();
        member.fetchValue(callback);
        
        // wait till its ready
        synchronized(callback) {
            if(callback.value == null) {
                try {
                    callback.wait();
                } catch(InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        }
        
        // return the result
        return callback.value;
    }
    
    /**
     * Handles a value being completely loaded into memory and ready to read.
     */
    public void valueLoaded(Chunk member, Bufferlo value) {
         synchronized(this) {
             this.value = value;
             notify();
         }
    }
}





© 2015 - 2024 Weber Informatics LLC | Privacy Policy