com.github.lontime.extredisson.rpc.common.CallContext Maven / Gradle / Ivy
package com.github.lontime.extredisson.rpc.common;
import java.time.Duration;
import java.util.ArrayList;
import java.util.List;
import com.github.lontime.base.serial.mq.Header;
import lombok.Getter;
/**
* CallContext.
* @author lontime
* @since 1.0
*/
@Getter
public class CallContext {
private final String redissonName;
private final String serviceName;
private final String methodName;
private final Duration timeout;
private final List headers;
private final List tags;
private final Boolean ack;
private final Boolean fastReply;
private final long createdTime;
public CallContext(String redissonName, String serviceName, String methodName, Duration timeout, List headers, List tags, Boolean ack, Boolean fastReply) {
this.redissonName = redissonName;
this.serviceName = serviceName;
this.methodName = methodName;
this.timeout = timeout;
this.headers = headers;
this.tags = tags;
this.ack = ack;
this.fastReply = fastReply;
this.createdTime = System.currentTimeMillis();
}
public static Builder builder() {
return new Builder();
}
public static class Builder {
private String redissonName;
private String serviceName;
private String methodName = "index";
private Duration timeout = Duration.ofMinutes(2);
private List headers = new ArrayList<>();
private List tags = new ArrayList<>();
private Boolean ack = Boolean.FALSE;
private Boolean fastReply = Boolean.FALSE;
public CallContext build() {
return new CallContext(redissonName, serviceName, methodName, timeout, headers, tags, ack, fastReply);
}
public Builder redissonName(String redissonName) {
this.redissonName = redissonName;
return this;
}
public Builder serviceName(String serviceName) {
this.serviceName = serviceName;
return this;
}
public Builder methodName(String methodName) {
this.methodName = methodName;
return this;
}
public Builder timeout(Duration timeout) {
this.timeout = timeout;
return this;
}
public Builder header(String key, String value) {
this.headers.add(Header.from(key, value));
return this;
}
public Builder header(Header header) {
this.headers.add(header);
return this;
}
public Builder headers(List headers) {
this.headers.addAll(headers);
return this;
}
public Builder tag(String tag) {
this.tags.add(tag);
return this;
}
public Builder tags(List tags) {
this.tags.addAll(tags);
return this;
}
public Builder ack() {
this.ack = true;
return this;
}
public Builder fastReply() {
this.fastReply = true;
return this;
}
}
}