You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pulsar.apache.org by gi...@git.apache.org on 2017/07/25 05:16:40 UTC

[GitHub] merlimat commented on a change in pull request #538: Make broker configurable to own non-persistent topic

merlimat commented on a change in pull request #538: Make broker configurable to own non-persistent topic
URL: https://github.com/apache/incubator-pulsar/pull/538#discussion_r129212256
 
 

 ##########
 File path: pulsar-broker/src/main/java/org/apache/pulsar/broker/service/nonpersistent/NonPersistentDispatcherSingleActiveConsumer.java
 ##########
 @@ -0,0 +1,206 @@
+/**
+ * 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.broker.service.nonpersistent;
+
+import static com.google.common.base.Preconditions.checkArgument;
+
+import java.util.List;
+import java.util.Objects;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
+import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
+
+import org.apache.bookkeeper.mledger.Entry;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.pulsar.broker.service.BrokerServiceException;
+import org.apache.pulsar.broker.service.BrokerServiceException.ConsumerBusyException;
+import org.apache.pulsar.broker.service.BrokerServiceException.ServerMetadataException;
+import org.apache.pulsar.broker.service.Consumer;
+import org.apache.pulsar.common.api.proto.PulsarApi.CommandSubscribe.SubType;
+import org.apache.pulsar.utils.CopyOnWriteArrayList;
+
+public final class NonPersistentDispatcherSingleActiveConsumer implements NonPersistentDispatcher {
+
+    private final NonPersistentTopic topic;
+    private static final AtomicReferenceFieldUpdater<NonPersistentDispatcherSingleActiveConsumer, Consumer> ACTIVE_CONSUMER_UPDATER = AtomicReferenceFieldUpdater
+            .newUpdater(NonPersistentDispatcherSingleActiveConsumer.class, Consumer.class, "activeConsumer");
+    private volatile Consumer activeConsumer = null;
+    private final CopyOnWriteArrayList<Consumer> consumers;
+    private CompletableFuture<Void> closeFuture = null;
+    private final int partitionIndex;
+
+    // This dispatcher supports both the Exclusive and Failover subscription types
+    private final SubType subscriptionType;
+
+    private static final int FALSE = 0;
+    private static final int TRUE = 1;
+    private static final AtomicIntegerFieldUpdater<NonPersistentDispatcherSingleActiveConsumer> IS_CLOSED_UPDATER = AtomicIntegerFieldUpdater
+            .newUpdater(NonPersistentDispatcherSingleActiveConsumer.class, "isClosed");
+    private volatile int isClosed = FALSE;
+
+    public NonPersistentDispatcherSingleActiveConsumer(SubType subscriptionType, int partitionIndex,
+            NonPersistentTopic topic) {
+        this.topic = topic;
+        this.consumers = new CopyOnWriteArrayList<>();
+        this.partitionIndex = partitionIndex;
+        this.subscriptionType = subscriptionType;
+        ACTIVE_CONSUMER_UPDATER.set(this, null);
+    }
+
+    private void pickAndScheduleActiveConsumer() {
 
 Review comment:
   Same here, most of these methods looks very similar to the "persistent" version. Share the same code if possible.
 
----------------------------------------------------------------
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