Record Class ActorOptions
- Record Components:
mailboxCapacity- the maximum mailbox (queue) size;0for unboundedoverflow- the policy when a bounded mailbox is full; ignored whenmailboxCapacityis0stashCapacity- the maximum stash buffer size;0for unbounded (the back-compat default)stashOverflow- the policy when a bounded stash is full; ignored whenstashCapacityis0executor- the executor used to run the actor's processing loop;nullselects the default async executorcurrentSelfEnabled- whentrue, the actor publishes itself via a thread-local during handler dispatch so thatActor.currentSelf()can be used from inside handlers. Off by default to avoid paying for a mechanism the actor doesn't use.
Actor.
Carries the mailbox capacity / overflow policy, the optional stash
capacity / overflow policy, the executor, and the opt-in flag for
Actor.currentSelf() thread-local support. Pass to the
Actor.reactor(java.util.function.Function, ActorOptions) or
Actor.stateful(Object, java.util.function.BiFunction, ActorOptions)
factory variants. Settings that can be changed after construction
(currently: the error handler) are not carried here — see
Actor.onError(java.util.function.BiConsumer).
var actor = Actor.reactor(handler,
ActorOptions.DEFAULTS
.withBoundedMailbox(1000, ActorOptions.Overflow.BLOCK)
.withStashBound(64, ActorOptions.StashOverflow.REJECT)
.withExecutor(Pool.cpu()));
- Since:
- 6.0.0
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumPolicy applied whenActor.send(Object)is called on an actor whose bounded mailbox is full.static enumPolicy applied whenActorContext.stash()is called and the actor's bounded stash is already at capacity. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final ActorOptionsDefault options: unbounded mailbox, unbounded stash, default async executor, no thread-local current-self. -
Constructor Summary
ConstructorsConstructorDescriptionActorOptions(int mailboxCapacity, ActorOptions.Overflow overflow, int stashCapacity, ActorOptions.StashOverflow stashOverflow, Executor executor, boolean currentSelfEnabled) Canonical constructor — validates that capacities are non-negative and that the overflow policies are non-null. -
Method Summary
Modifier and TypeMethodDescriptionbooleanReturns the value of thecurrentSelfEnabledrecord component.final booleanIndicates whether some other object is "equal to" this one.executor()Returns the value of theexecutorrecord component.final inthashCode()Returns a hash code value for this object.booleanReturnstrueif the mailbox is bounded.booleanReturnstrueif the stash buffer is bounded.intReturns the value of themailboxCapacityrecord component.overflow()Returns the value of theoverflowrecord component.intReturns the value of thestashCapacityrecord component.Returns the value of thestashOverflowrecord component.final StringtoString()Returns a string representation of this record class.withBoundedMailbox(int capacity, ActorOptions.Overflow strategy) Returns a copy of these options configured with a bounded mailbox of the given capacity and overflow strategy.withCurrentSelf(boolean enabled) Returns a copy of these options with thread-localcurrentSelfsupport toggled.withExecutor(Executor executor) Returns a copy of these options configured to use the given executor for the actor's processing loop.withStashBound(int capacity, ActorOptions.StashOverflow strategy) Returns a copy of these options configured with a bounded stash buffer of the given capacity and overflow strategy.
-
Field Details
-
DEFAULTS
Default options: unbounded mailbox, unbounded stash, default async executor, no thread-local current-self.Note: the
overflowandstashOverflowvalues carried byDEFAULTSare placeholders, used only when the corresponding capacity is later raised above zero viawithBoundedMailbox(int, Overflow)orwithStashBound(int, StashOverflow). ReadisBounded()/isStashBounded()before treatingoverflow()/stashOverflow()as meaningful.
-
-
Constructor Details
-
ActorOptions
public ActorOptions(int mailboxCapacity, ActorOptions.Overflow overflow, int stashCapacity, ActorOptions.StashOverflow stashOverflow, Executor executor, boolean currentSelfEnabled) Canonical constructor — validates that capacities are non-negative and that the overflow policies are non-null. The executor may benull(meaning "use the default").
-
-
Method Details
-
withBoundedMailbox
Returns a copy of these options configured with a bounded mailbox of the given capacity and overflow strategy.Note:
capacity == 0is rejected here even though the canonical constructor accepts it. The constructor's0means "explicitly unbounded"; passing0to this builder almost always indicates a missing real capacity, so it fails fast. To revert a bounded actor to unbounded, build a new options instance fromDEFAULTS.- Parameters:
capacity- the mailbox capacity (must be positive)strategy- the overflow policy- Returns:
- a new
ActorOptionswith the bounded mailbox applied - Throws:
IllegalArgumentException- ifcapacityis not positive
-
withStashBound
Returns a copy of these options configured with a bounded stash buffer of the given capacity and overflow strategy. Unbounded by default — set a bound when the actor accepts messages from a source whose volume you do not control and the actor may stay in a stashing phase indefinitely.- Parameters:
capacity- the stash capacity (must be positive)strategy- the overflow policy- Returns:
- a new
ActorOptionswith the bounded stash applied - Throws:
IllegalArgumentException- ifcapacityis not positive- Since:
- 6.0.0
-
withExecutor
Returns a copy of these options configured to use the given executor for the actor's processing loop. Passnullto revert to the default async executor.- Parameters:
executor- the executor to use, ornullfor the default- Returns:
- a new
ActorOptionswith the executor applied
-
withCurrentSelf
Returns a copy of these options with thread-localcurrentSelfsupport toggled. When enabled, the actor publishes itself into a thread-local for the duration of each handler dispatch so thatActor.currentSelf()returns the executing actor.Off by default. Prefer the context-aware
StatefulHandler/ReactorHandlerfactories where possible; this knob exists for callers who want self-stop without restructuring to the context-aware handler shape.- Parameters:
enabled-trueto enableActor.currentSelf()support;falseto disable- Returns:
- a new
ActorOptionswith the flag applied - Since:
- 6.0.0
-
isBounded
public boolean isBounded()Returnstrueif the mailbox is bounded. -
isStashBounded
public boolean isStashBounded()Returnstrueif the stash buffer is bounded. -
toString
Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components. -
hashCode
public final int hashCode()Returns a hash code value for this object. The value is derived from the hash code of each of the record components. -
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared withObjects::equals(Object,Object); primitive components are compared with '=='. -
mailboxCapacity
public int mailboxCapacity()Returns the value of themailboxCapacityrecord component.- Returns:
- the value of the
mailboxCapacityrecord component
-
overflow
Returns the value of theoverflowrecord component.- Returns:
- the value of the
overflowrecord component
-
stashCapacity
public int stashCapacity()Returns the value of thestashCapacityrecord component.- Returns:
- the value of the
stashCapacityrecord component
-
stashOverflow
Returns the value of thestashOverflowrecord component.- Returns:
- the value of the
stashOverflowrecord component
-
executor
Returns the value of theexecutorrecord component.- Returns:
- the value of the
executorrecord component
-
currentSelfEnabled
public boolean currentSelfEnabled()Returns the value of thecurrentSelfEnabledrecord component.- Returns:
- the value of the
currentSelfEnabledrecord component
-