org.jetlinks.rule.engine.api.RuleData Maven / Gradle / Ivy
The newest version!
package org.jetlinks.rule.engine.api;
import com.alibaba.fastjson.JSON;
import lombok.Getter;
import lombok.Setter;
import org.hswebframework.web.bean.FastBeanCopier;
import org.hswebframework.web.id.IDGenerator;
import org.jetlinks.core.metadata.Jsonable;
import org.jetlinks.core.utils.SerializeUtils;
import reactor.core.publisher.Flux;
import java.io.*;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Consumer;
/**
* 规则数据,用于在规则之间传递数据
*
* @author zhouhao
* @since 1.0.0
*/
@Getter
@Setter
public class RuleData implements Externalizable {
private static final long serialVersionUID = 1L;
public static final String RECORD_DATA_TO_HEADER = "record_data_to_header";
public static final String RECORD_DATA_TO_HEADER_KEY = "record_data_to_header_key";
public static final String RECORD_DATA_TO_HEADER_KEY_PREFIX = "rd:";
public static final String HEADER_SOURCE_NODE_ID = "sourceNode";
static {
SerializeUtils.registerSerializer(0x50, RuleData.class, ignore -> new RuleData());
}
/**
* 数据ID
*/
private String id;
/**
* 上下文ID,在一条数据创建时生成,在传递过程中此ID不变
*/
private String contextId;
/**
* 真实数据
*/
private Object data;
/**
* 规则头信息,可以通过头信息来传递更多的拓展消息
*/
@Getter
private Map headers = new ConcurrentHashMap<>(16);
public void setHeader(String key, Object value) {
if (key == null || value == null) {
return;
}
headers.put(key, value);
}
public void removeHeader(String key) {
if (key == null) {
return;
}
headers.remove(key);
}
public void clearHeader() {
headers.clear();
}
public Optional