lhotari commented on code in PR #22861:
URL: https://github.com/apache/pulsar/pull/22861#discussion_r1634886201


##########
pulsar-client-api/src/main/java/org/apache/pulsar/client/api/MessageListenerExecutor.java:
##########
@@ -0,0 +1,48 @@
+/*
+ * 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.api;
+
+import java.io.Serializable;
+import java.util.concurrent.ExecutorService;
+
+/**
+ * Interface for providing an executor service to execute message listeners.
+ */
+public interface MessageListenerExecutor extends Serializable {
+
+    ExecutorService getExecutor();
+
+    /**
+     * Execute the runnable with the given shard key. The runnable will be 
executed by same thread of the same shard key.
+     *
+     * @param shardKey the shard key
+     * @param runnable the runnable to execute
+     */
+    void execute(byte[] shardKey, Runnable runnable);
+
+    /**
+     * Shutdown the provider and all thread resources of it.
+     */
+    void shutdownNow();
+
+    /**
+     * Check if the provider is shutdown.
+     */
+    boolean isShutdown();

Review Comment:
   Remove these. The implementer should handle implementation details and the 
lifecycle of the executor.



##########
pulsar-client-api/src/main/java/org/apache/pulsar/client/api/MessageListenerExecutor.java:
##########
@@ -0,0 +1,48 @@
+/*
+ * 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.api;
+
+import java.io.Serializable;
+import java.util.concurrent.ExecutorService;
+
+/**
+ * Interface for providing an executor service to execute message listeners.
+ */
+public interface MessageListenerExecutor extends Serializable {

Review Comment:
   Remove `Serializable`. I don't see a reason for that.
   ```suggestion
   public interface MessageListenerExecutor {
   ```



##########
pulsar-client-api/src/main/java/org/apache/pulsar/client/api/MessageListenerExecutor.java:
##########
@@ -0,0 +1,48 @@
+/*
+ * 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.api;
+
+import java.io.Serializable;
+import java.util.concurrent.ExecutorService;
+
+/**
+ * Interface for providing an executor service to execute message listeners.
+ */
+public interface MessageListenerExecutor extends Serializable {
+
+    ExecutorService getExecutor();
+
+    /**
+     * Execute the runnable with the given shard key. The runnable will be 
executed by same thread of the same shard key.
+     *
+     * @param shardKey the shard key
+     * @param runnable the runnable to execute
+     */
+    void execute(byte[] shardKey, Runnable runnable);

Review Comment:
   Instead of adding `shardKey`, simply add the `Message` parameter.
   This will allow the implementation to do whatever ordering is needed for the 
use case. For example, a priority queue could be used based on some value in 
the message headers etc.
   
   ```suggestion
       void execute(Message<?> message, Runnable runnable);
   ```



##########
pulsar-client-api/src/main/java/org/apache/pulsar/client/api/MessageListenerExecutor.java:
##########
@@ -0,0 +1,48 @@
+/*
+ * 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.api;
+
+import java.io.Serializable;
+import java.util.concurrent.ExecutorService;
+
+/**
+ * Interface for providing an executor service to execute message listeners.
+ */
+public interface MessageListenerExecutor extends Serializable {
+
+    ExecutorService getExecutor();

Review Comment:
   remove this. An implementer should handle implementation details such as the 
underlying executor / thread pool.



##########
pulsar-client/src/main/java/org/apache/pulsar/client/util/ExecutorProvider.java:
##########
@@ -83,6 +85,12 @@ public ExecutorService getExecutor() {
         return executors.get((currentThread.getAndIncrement() & 
Integer.MAX_VALUE) % numThreads).getKey();
     }
 
+    @Override
+    public void execute(byte[] shardKey, Runnable runnable) {
+        int keyHash = Murmur3_32Hash.getInstance().makeHash(shardKey);

Review Comment:
   This will be obsolete once `Message<?> message` is passed in the 
MessageListenerExecutor.



-- 
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: commits-unsubscr...@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to