Browse Source

netty3 future listener for metrics.

Chuanyi Li 7 years ago
parent
commit
1c245280c7

+ 42 - 0
server/src/main/java/com/alibaba/otter/canal/server/netty/listener/ChannelFutureAggregator.java

@@ -0,0 +1,42 @@
+package com.alibaba.otter.canal.server.netty.listener;
+
+import com.alibaba.otter.canal.protocol.CanalPacket;
+import org.jboss.netty.channel.ChannelFuture;
+import org.jboss.netty.channel.ChannelFutureListener;
+
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * @author Chuanyi Li
+ */
+public class ChannelFutureAggregator implements ChannelFutureListener {
+
+    private String                 dest;
+
+    private CanalPacket.PacketType type;
+
+    private int                    amount;
+
+    private int                    errorCode;
+
+    public ChannelFutureAggregator(String dest, CanalPacket.PacketType type, int amount) {
+        this(dest, type, amount, 0);
+    }
+
+    public ChannelFutureAggregator(String dest, CanalPacket.PacketType type, int amount, int errorCode) {
+        this.dest = dest;
+        this.type = type;
+        this.amount = amount;
+        this.errorCode = errorCode;
+    }
+
+    @Override
+    public void operationComplete(ChannelFuture future) throws Exception {
+        if (future.isSuccess()) {
+            ConcurrentHashMap map = new ConcurrentHashMap();
+            map.putIfAbsent("", "");
+        } else {
+            Throwable t = future.getCause();
+        }
+    }
+}