Class ConsumerAction

java.lang.Object
cloud.opencode.base.rules.action.ConsumerAction
All Implemented Interfaces:
Action

public class ConsumerAction extends Object implements Action
Consumer Action - Action Based on Java Consumer 消费者动作 - 基于Java消费者的动作

Wraps a Java Consumer as a rule action for flexible action definition.

将Java消费者包装为规则动作,以便灵活定义动作。

Features | 主要功能:

  • Consumer-to-Action adapter - 消费者到动作的适配器
  • Lambda-friendly API - Lambda友好的API
  • Factory method support - 工厂方法支持

Usage Examples | 使用示例:

Action action = new ConsumerAction(ctx -> {
    double amount = ctx.get("amount");
    ctx.setResult("discount", amount * 0.1);
});

Security | 安全性:

  • Thread-safe: No (depends on consumer) - 线程安全: 否(取决于消费者)
  • Null-safe: No (consumer must not be null) - 空值安全: 否(消费者不能为null)
Since:
JDK 25, opencode-base-rules V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Constructor Details

    • ConsumerAction

      public ConsumerAction(Consumer<RuleContext> consumer)
      Creates a consumer action 创建消费者动作
      Parameters:
      consumer - the consumer | 消费者
  • Method Details

    • execute

      public void execute(RuleContext context)
      Description copied from interface: Action
      Executes this action with the given context 使用给定上下文执行此动作
      Specified by:
      execute in interface Action
      Parameters:
      context - the rule context | 规则上下文
    • of

      public static ConsumerAction of(Consumer<RuleContext> consumer)
      Creates a consumer action from a consumer 从消费者创建消费者动作
      Parameters:
      consumer - the consumer | 消费者
      Returns:
      the action | 动作