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.voidsetExecutorServiceFactory(ExecutorServiceFactory<ExecutorService> executorServiceFactory) voidsetResourceService(ResourceService resourceService) voidsetScheduledExecutorServiceFactory(ExecutorServiceFactory<ScheduledExecutorService> scheduledExecutorServiceFactory) voidstart()Starts the Scheduler.voidstop()Shuts down the Scheduler.<T> Future<T> Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods 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:SchedulerStarts the Scheduler. Attempting to invoke any the other methods before invoking this will result in anIllegalStateException. -
stop
public void stop()Description copied from interface:SchedulerShuts down the Scheduler. Attempting to invoke any the other methods after invoking this will result in anIllegalStateExceptionuntil a subsequent call toScheduler.start()is made. -
submit
Description copied from interface:Scheduler -
scheduleUnlink
Description copied from interface:SchedulerProvided 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 anyResources associated with the suppliedPath. If theResourceis 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:
scheduleUnlinkin interfaceScheduler- Parameters:
path- thePathto 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:SchedulerProvided 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 theResourceassociated with the supplied.ResourceId. This ensures that the underlyingResourceis removed from theResourceServiceand itsResource.close()method invoked. This returns aRunnableFuture<Void>which may be run sooner to short-circuit the unlink operation- Specified by:
scheduleDestructionin 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:SchedulerPerforms 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:SchedulerPerforms 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:SchedulerPerforms the suppliedFunction<Resource,after a specified delay. The delay is calculated using the supplied time andT> TimeUnit.- Specified by:
performAfterDelayin 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
-