org.dfdaemon.il2.core.task.impl
Class CoreTaskExecutorImpl

java.lang.Object
  extended by org.dfdaemon.il2.core.task.impl.CoreTaskExecutorImpl
All Implemented Interfaces:
CoreTaskExecutionCallback, CoreTaskExecutor, CoreTaskScheduler, Lifecycle

public final class CoreTaskExecutorImpl
extends Object
implements CoreTaskExecutionCallback, Lifecycle, CoreTaskExecutor, CoreTaskScheduler

Class CoreTaskExecutorImpl manages CoreTasks in a way, that submit(org.dfdaemon.il2.core.task.CoreTask) waits for task initialization (by waiting for CoreTask.preRun() complete).

By default, if thread terminates with error, manager will shutdown in a whole.

Author:
aka50 Created on 04.05.2007

Field Summary
 
Fields inherited from interface org.dfdaemon.il2.core.task.CoreTaskExecutionCallback
EMPTY
 
Constructor Summary
CoreTaskExecutorImpl()
           
 
Method Summary
 void awaitCompletition(CoreTask task)
          Wait for task with specified time (if interrupted, simple return with no really completition guarantee).
 void awaitCompletition(CoreTask task, long amount, TimeUnit units)
          Wait for task with infinite time (if interrupted, simple return with no really completition guarantee).
 boolean awaitTermination(long timeout, TimeUnit unit)
          Awaits for shutdown specified amount of time.
 void cancel(CoreTask task)
          Cancel task with infinite wait (if interrupted, simple return with no really cancel guarantee).
 void cancel(CoreTask task, long amount, TimeUnit units)
          Cancel with specified waittime.
 boolean isRunning()
          
 boolean isTerminated()
          Getter for property 'terminated'.
 void onTaskCompletition(CoreTask task)
          Succesfull task completition.
 void onTaskCrash(CoreTask task, Throwable t)
          Task crashed.
 boolean schedule(CoreTask task, CoreTaskSchedulerPolicy policy)
          
 void setStartupCoreTasks(Map<String,CoreTask> startupCoreTasks)
          Setter for property 'startupCoreTasks'.
 void setWaitTime(int waitSeconds)
          Setter for property 'waitTime'.
 void shutdownNow()
          Method shutdown instance.
 void start()
          
 void stop()
          
 boolean submit(CoreTask task)
          Method submits task for execution with default crash handler
 boolean submit(CoreTask task, CoreTaskExecutionCallback handler)
          Method submit task for execution with userdefinded crash handler.
 void unschedule(CoreTask task)
          
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CoreTaskExecutorImpl

public CoreTaskExecutorImpl()
Method Detail

submit

public boolean submit(CoreTask task)
Method submits task for execution with default crash handler

Specified by:
submit in interface CoreTaskExecutor
Parameters:
task - of type CoreTask
Returns:
boolean

submit

public boolean submit(CoreTask task,
                      CoreTaskExecutionCallback handler)
Method submit task for execution with userdefinded crash handler.

Specified by:
submit in interface CoreTaskExecutor
Parameters:
task - of type CoreTask
handler - of type CoreTaskExecutionCallback (if null, default will be used).
Returns:
boolean

cancel

public void cancel(CoreTask task,
                   long amount,
                   TimeUnit units)
            throws InterruptedException
Cancel with specified waittime.

Specified by:
cancel in interface CoreTaskExecutor
Parameters:
task - of type CoreTask
amount - of type long
units - of type TimeUnit
Throws:
InterruptedException - when

cancel

public void cancel(CoreTask task)
Cancel task with infinite wait (if interrupted, simple return with no really cancel guarantee).

Specified by:
cancel in interface CoreTaskExecutor
Parameters:
task - of type CoreTask

isTerminated

public boolean isTerminated()
Getter for property 'terminated'.

Returns:
Value for property 'terminated'.

shutdownNow

public void shutdownNow()
Method shutdown instance.


awaitTermination

public boolean awaitTermination(long timeout,
                                TimeUnit unit)
                         throws InterruptedException
Awaits for shutdown specified amount of time.

Specified by:
awaitTermination in interface CoreTaskExecutor
Parameters:
timeout - of type long
unit - of type TimeUnit
Returns:
boolean
Throws:
InterruptedException - when

schedule

public boolean schedule(CoreTask task,
                        CoreTaskSchedulerPolicy policy)

Specified by:
schedule in interface CoreTaskScheduler

unschedule

public void unschedule(CoreTask task)

Specified by:
unschedule in interface CoreTaskScheduler

awaitCompletition

public void awaitCompletition(CoreTask task)
                       throws InterruptedException
Wait for task with specified time (if interrupted, simple return with no really completition guarantee).

Specified by:
awaitCompletition in interface CoreTaskExecutor
Parameters:
task - of type CoreTask
Throws:
InterruptedException - on interrupt

awaitCompletition

public void awaitCompletition(CoreTask task,
                              long amount,
                              TimeUnit units)
                       throws InterruptedException
Wait for task with infinite time (if interrupted, simple return with no really completition guarantee).

Specified by:
awaitCompletition in interface CoreTaskExecutor
Parameters:
task - of type CoreTask
amount - amount of TimeUnits
units - TimeUnits
Throws:
InterruptedException - on interrupt

setWaitTime

public void setWaitTime(int waitSeconds)
Setter for property 'waitTime'.

Parameters:
waitSeconds - Value to set for property 'waitTime'.

setStartupCoreTasks

public void setStartupCoreTasks(Map<String,CoreTask> startupCoreTasks)
Setter for property 'startupCoreTasks'.

Parameters:
startupCoreTasks - Value to set for property 'startupCoreTasks'.

start

public void start()

Specified by:
start in interface Lifecycle

stop

public void stop()

Specified by:
stop in interface Lifecycle

isRunning

public boolean isRunning()

Specified by:
isRunning in interface Lifecycle

onTaskCompletition

public void onTaskCompletition(CoreTask task)
Succesfull task completition.

Specified by:
onTaskCompletition in interface CoreTaskExecutionCallback
Parameters:
task - of type CoreTask

onTaskCrash

public void onTaskCrash(CoreTask task,
                        Throwable t)
Task crashed.

Specified by:
onTaskCrash in interface CoreTaskExecutionCallback
Parameters:
task - crashed instance of type CoreTask
t - of type Throwable


Copyright © 2007-2008. All Rights Reserved.