org.opcfoundation.ua.transport.impl
Class AsyncResultImpl<T>

java.lang.Object
  extended by org.opcfoundation.ua.transport.impl.AsyncResultImpl<T>
All Implemented Interfaces:
AsyncResult<T>

public class AsyncResultImpl<T>
extends Object
implements AsyncResult<T>

AsyncResultImpl class.


Nested Class Summary
 
Nested classes/interfaces inherited from interface org.opcfoundation.ua.transport.AsyncResult
AsyncResult.AsyncResultStatus
 
Constructor Summary
AsyncResultImpl()
          Constructor for AsyncResultImpl.
 
Method Summary
 ServiceResultException getError()
          getError.
 T getResult()
          Get result if available
 AsyncResult.AsyncResultStatus getStatus()
          Get request status
 void setError(ServiceResultException error)
          Set error, invokes any listener in executor thread.
 void setErrorSync(ServiceResultException error)
          Set error, invokes any listener here and now.
 void setListener(ResultListener<T> listener)
          Set a listener.
 void setResult(T result)
          Set error, invokes any listener in excutor thread If result or error has already been set, this method does nothing.
 void setResultSync(T result)
          setResultSync.
 void setSource(AsyncResult<T> source)
          Links another result as a source of this result object
 T waitForResult()
          Wait for result until result is available.
 T waitForResult(long timeout, TimeUnit unit)
          Wait for result or time out.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AsyncResultImpl

public AsyncResultImpl()

Constructor for AsyncResultImpl.

Method Detail

getError

public ServiceResultException getError()

getError.

Specified by:
getError in interface AsyncResult<T>
Returns:
a ServiceResultException object.

getResult

public T getResult()
Get result if available

Specified by:
getResult in interface AsyncResult<T>
Returns:
result or null if not complete

getStatus

public AsyncResult.AsyncResultStatus getStatus()
Get request status

Specified by:
getStatus in interface AsyncResult<T>
Returns:
status

setError

public void setError(ServiceResultException error)
Set error, invokes any listener in executor thread. If result or error has already been set, this method does nothing.

Parameters:
error - a ServiceResultException object.

setErrorSync

public void setErrorSync(ServiceResultException error)
                  throws RuntimeException
Set error, invokes any listener here and now. Note the listener may throw unexpected RuntimeException

Parameters:
error - a ServiceResultException object.
Throws:
RuntimeException - if any.

setListener

public void setListener(ResultListener<T> 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.

Specified by:
setListener in interface AsyncResult<T>
Parameters:
listener - (listener may not block) or null to remove listener

setResult

public void setResult(T result)
Set error, invokes any listener in excutor thread If result or error has already been set, this method does nothing.

Parameters:
result - a T object.

setResultSync

public void setResultSync(T result)
                   throws RuntimeException

setResultSync.

Parameters:
result - a T object.
Throws:
RuntimeException - if any.

setSource

public void setSource(AsyncResult<T> source)
Links another result as a source of this result object

Parameters:
source - a AsyncResult object.

waitForResult

public T waitForResult()
                throws ServiceResultException
Wait for result until result is available. Typically result becomes available in a default operation time out period. (120s)

Specified by:
waitForResult in interface AsyncResult<T>
Returns:
the result
Throws:
ServiceResultException - network error, e.g. IOException of MethodNotSupportedException

waitForResult

public T waitForResult(long timeout,
                       TimeUnit unit)
                throws ServiceResultException
Wait for result or time out. On timeout ServiceResultException(Bad_Timeout) is thrown.

Specified by:
waitForResult in interface AsyncResult<T>
Parameters:
timeout - time out value
unit - time unit
Returns:
the result
Throws:
ServiceResultException - error during invocation


Copyright © 2018. All rights reserved.