Class ResourceBasedSlotSupplier<SI extends SlotInfo>
- java.lang.Object
-
- io.temporal.worker.tuning.ResourceBasedSlotSupplier<SI>
-
- All Implemented Interfaces:
SlotSupplier<SI>
public class ResourceBasedSlotSupplier<SI extends SlotInfo> extends java.lang.Object implements SlotSupplier<SI>
Implements aSlotSupplierbased on resource usage for a particular slot type.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static ResourceBasedSlotSupplier<ActivitySlotInfo>createForActivity(ResourceBasedController resourceBasedController, ResourceBasedSlotOptions options)Construct a slot supplier for activity tasks with the given resource controller and options.static ResourceBasedSlotSupplier<ActivitySlotInfo>createForActivity(ResourceBasedController resourceBasedController, ResourceBasedSlotOptions options, java.util.concurrent.ScheduledExecutorService scheduler)AscreateForActivity(ResourceBasedController, ResourceBasedSlotOptions), but allows overriding the internal thread pool.static ResourceBasedSlotSupplier<LocalActivitySlotInfo>createForLocalActivity(ResourceBasedController resourceBasedController, ResourceBasedSlotOptions options)Construct a slot supplier for local activities with the given resource controller and options.static ResourceBasedSlotSupplier<LocalActivitySlotInfo>createForLocalActivity(ResourceBasedController resourceBasedController, ResourceBasedSlotOptions options, java.util.concurrent.ScheduledExecutorService scheduler)AscreateForLocalActivity(ResourceBasedController, ResourceBasedSlotOptions), but allows overriding the internal thread pool.static ResourceBasedSlotSupplier<NexusSlotInfo>createForNexus(ResourceBasedController resourceBasedController, ResourceBasedSlotOptions options)Construct a slot supplier for nexus tasks with the given resource controller and options.static ResourceBasedSlotSupplier<NexusSlotInfo>createForNexus(ResourceBasedController resourceBasedController, ResourceBasedSlotOptions options, java.util.concurrent.ScheduledExecutorService scheduler)AscreateForNexus(ResourceBasedController, ResourceBasedSlotOptions), but allows overriding the internal thread pool.static ResourceBasedSlotSupplier<WorkflowSlotInfo>createForWorkflow(ResourceBasedController resourceBasedController, ResourceBasedSlotOptions options)Construct a slot supplier for workflow tasks with the given resource controller and options.static ResourceBasedSlotSupplier<WorkflowSlotInfo>createForWorkflow(ResourceBasedController resourceBasedController, ResourceBasedSlotOptions options, java.util.concurrent.ScheduledExecutorService scheduler)AscreateForWorkflow(ResourceBasedController, ResourceBasedSlotOptions), but allows overriding the internal thread pool.ResourceBasedControllergetResourceController()voidmarkSlotUsed(SlotMarkUsedContext<SI> ctx)This function is called once a slot is actually being used to process some task, which may be some time after the slot was reserved originally.voidreleaseSlot(SlotReleaseContext<SI> ctx)This function is called once a permit is no longer needed.SlotSupplierFuturereserveSlot(SlotReserveContext<SI> ctx)This function is called before polling for new tasks.java.util.Optional<SlotPermit>tryReserveSlot(SlotReserveContext<SI> ctx)This function is called when trying to reserve slots for "eager" workflow and activity tasks.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface io.temporal.worker.tuning.SlotSupplier
getMaximumSlots
-
-
-
-
Method Detail
-
createForWorkflow
public static ResourceBasedSlotSupplier<WorkflowSlotInfo> createForWorkflow(ResourceBasedController resourceBasedController, ResourceBasedSlotOptions options)
Construct a slot supplier for workflow tasks with the given resource controller and options.The resource controller must be the same among all slot suppliers in a worker. If you want to use resource-based tuning for all slot suppliers, prefer
ResourceBasedTuner.
-
createForWorkflow
public static ResourceBasedSlotSupplier<WorkflowSlotInfo> createForWorkflow(ResourceBasedController resourceBasedController, ResourceBasedSlotOptions options, java.util.concurrent.ScheduledExecutorService scheduler)
AscreateForWorkflow(ResourceBasedController, ResourceBasedSlotOptions), but allows overriding the internal thread pool. It is recommended to share the same executor across all resource based slot suppliers in a worker.
-
createForActivity
public static ResourceBasedSlotSupplier<ActivitySlotInfo> createForActivity(ResourceBasedController resourceBasedController, ResourceBasedSlotOptions options)
Construct a slot supplier for activity tasks with the given resource controller and options.The resource controller must be the same among all slot suppliers in a worker. If you want to use resource-based tuning for all slot suppliers, prefer
ResourceBasedTuner.
-
createForActivity
public static ResourceBasedSlotSupplier<ActivitySlotInfo> createForActivity(ResourceBasedController resourceBasedController, ResourceBasedSlotOptions options, java.util.concurrent.ScheduledExecutorService scheduler)
AscreateForActivity(ResourceBasedController, ResourceBasedSlotOptions), but allows overriding the internal thread pool. It is recommended to share the same executor across all resource based slot suppliers in a worker.
-
createForLocalActivity
public static ResourceBasedSlotSupplier<LocalActivitySlotInfo> createForLocalActivity(ResourceBasedController resourceBasedController, ResourceBasedSlotOptions options)
Construct a slot supplier for local activities with the given resource controller and options.The resource controller must be the same among all slot suppliers in a worker. If you want to use resource-based tuning for all slot suppliers, prefer
ResourceBasedTuner.
-
createForLocalActivity
public static ResourceBasedSlotSupplier<LocalActivitySlotInfo> createForLocalActivity(ResourceBasedController resourceBasedController, ResourceBasedSlotOptions options, java.util.concurrent.ScheduledExecutorService scheduler)
AscreateForLocalActivity(ResourceBasedController, ResourceBasedSlotOptions), but allows overriding the internal thread pool. It is recommended to share the same executor across all resource based slot suppliers in a worker.
-
createForNexus
public static ResourceBasedSlotSupplier<NexusSlotInfo> createForNexus(ResourceBasedController resourceBasedController, ResourceBasedSlotOptions options)
Construct a slot supplier for nexus tasks with the given resource controller and options.The resource controller must be the same among all slot suppliers in a worker. If you want to use resource-based tuning for all slot suppliers, prefer
ResourceBasedTuner.
-
createForNexus
public static ResourceBasedSlotSupplier<NexusSlotInfo> createForNexus(ResourceBasedController resourceBasedController, ResourceBasedSlotOptions options, java.util.concurrent.ScheduledExecutorService scheduler)
AscreateForNexus(ResourceBasedController, ResourceBasedSlotOptions), but allows overriding the internal thread pool. It is recommended to share the same executor across all resource based slot suppliers in a worker.
-
reserveSlot
public SlotSupplierFuture reserveSlot(SlotReserveContext<SI> ctx) throws java.lang.Exception
Description copied from interface:SlotSupplierThis function is called before polling for new tasks. Your implementation should return a future that is completed with aSlotPermitwhen one becomes available.These futures may be cancelled if the worker is shutting down or otherwise abandons the reservation. This can cause an
InterruptedExceptionto be thrown, in the thread running your implementation. You may want to catch it to perform any necessary cleanup, and then you should rethrow the exception. Other thrown exceptions will be logged.- Specified by:
reserveSlotin interfaceSlotSupplier<SI extends SlotInfo>- Parameters:
ctx- The context for slot reservation.- Returns:
- A future that will be completed with a permit to use the slot when one becomes available. Never return null, or complete the future with null.
- Throws:
java.lang.Exception
-
tryReserveSlot
public java.util.Optional<SlotPermit> tryReserveSlot(SlotReserveContext<SI> ctx)
Description copied from interface:SlotSupplierThis function is called when trying to reserve slots for "eager" workflow and activity tasks. Eager tasks are those which are returned as a result of completing a workflow task, rather than from polling. Your implementation must not block, and If a slot is available, return a permit to use that slot.- Specified by:
tryReserveSlotin interfaceSlotSupplier<SI extends SlotInfo>- Parameters:
ctx- The context for slot reservation.- Returns:
- Maybe a permit to use the slot which may be populated with your own data.
-
markSlotUsed
public void markSlotUsed(SlotMarkUsedContext<SI> ctx)
Description copied from interface:SlotSupplierThis function is called once a slot is actually being used to process some task, which may be some time after the slot was reserved originally. For example, if there is no work for a worker, a number of slots equal to the number of active pollers may already be reserved, but none of them are being used yet. This call should be non-blocking.- Specified by:
markSlotUsedin interfaceSlotSupplier<SI extends SlotInfo>- Parameters:
ctx- The context for marking a slot as used.
-
releaseSlot
public void releaseSlot(SlotReleaseContext<SI> ctx)
Description copied from interface:SlotSupplierThis function is called once a permit is no longer needed. This could be because the task has finished, whether successfully or not, or because the slot was no longer needed (ex: the number of active pollers decreased). This call should be non-blocking.- Specified by:
releaseSlotin interfaceSlotSupplier<SI extends SlotInfo>- Parameters:
ctx- The context for releasing a slot.
-
getResourceController
public ResourceBasedController getResourceController()
-
-