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

net.hycube.search.SearchWaitCallback Maven / Gradle / Ivy

Go to download

HyCube is a distributed hash table based on a hierarchical hypercube geometry, employing a novel variable metric adopting the Steinhaus transform.

There is a newer version: 1.0.5
Show newest version
package net.hycube.search;

import net.hycube.core.NodePointer;

public class SearchWaitCallback implements SearchCallback {

	protected int searchId;
	protected NodePointer[] result;
	
	protected boolean returned;
	
	public SearchWaitCallback() {
		returned = false;
		result = null;
	}
	
	
		
	@Override
	public synchronized void searchReturned(int searchId, Object callbackArg, NodePointer[] result) {
		this.searchId = searchId;
		this.result = result;
		returned = true;
		notify();
		
	}

	
	public synchronized boolean hasReturned() {
		return returned;
	}

	
	public synchronized NodePointer[] waitForResult() throws InterruptedException {
		return waitForResult(0);
	}
	
	public synchronized NodePointer[] waitForResult(long timeout) throws InterruptedException {
		
		if (returned) return result;
		
		try {
			wait(timeout);
		} catch (InterruptedException e) {
			throw e;
		}
		
		return result;
		
	}
	
	
}





© 2015 - 2025 Weber Informatics LLC | Privacy Policy