org.simantics.databoard.channel
Interface AsyncRequest


public interface AsyncRequest

Delayed response object. The result or error may be or become available to this object at any given time. This interface is intended to be used by clients that make service requests over command channel.

Author:
Toni Kalajainen

Nested Class Summary
static interface AsyncRequest.RequestListener
           
static class AsyncRequest.Status
          Get the current request status.
 
Method Summary
 java.lang.Exception getError()
          Get error if available.
 java.lang.Object getResult(Binding binding)
          Get result if available.
 AsyncRequest.Status getStatus()
           
 void setListener(AsyncRequest.RequestListener listener)
          Set a listener.
 java.lang.Object waitForResult(Binding binding)
          Synchronous wait for result until default timeout.
 java.lang.Object waitForResult(Binding binding, long timeout, java.util.concurrent.TimeUnit unit)
          Wait for result or break after until timeout.
 

Method Detail

getStatus

AsyncRequest.Status getStatus()

getResult

java.lang.Object getResult(Binding binding)
                           throws RequestException
Get result if available.

Parameters:
binding -
Returns:
result or null
Throws:
RequestException

getError

java.lang.Exception getError()
Get error if available. Cause is (typically) one of these: o Communication problems IOException o Timeout TimeoutException o Service(handler) problem ServiceException

Returns:
error or null

waitForResult

java.lang.Object waitForResult(Binding binding)
                               throws RequestException
Synchronous wait for result until default timeout. Default timeout is configured to the channel. If timeout occurs TimeoutException is thrown wrapped in RequestException.

Parameters:
binding - the format for the result
Returns:
the result object
Throws:
RequestException

waitForResult

java.lang.Object waitForResult(Binding binding,
                               long timeout,
                               java.util.concurrent.TimeUnit unit)
                               throws RequestException
Wait for result or break after until timeout. If timeout occurs TimeoutException is thrown wrapped in RequestException.

Parameters:
binding -
timeout -
unit -
Returns:
result
Throws:
RequestException

setListener

void setListener(AsyncRequest.RequestListener listener)
Set a listener. If the result is already available, the event schedueled immediately.

Parameters:
listener - (listener may not block) or null to remove listener