From bd14848600fa40729922b988041f5673994ae240 Mon Sep 17 00:00:00 2001 From: Chuanyi Li L Date: Thu, 2 Aug 2018 17:36:22 +0800 Subject: [PATCH] Builder of Aggregator. --- .../listener/ChannelFutureAggregator.java | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/server/src/main/java/com/alibaba/otter/canal/server/netty/listener/ChannelFutureAggregator.java b/server/src/main/java/com/alibaba/otter/canal/server/netty/listener/ChannelFutureAggregator.java index aa9b0da3..e3f60dca 100644 --- a/server/src/main/java/com/alibaba/otter/canal/server/netty/listener/ChannelFutureAggregator.java +++ b/server/src/main/java/com/alibaba/otter/canal/server/netty/listener/ChannelFutureAggregator.java @@ -4,6 +4,7 @@ import com.alibaba.otter.canal.protocol.CanalPacket; import org.jboss.netty.channel.ChannelFuture; import org.jboss.netty.channel.ChannelFutureListener; +import java.util.Optional; import java.util.concurrent.ConcurrentHashMap; /** @@ -39,4 +40,64 @@ public class ChannelFutureAggregator implements ChannelFutureListener { Throwable t = future.getCause(); } } + + public static class ClientRequestResult { + + private String dest; + + private CanalPacket.PacketType type; + + private int amount; + + private int errorCode; + + private ClientRequestResult() {} + + private ClientRequestResult(Builder builder) { + this.dest = builder.dest; + this.type = builder.type; + this.amount = builder.amount; + this.errorCode = builder.errorCode; + } + + private static class Builder { + + private String dest; + private CanalPacket.PacketType type; + private int amount; + private int errorCode; + + public Builder dest(String dest) { + this.dest = dest; + return this; + } + + public Builder type(CanalPacket.PacketType type) { + this.type = type; + return this; + } + + public Builder amount(int amount) { + this.amount = amount; + return this; + } + + public Builder errorCode(int errorCode) { + this.errorCode = errorCode; + return this; + } + + public Builder fromPrototype(ClientRequestResult prototype) { + dest = prototype.dest; + type = prototype.type; + amount = prototype.amount; + errorCode = prototype.errorCode; + return this; + } + + public ClientRequestResult build() { + return new ClientRequestResult(this); + } + } + } }