package org.msgpack.rpc.client;

import java.io.IOException;

public class Future {
	protected Object error;
	protected Object result;
    protected boolean isJoined;
	
    public Future() {
        this.error = null;
        this.result = null;
        this.isJoined = false;
    }

    public synchronized void join() {
    	try {
    		while (error == null && result == null)
    			this.wait();
    	} catch (Exception e) {
    		e.printStackTrace();
    		error = e;
    	}
    	isJoined = true;
    }
    
    public void setResult(Object result) {
    	set(null, result);
    }

    public void setError(Object error) {
    	if (error instanceof String)
    		error = new IOException((String)error);
    	set(error, null);
    }

    protected synchronized void set(Object error, Object result) {
    	this.error = error;
        this.result = result;
        this.notifyAll();
    }

    public synchronized Object getResult() throws Exception {
    	if (!isJoined)
    		throw new IOException("Calling getResult() without join()");
        return result;
    }
    
    public synchronized Object getError() throws Exception {
       	if (!isJoined)
    		throw new IOException("Calling getResult() without join()");
    	return error;
    }
}

@@ -88,22 +88,25 @@
 otected 
-Object
+Exception
  error;%0A
@@ -619,24 +619,42 @@
 ct error) %7B%0A
+    %09Exception e;%0A
     %09if (err
@@ -682,20 +682,16 @@
 %0A    %09%09e
-rror
  = new I
@@ -726,17 +726,137 @@
    %09
+else if (error instanceof Exception)%0A    %09%09e = (Exception)error;%0A    %09else%0A    %09%09e = new IOException(%22Unknown Error%22);%0A    %09
 set(e
-rror
 , nu
@@ -903,22 +903,25 @@
 oid set(
-Object
+Exception
  error, 
@@ -1182,206 +1182,68 @@
     
-    return result;%0A    %7D%0A    %0A    public synchronized Object getError() throws Exception %7B%0A       %09if (!isJoined)%0A    %09%09throw new IOException(%22Calling getResult() without join()%22);%0A
+%09if (error != null)%0A    %09%09throw error;%0A   
     
-%09
+ 
 return 
-error
+result
 ;%0A  

change Future interface. throws Exception when calling getResult().