Enum Class ExecutorSelector
- All Implemented Interfaces:
Serializable, Comparable<ExecutorSelector>, Constable
Subscriber thread executor selection strategy.
for example
public class YourEventBusSubscriber implements EventBusSubscriber {
// Specify the thread executor to execute the subscriber's logic
@EventSubscribe(ExecutorSelector.userExecutor)
public void userLogin(YourEventMessage message) {
log.info("event - User [{}] logged in", message.getUserId());
}
}
@Data
public class YourEventMessage {
final long userId;
public YourEventMessage(long userId) {
this.userId = userId;
}
}
- Since:
- 21
- Author:
- 渔民小镇
- See Also:
- date:
- 2024-01-11
-
Nested Class Summary
Nested classes/interfaces inherited from class Enum
Enum.EnumDesc<E> -
Enum Constant Summary
Enum ConstantsEnum ConstantDescriptionReserved for developers[Thread Safe] Execute in a thread executor[Thread Safe] Execute in a thread executor[Thread Safe] Execute in the user thread executorExecute in the virtual thread executor -
Method Summary
Modifier and TypeMethodDescriptionstatic ExecutorSelectorReturns the enum constant of this class with the specified name.static ExecutorSelector[]values()Returns an array containing the constants of this enum class, in the order they are declared.
-
Enum Constant Details
-
userExecutor
[Thread Safe] Execute in the user thread executorThis strategy will use the action's thread executor to ensure that the same user (userId), when consuming events and actions, uses the same thread executor to avoid concurrency issues. Note: Do not perform time-consuming IO-related operations to avoid blocking the consumption of actions.
- See Also:
-
userVirtualExecutor
Execute in the virtual thread executorTime-consuming operations can choose this strategy
- See Also:
-
methodExecutor
[Thread Safe] Execute in a thread executorThis strategy will use the Subscriber.id to determine the thread executor, ensuring that the same subscriber method, when consuming events, uses the same thread executor to avoid concurrency issues. Note: Do not perform time-consuming IO-related operations to avoid blocking the consumption of other subscribers. Other supplementary explanation: Subscriber.id is allocated by the framework. This strategy is similar to userExecutor and simpleExecutor. userExecutor and simpleExecutor use userId to determine the thread executor, while methodExecutor uses the subscriber's own Subscriber.id to determine the thread executor (you can think of it as being partitioned by subscriber method).
- See Also:
-
simpleExecutor
[Thread Safe] Execute in a thread executorThis strategy is similar to userExecutor, but uses an independent thread executor (
ExecutorRegion.getSimpleThreadExecutorRegion()). When using, the developer needs to set the value ofEventBusMessage.threadIndex(this value needs to be > 0).- See Also:
-
customExecutor
Reserved for developersIf the above strategies do not meet the business requirements, developers can implement the
exampleSubscribeExecutorStrategyinterface for custom extension// The logic server adds EventBusRunner to handle EventBus related business builder.addRunner(new AbstractEventBusRunner() { @Override public void registerEventBus(EventBus eventBus, BarSkeleton skeleton) { // Your thread executor selection strategy eventBus.setSubscribeExecutorStrategy(new YourSubscribeExecutorStrategy()); } });- See Also:
-
-
Method Details
-
values
Returns an array containing the constants of this enum class, in the order they are declared.- Returns:
- an array containing the constants of this enum class, in the order they are declared
-
valueOf
Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)- Parameters:
name- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
IllegalArgumentException- if this enum class has no constant with the specified nameNullPointerException- if the argument is null
-