pulsar-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] codelipenghui commented on a change in pull request #3118: UnAcked message tracker based on TimePartition
Date Tue, 11 Dec 2018 10:32:04 GMT
codelipenghui commented on a change in pull request #3118: UnAcked message tracker based on
TimePartition
URL: https://github.com/apache/pulsar/pull/3118#discussion_r240553641
 
 

 ##########
 File path: pulsar-client/src/main/java/org/apache/pulsar/client/impl/TimePartitionedUnAckedMessageTracker.java
 ##########
 @@ -0,0 +1,190 @@
+/**
+ * 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.pulsar.client.impl;
+
+import io.netty.util.Timeout;
+import io.netty.util.TimerTask;
+import org.apache.pulsar.client.api.MessageId;
+import org.apache.pulsar.common.util.collections.ConcurrentOpenHashSet;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.Closeable;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.Set;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
+
+public class TimePartitionedUnAckedMessageTracker extends UnAckedMessageTracker implements
Closeable {
+
+    private static final Logger log = LoggerFactory.getLogger(TimePartitionedUnAckedMessageTracker.class);
+
+    private LinkedList<ConcurrentOpenHashSet<MessageId>> timePartitions;
+
+    protected final long ackTimeoutMillis;
+    protected final long tickDurationInMs;
+
+    protected final ConsumerBase<?> consumerBase;
+
+    protected final Lock readLock;
+    protected final Lock writeLock;
+
+    private Timeout timeout;
+
+    public TimePartitionedUnAckedMessageTracker(PulsarClientImpl client, ConsumerBase<?>
consumerBase, long ackTimeoutMillis, long tickDurationInMs) {
+
+        this.consumerBase = consumerBase;
+        if (ackTimeoutMillis < tickDurationInMs) {
+            this.ackTimeoutMillis = tickDurationInMs;
+        } else {
+            this.ackTimeoutMillis = ackTimeoutMillis;
+        }
+        this.tickDurationInMs = tickDurationInMs;
+        ReentrantReadWriteLock readWriteLock = new ReentrantReadWriteLock();
+        this.readLock = readWriteLock.readLock();
+        this.writeLock = readWriteLock.writeLock();
+        this.timePartitions = new LinkedList<>();
+
+        int blankPartitions = (int)Math.ceil((double)ackTimeoutMillis / tickDurationInMs);
+        for (int i = 0; i < blankPartitions; i++) {
+            timePartitions.add(new ConcurrentOpenHashSet<>());
+        }
+
+        timeout = client.timer().newTimeout(new TimerTask() {
 
 Review comment:
   Already use client.timer(), do you mean this?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

Mime
View raw message