View Javadoc

1   package org.xvsm.lookup.freepastry;
2   
3   import java.net.URI;
4   
5   import org.xvsm.core.ContainerRef;
6   import org.xvsm.lookup.exceptions.LookupException;
7   import org.xvsm.remote.freepastry.FreePastryConnection;
8   
9   import rice.Continuation;
10  import rice.p2p.commonapi.NodeHandle;
11  import rice.p2p.commonapi.NodeHandleSet;
12  
13  /***
14   * This class is the class, which receiveResult is called when a lookup
15   * operation is performed successfully
16   * 
17   * @author Hannu-Daniel Goiss
18   */
19  public class LookupContinuation implements Continuation {
20  	private boolean finished = false;
21  	private Exception exception = null;
22  	private ContainerRef cref = null;
23  
24  	/* (non-Javadoc)
25  	 * @see rice.Continuation#receiveResult(java.lang.Object)
26  	 */
27  	public void receiveResult(Object result) {
28  
29  		if (result == null)
30  			exception = new LookupException("result couldn't be found");
31  		else {
32  			try {
33  				cref = new ContainerRef(new URI(((FPPastContent) result)
34  						.getContent()));
35  			} catch (Exception e) {
36  				e.printStackTrace();
37  			}
38  		}
39  
40  		finished = true;
41  	}
42  
43  	/* (non-Javadoc)
44  	 * @see rice.Continuation#receiveException(java.lang.Exception)
45  	 */
46  	public void receiveException(Exception result) {
47  		exception = result;
48  		finished = true;
49  	}
50  
51  	/***
52  	 * @return the finished
53  	 */
54  	public boolean isFinished() {
55  		return finished;
56  	}
57  
58  	/***
59  	 * @return the exception
60  	 */
61  	public Exception getException() {
62  		return exception;
63  	}
64  
65  	/***
66  	 * @return the cref
67  	 */
68  	public ContainerRef getCref() {
69  		return cref;
70  	}
71  }