Package dev.getelements.elements.rt
Class SimpleScheduler
java.lang.Object
dev.getelements.elements.rt.SimpleScheduler
- All Implemented Interfaces:
Scheduler
The simple handler server is responsible for dispatching requests and events to all
Resource
instances
contained therein.
Internally, it leverages an instance an ExecutorService
and a CompletionService
to
perform all updates in parallel.
Created by patricktwohig on 8/22/15.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<T> Future
<T> perform
(ResourceId resourceId, Function<ResourceService.ResourceTransaction, T> operation, Consumer<Throwable> failure) Performs an action against the resource with the providedResourceId
.<T> Future
<T> perform
(Path path, Function<ResourceService.ResourceTransaction, T> operation, Consumer<Throwable> failure) Performs an action against the resource with the providedResourceId
<T> Future
<T> performAfterDelay
(ResourceId resourceId, long time, TimeUnit timeUnit, Function<ResourceService.ResourceTransaction, T> operation, Consumer<Throwable> failure) scheduleDestruction
(ResourceId resourceId) scheduleDestruction
(ResourceId resourceId, long delay, TimeUnit timeUnit) Provided theResourceId
, this will schedule destruction at some point in the near future, but not before.scheduleUnlink
(Path path, long delay, TimeUnit timeUnit) Provided thePath
, this will schedule an unlink operation at some point in the near future, but not before the delay time specified in the parameters of this method.void
setExecutorServiceFactory
(ExecutorServiceFactory<ExecutorService> executorServiceFactory) void
setResourceService
(ResourceService resourceService) void
setScheduledExecutorServiceFactory
(ExecutorServiceFactory<ScheduledExecutorService> scheduledExecutorServiceFactory) void
start()
Starts the Scheduler.void
stop()
Shuts down the Scheduler.<T> Future
<T> Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface dev.getelements.elements.rt.Scheduler
performAfterDelayV, performV, performV, resumeTask, resumeTaskAfterDelay, submitV
-
Constructor Details
-
SimpleScheduler
public SimpleScheduler()
-
-
Method Details
-
start
public void start()Description copied from interface:Scheduler
Starts the Scheduler. Attempting to invoke any the other methods before invoking this will result in anIllegalStateException
. -
stop
public void stop()Description copied from interface:Scheduler
Shuts down the Scheduler. Attempting to invoke any the other methods after invoking this will result in anIllegalStateException
until a subsequent call toScheduler.start()
is made. -
submit
Description copied from interface:Scheduler
-
scheduleUnlink
Description copied from interface:Scheduler
Provided thePath
, this will schedule an unlink operation at some point in the near future, but not before the delay time specified in the parameters of this method. Any pending operations to relase their locks gracefully unlink an potentially destroy anyResource
s associated with the suppliedPath
. If theResource
is removed this will ensure that theResource.close()
method is called appropriately. This returns aRunnableFuture<Void>
which may be run sooner to short-circuit the unlink operation- Specified by:
scheduleUnlink
in interfaceScheduler
- Parameters:
path
- thePath
to unlink- Returns:
- a
RunnableFuture<Void>
used to signal destruction, may be run sooner by the calling code
-
scheduleDestruction
public RunnableFuture<Void> scheduleDestruction(ResourceId resourceId, long delay, TimeUnit timeUnit) Description copied from interface:Scheduler
Provided theResourceId
, this will schedule destruction at some point in the near future, but not before. the delay specified in the arguments to this method. This allows any pending operations to scheduleRelease their locks gracefully and destroy theResource
associated with the supplied.ResourceId
. This ensures that the underlyingResource
is removed from theResourceService
and itsResource.close()
method invoked. This returns aRunnableFuture<Void>
which may be run sooner to short-circuit the unlink operation- Specified by:
scheduleDestruction
in interfaceScheduler
- Parameters:
resourceId
- theResourceId
- Returns:
- a
RunnableFuture<Void>
used to signal destruction, may be run sooner by the calling code
-
scheduleDestruction
-
perform
public <T> Future<T> perform(ResourceId resourceId, Function<ResourceService.ResourceTransaction, T> operation, Consumer<Throwable> failure) Description copied from interface:Scheduler
Performs an action against the resource with the providedResourceId
. -
perform
public <T> Future<T> perform(Path path, Function<ResourceService.ResourceTransaction, T> operation, Consumer<Throwable> failure) Description copied from interface:Scheduler
Performs an action against the resource with the providedResourceId
-
performAfterDelay
public <T> Future<T> performAfterDelay(ResourceId resourceId, long time, TimeUnit timeUnit, Function<ResourceService.ResourceTransaction, T> operation, Consumer<Throwable> failure) Description copied from interface:Scheduler
Performs the suppliedFunction<Resource,
after a specified delay. The delay is calculated using the supplied time andT> TimeUnit
.- Specified by:
performAfterDelay
in interfaceScheduler
- Type Parameters:
T
-- Parameters:
resourceId
- the id of the resourcetime
- the time value to delaytimeUnit
- the units of the time valueoperation
- the operation to perform- Returns:
Future<T>
which can be used to monitor the status of the request
-
getExecutorServiceFactory
-
setExecutorServiceFactory
@Inject public void setExecutorServiceFactory(@Named("dev.getelements.elements.rt.executor") ExecutorServiceFactory<ExecutorService> executorServiceFactory) -
getScheduledExecutorServiceFactory
-
setScheduledExecutorServiceFactory
@Inject public void setScheduledExecutorServiceFactory(@Named("dev.getelements.elements.rt.scheduled.executor") ExecutorServiceFactory<ScheduledExecutorService> scheduledExecutorServiceFactory) -
getResourceService
-
setResourceService
-