public class JiffleExecutor extends Object
The client can optionally follow progress during execution with a
JiffleProgressListener
. When the task is
finished its status and results can be retrieved via JiffleEventListener
.
Example of use:
// assuming the executor is a class field in this example
executor = new JiffleExecutor();
executor.addEventListener(new JiffleEventListener() {
public void onCompletionEvent(JiffleEvent ev) {
myCompletionMethod(ev);
}
public void onFailureEvent(JiffleEvent ev) {
myFailureMethod(ev);
}
});
Now we can build Jiffle objects and submit them to the executor as shown here:
String script = "dest = src > 10 ? src : null;" ;
Map<String, Jiffle.ImageRole> imageParams = CollectionFactory.map();
imageParams.put("src", Jiffle.ImageRole.SOURCE);
imageParams.put("dest", Jiffle.ImageRole.DEST);
Jiffle jiffle = new Jiffle(script, imageParams);
// Map with the source and destination images
RenderedImage sourceImg = ...
WritableRenderedImage destImg = ...
Map<String, RenderedImage> images = CollectionFactory.map();
images.put("src", sourceImg);
images.put("dest", destImg);
// Submit the task to the executor
executor.submit(jiffle, images, new MyProgressListener());
When the script has completed the event listener will be notified and
the results can be retrieved:
private void myCompletionMethod(JiffleEvent ev) {
// Get and display the result image
JiffleExecutorResult result = ev.getResult();
RenderedImage img = result.getImages().get("dest");
...
}
private void myFailureMethod(JiffleEvent ev) {
System.out.println("Bummer...");
}
Once the application has finished with th executor it should call one of
the shutdown methods which terminate the task and polling threads.Modifier and Type | Field and Description |
---|---|
static long |
DEFAULT_POLLING_INTERVAL
The default interval for polling tasks to check for
completion (20 mS)
|
Constructor and Description |
---|
JiffleExecutor()
Creates an executor with default settings.
|
JiffleExecutor(int maxTasks)
Creates an executor that can have, at most,
maxTasks
running concurrently, with further tasks being placed in a queue. |
Modifier and Type | Method and Description |
---|---|
void |
addEventListener(JiffleEventListener listener)
Adds an event listener.
|
long |
getPollingInterval()
Gets the interval in milliseconds for polling task completion.
|
boolean |
isListening(JiffleEventListener listener)
Checks if a particular listener is registered with this executor.
|
boolean |
removeEventListener(JiffleEventListener listener)
Removes an event listener.
|
void |
setPollingInterval(long millis)
Sets the polling interval for task completion.
|
void |
shutdown()
Requests that the executor shutdown after completing any tasks
already submitted.
|
boolean |
shutdownAndWait(long timeOut,
TimeUnit unit)
Requests that the executor shutdown after completing any tasks
already submitted.
|
void |
shutdownNow()
Attempts to shutdown the executor immediately.
|
int |
submit(JiffleDirectRuntime runtime,
JiffleProgressListener progressListener)
Submits an
JiffleDirectRuntime object for execution. |
public static final long DEFAULT_POLLING_INTERVAL
public JiffleExecutor()
public JiffleExecutor(int maxTasks)
maxTasks
running concurrently, with further tasks being placed in a queue.maxTasks
- the maximum number of concurrent taskspublic void setPollingInterval(long millis)
millis
- interval between task polling in milliseconds; values
less than 1 are ignoredDEFAULT_POLLING_INTERVAL
public long getPollingInterval()
public void addEventListener(JiffleEventListener listener)
listener
- the listenerJiffleEvent
public boolean removeEventListener(JiffleEventListener listener)
listener
- the listenertrue
if the listener was removed;
false
if it was not registered with this executorpublic boolean isListening(JiffleEventListener listener)
listener
- the listenertrue
if the listener has already been added;
false
otherwisepublic int submit(JiffleDirectRuntime runtime, JiffleProgressListener progressListener)
JiffleDirectRuntime
object for execution. Depending
on existing tasks and the number of threads available to the executor
there could be a delay before the task starts. Clients can receive
notification via an optional progress listener.
runtime
- the run-time instance to executeprogressListener
- an optional progress listener (may be null
)public void shutdown()
public boolean shutdownAndWait(long timeOut, TimeUnit unit)
timeOut
- time-out periodunit
- time unittrue
if the executor has shutdown; false
if
the time-out period elapsed or the thread was interruptedpublic void shutdownNow()
Copyright © 2006–2018 GeoSolutions. All rights reserved.