com.samskivert.util
Interface ResultListener<T>

All Known Implementing Classes:
AWTResultListener, ChainedResultListener, ComplainingListener, FailureListener, ResultHandler, ResultListener.NOOP, ResultListenerList, ServiceWaiter, ServiceWaiter

public interface ResultListener<T>

Provides access to a future result, or the exception associated with failure. In the trying course of implementing a method, one is often left with no choice but to foist control off onto another thread or generally postpone things beyond the lifetime of the current call. In such circumstances, it is handy to have a general purpose mechanism for leting the caller know when things are done and whether or not the succeeded; this class serves that purpose.

The following contrived example will hopefully communicate its use more clearly than the previous paragraph of flowery prose:

 public void doSomeStuff (ResultListener listener)
 {
     Runnable run = new Runnable () {
         public void run () {
             try {
                 // do our thing
                 listener.requestCompleted("Elvis!");
             } catch (Exception e) {
                 listener.requestFailed(e);
             }
         }
     };
     new Thread(run).start();
 }
 

See Also:
IntResultListener

Nested Class Summary
static class ResultListener.NOOP<T>
          A result listener that does nothing for cases where that is an appropriate behavior.
 
Field Summary
static ResultListener<Object> NOOP
          Deprecated. This cannot be type safe so don't use it.
 
Method Summary
 void requestCompleted(T result)
          Called to communicate that the request succeeded and that the result is available.
 void requestFailed(Exception cause)
          Called to communicate that the request failed and to provide the reason for failure.
 

Field Detail

NOOP

@Deprecated
static final ResultListener<Object> NOOP
Deprecated. This cannot be type safe so don't use it.
Method Detail

requestCompleted

void requestCompleted(T result)
Called to communicate that the request succeeded and that the result is available.


requestFailed

void requestFailed(Exception cause)
Called to communicate that the request failed and to provide the reason for failure.



Copyright © 2000-2008 Michael Bayne. All Rights Reserved.