org.simantics.databoard.channel
Interface AsyncRequest


public interface AsyncRequest

Author:
Toni Kalajainen

Nested Class Summary
static interface AsyncRequest.RequestListener
           
static class AsyncRequest.Status
           
 
Method Summary
 java.lang.Exception getError()
          Get error if available.
 java.lang.Object getResult(Binding binding)
          Get result if available.
 AsyncRequest.Status getStatus()
          Get request status
 void setListener(AsyncRequest.RequestListener listener)
          Set a listener.
 java.lang.Object waitForResult(Binding binding)
          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()
Get request status

Returns:
status

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
Wait for result until default timeout. Default timeout is configured to the channel. If timeout occurs TimeoutException is thrown wrapped in RequestException.

Parameters:
binding -
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 listener is invoked from the current thread. Otherwise, the notification is placed from the thread that sets the result. The listener implementation may not create any locks during the handling of the result, also it is good policy not do any long term operations in the listener implementation.

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