luchunliang commented on a change in pull request #2442:
URL: https://github.com/apache/incubator-inlong/pull/2442#discussion_r805469809



##########
File path: 
inlong-dataproxy/dataproxy-source/src/main/java/org/apache/inlong/dataproxy/dispatch/DispatchManager.java
##########
@@ -0,0 +1,160 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.inlong.dataproxy.dispatch;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map.Entry;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import org.apache.flume.Context;
+import org.apache.inlong.sdk.commons.protocol.ProxyEvent;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * DispatchManager
+ */
+public class DispatchManager {
+
+    public static final Logger LOG = 
LoggerFactory.getLogger(DispatchManager.class);
+    public static final String KEY_DISPATCH_TIMEOUT = "dispatchTimeout";
+    public static final String KEY_DISPATCH_MAX_PACKCOUNT = 
"dispatchMaxPackCount";
+    public static final String KEY_DISPATCH_MAX_PACKSIZE = 
"dispatchMaxPackSize";
+    public static final long DEFAULT_DISPATCH_TIMEOUT = 2000;
+    public static final long DEFAULT_DISPATCH_MAX_PACKCOUNT = 256;
+    public static final long DEFAULT_DISPATCH_MAX_PACKSIZE = 327680;
+    public static final long MINUTE_MS = 60L * 1000;
+
+    private LinkedBlockingQueue<DispatchProfile> dispatchQueue;
+    private final long dispatchTimeout;
+    private final long maxPackCount;
+    private final long maxPackSize;
+    private ConcurrentHashMap<String, DispatchProfile> profileCache = new 
ConcurrentHashMap<>();
+    //
+    private AtomicBoolean needOutputOvertimeData = new AtomicBoolean(false);
+
+    /**
+     * Constructor
+     * 
+     * @param context
+     * @param dispatchQueue
+     */
+    public DispatchManager(Context context, 
LinkedBlockingQueue<DispatchProfile> dispatchQueue) {
+        this.dispatchQueue = dispatchQueue;
+        this.dispatchTimeout = context.getLong(KEY_DISPATCH_TIMEOUT, 
DEFAULT_DISPATCH_TIMEOUT);
+        this.maxPackCount = context.getLong(KEY_DISPATCH_MAX_PACKCOUNT, 
DEFAULT_DISPATCH_MAX_PACKCOUNT);
+        this.maxPackSize = context.getLong(KEY_DISPATCH_MAX_PACKSIZE, 
DEFAULT_DISPATCH_MAX_PACKSIZE);
+    }
+
+    /**
+     * addEvent
+     * 
+     * @param event
+     */
+    public void addEvent(ProxyEvent event) {
+        if (needOutputOvertimeData.get()) {
+            this.outputOvertimeData();
+            this.needOutputOvertimeData.set(false);
+        }
+        // parse
+        String eventUid = event.getUid();
+        long dispatchTime = event.getMsgTime() - event.getMsgTime() % 
MINUTE_MS;
+        String dispatchKey = eventUid + "." + dispatchTime;
+        //

Review comment:
       add comment.

##########
File path: 
inlong-dataproxy/dataproxy-source/src/main/java/org/apache/inlong/dataproxy/dispatch/DispatchManager.java
##########
@@ -0,0 +1,160 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.inlong.dataproxy.dispatch;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map.Entry;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import org.apache.flume.Context;
+import org.apache.inlong.sdk.commons.protocol.ProxyEvent;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * DispatchManager
+ */
+public class DispatchManager {
+
+    public static final Logger LOG = 
LoggerFactory.getLogger(DispatchManager.class);
+    public static final String KEY_DISPATCH_TIMEOUT = "dispatchTimeout";
+    public static final String KEY_DISPATCH_MAX_PACKCOUNT = 
"dispatchMaxPackCount";
+    public static final String KEY_DISPATCH_MAX_PACKSIZE = 
"dispatchMaxPackSize";
+    public static final long DEFAULT_DISPATCH_TIMEOUT = 2000;
+    public static final long DEFAULT_DISPATCH_MAX_PACKCOUNT = 256;
+    public static final long DEFAULT_DISPATCH_MAX_PACKSIZE = 327680;
+    public static final long MINUTE_MS = 60L * 1000;
+
+    private LinkedBlockingQueue<DispatchProfile> dispatchQueue;
+    private final long dispatchTimeout;
+    private final long maxPackCount;
+    private final long maxPackSize;
+    private ConcurrentHashMap<String, DispatchProfile> profileCache = new 
ConcurrentHashMap<>();
+    //
+    private AtomicBoolean needOutputOvertimeData = new AtomicBoolean(false);
+
+    /**
+     * Constructor
+     * 
+     * @param context
+     * @param dispatchQueue
+     */
+    public DispatchManager(Context context, 
LinkedBlockingQueue<DispatchProfile> dispatchQueue) {
+        this.dispatchQueue = dispatchQueue;
+        this.dispatchTimeout = context.getLong(KEY_DISPATCH_TIMEOUT, 
DEFAULT_DISPATCH_TIMEOUT);
+        this.maxPackCount = context.getLong(KEY_DISPATCH_MAX_PACKCOUNT, 
DEFAULT_DISPATCH_MAX_PACKCOUNT);
+        this.maxPackSize = context.getLong(KEY_DISPATCH_MAX_PACKSIZE, 
DEFAULT_DISPATCH_MAX_PACKSIZE);
+    }
+
+    /**
+     * addEvent
+     * 
+     * @param event
+     */
+    public void addEvent(ProxyEvent event) {
+        if (needOutputOvertimeData.get()) {
+            this.outputOvertimeData();
+            this.needOutputOvertimeData.set(false);
+        }
+        // parse
+        String eventUid = event.getUid();
+        long dispatchTime = event.getMsgTime() - event.getMsgTime() % 
MINUTE_MS;
+        String dispatchKey = eventUid + "." + dispatchTime;
+        //
+        DispatchProfile dispatchProfile = this.profileCache.get(dispatchKey);
+        if (dispatchProfile == null) {
+            dispatchProfile = new DispatchProfile(eventUid, 
event.getInlongGroupId(), event.getInlongStreamId(),
+                    dispatchTime);
+            this.profileCache.put(dispatchKey, dispatchProfile);
+        }
+        //

Review comment:
       add comment.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to