Task
Class RecurringNetworkTask<ReturnValueType>

java.lang.Object
  extended by Task.AbstractTask
      extended by Task.NetworkTask<ReturnValueType>
          extended by Task.RecurringNetworkTask<ReturnValueType>

public class RecurringNetworkTask<ReturnValueType>
extends NetworkTask<ReturnValueType>

This task is a subclass of NetworkTask. It adds the abillty to perform recurring tasks on top of the implementation of NetworkTask.

You can specify a refresh delay to define the schedule that will be used to run the TaskExecutor. You can change this at any time as well.

Since:
May 30, 2007, 1:33:23 PM
Version:
1.0
Author:
Nazmul Idris

Nested Class Summary
 
Nested classes/interfaces inherited from class Task.AbstractTask
AbstractTask.PropertyNames, AbstractTask.State, AbstractTask.Type
 
Field Summary
protected  java.util.concurrent.ScheduledExecutorService _execService
           
protected  int _refreshDelayInSec
           
protected  java.util.concurrent.ScheduledFuture _scheduledFuture
           
 
Fields inherited from class Task.NetworkTask
_exec, _swingWorker, _taskHandler, testMode_Enabled, testMode_isOnline
 
Fields inherited from class Task.AbstractTask
_autoShutdownRay, _boundProperties, _boundPropertiesLock, _shutdownCalled, _state, _status, _taskManager
 
Constructor Summary
RecurringNetworkTask(TaskExecutorIF<ReturnValueType> exec)
           
RecurringNetworkTask(TaskManager container, TaskExecutorIF<ReturnValueType> exec, java.lang.String name, java.lang.String descr, AutoShutdownSignals... policy)
           
 
Method Summary
protected  void _cancelScheduledFuture()
          This will cancel any Runnables that are being scheduled by the executor service.
protected  void _initScheduledFuture()
          This method actually attaches a Runnable object + delay with the _execService.
 void doShutdown()
          subclass should implement this method as is appropriate for them. this is called when the task is stopped, based on the AutoShutdownSignals policy
 AbstractTask.Type getType()
           
 void restartWithNewDelay(int refreshDelayInSec)
          After start(int) is called, this method can be used to change the refreshDelayInSec ...
 void setRefreshDelay(int refreshDelayInSec)
          Set the time delay between running TaskExecutorIF continually.
 void start()
          Start the recurring network task... it will use the default refresh delay...
 void start(int refreshDelayInSec)
          Start the recurring network task... it will periodically run the TaskExecutorIF in the background.
 void stopRecurring()
          Stop the recurring network task... this will stop the network task from running TaskExecutorIF in the background.
 
Methods inherited from class Task.NetworkTask
_createSwingWorker, _openGate, execute, executeAndWait, getSwingWorker, setTaskHandler, setTestMode_isOnline
 
Methods inherited from class Task.AbstractTask
_assertIsNotShutdown, _assertNoSwingWorkerCurrentlyActive, addStatusListener, cancel, clearAllStatusListeners, formattedString, getAutoShutdownPolicy, getBoundProperties, getDescription, getName, getState, getStatus, getTaskManager, getUIHook, hasAutoShutdownPolicy, isShutdown, setAutoShutdownPolicy, setDescription, setName, setState, setStatus, setTaskManager, shutdown
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_refreshDelayInSec

protected int _refreshDelayInSec

_execService

protected java.util.concurrent.ScheduledExecutorService _execService

_scheduledFuture

protected java.util.concurrent.ScheduledFuture _scheduledFuture
Constructor Detail

RecurringNetworkTask

public RecurringNetworkTask(TaskManager container,
                            TaskExecutorIF<ReturnValueType> exec,
                            java.lang.String name,
                            java.lang.String descr,
                            AutoShutdownSignals... policy)
                     throws java.lang.IllegalArgumentException
Throws:
java.lang.IllegalArgumentException

RecurringNetworkTask

public RecurringNetworkTask(TaskExecutorIF<ReturnValueType> exec)
Method Detail

getType

public AbstractTask.Type getType()
Overrides:
getType in class NetworkTask<ReturnValueType>

doShutdown

public void doShutdown()
subclass should implement this method as is appropriate for them. this is called when the task is stopped, based on the AutoShutdownSignals policy

Overrides:
doShutdown in class NetworkTask<ReturnValueType>

start

public void start(int refreshDelayInSec)
           throws TaskException
Start the recurring network task... it will periodically run the TaskExecutorIF in the background.

Throws:
TaskException

start

public void start()
           throws TaskException
Start the recurring network task... it will use the default refresh delay...

Throws:
TaskException

restartWithNewDelay

public void restartWithNewDelay(int refreshDelayInSec)
                         throws TaskException
After start(int) is called, this method can be used to change the refreshDelayInSec ...

Throws:
TaskException

_initScheduledFuture

protected void _initScheduledFuture()
                             throws TaskException
This method actually attaches a Runnable object + delay with the _execService.

The way this scheduler works is that it creates a new task at a delay. As long as a task is running, it will not create another one. So, the NetworkTask.executeAndWait() method just creates a new SwingWorker, and then waits for it to complete. The reason not to use NetworkTask.execute() is simply to keep new tasks from getting created until the first one finishes. That's why there is a gate to block the currently executing Runnable below until the underlying SwingWorker is complete!

So really, the total delay between these SwingWorkers being spawned is: Time required by the SwingWorker to execute to completion (err, ok, interrupted) + delay

Throws:
TaskException

_cancelScheduledFuture

protected void _cancelScheduledFuture()
This will cancel any Runnables that are being scheduled by the executor service. Additionally, if any SwingWorkers are currently running, they are cancelled as well.

See Also:
AbstractTask.cancel(), NetworkTask.executeAndWait()

stopRecurring

public void stopRecurring()
Stop the recurring network task... this will stop the network task from running TaskExecutorIF in the background. Also, stop any currently executing tasks:
  1. Thread: NetworkTask.getSwingWorker() - Method to kill it:AbstractTask.cancel()
  2. Thread: _scheduledFuture - Method to kill it:_cancelScheduledFuture()


setRefreshDelay

public void setRefreshDelay(int refreshDelayInSec)
Set the time delay between running TaskExecutorIF continually.

Parameters:
refreshDelayInSec - the time delay is in TimeUnit.SECONDS


Copyright © 2011. All Rights Reserved.