Class RFuture
java.lang.Object
uk.co.terminological.rjava.threads.RFuture
A slightly idiosyncratic implementation of a Java Future API that can be called
from generated R code. This only executes a named method with supplied parameters
which are validated at runtime using reflection. The use of this is triggered
by an @RAsync annotation on a method. It is also used for @RBlocking annotated
methods so as to allow long running blocking functions to be interrupted through R.
This is intended really to be only accessible through generated R6 code and not
generally expected to be used directly.
- Version:
- $Id: $Id
- Author:
- vp22681
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidattachProgressBar(String name) booleancancel()cancel.booleancancel(boolean mayInterruptIfRunning) get()This will only throw an interrupted exception if it was cancelled already or in interrupted whilst waiting to join the thread.get(long timeout) get.longgetId()Gets the system messages from Java for thread in current method thread.booleanbooleanisDone()booleanisStale()booleanpoll(long ms) Polls for completion for use in while loop.toString()
-
Constructor Details
-
RFuture
public RFuture(Object o, String method, ArrayList<Object> parameters, String returnSig, String converter) throws NoSuchMethodException, SecurityException, ClassNotFoundException Constructor for RFuture.
- Parameters:
o- aObjector a String representing a fully qualified class namemethod- aStringobject to be run in a threadparameters- aArrayListobject the parameters of the method (not checked)returnSig- the return signature in JNI notationconverter- the R expression to convert the return value to a R value (as a string).- Throws:
NoSuchMethodException- if any.SecurityException- if any.ClassNotFoundException- if any.
-
-
Method Details
-
cancel
public boolean cancel()cancel.
- Returns:
- a boolean
-
cancel
public boolean cancel(boolean mayInterruptIfRunning) -
isCancelled
public boolean isCancelled()- Specified by:
isCancelledin interfaceFuture<Object>
-
isDone
public boolean isDone() -
isStale
public boolean isStale() -
getMethod
-
get
This will only throw an interrupted exception if it was cancelled already or in interrupted whilst waiting to join the thread.- Specified by:
getin interfaceFuture<Object>- Throws:
InterruptedExceptionExecutionException
-
get
get.
- Parameters:
timeout- a long representing number of milliseconds- Returns:
- a
Objectobject - Throws:
InterruptedException- if the function was cancelled already or is cancelled in the . next `timeout` milliseconds.ExecutionException- if any issues executing the function.TimeoutException- if the function has not completed.
-
get
public Object get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException - Specified by:
getin interfaceFuture<Object>- Throws:
InterruptedExceptionExecutionExceptionTimeoutException
-
poll
public boolean poll(long ms) Polls for completion for use in while loop.- Parameters:
ms- time in millisecods- Returns:
- a boolean, true if completed, false if still running. Completed means thread is finished processing. It can be result of cancellation, error or completion.
-
getSystemMessages
Gets the system messages from Java for thread in current method thread.- Returns:
- the system messages
-
attachProgressBar
-
getProgressRCode
-
toString
-
getId
public long getId() -
getReturnSig
-
getConverter
-