franz1981 commented on a change in pull request #3876:
URL: https://github.com/apache/activemq-artemis/pull/3876#discussion_r766956766



##########
File path: 
artemis-commons/src/main/java/org/apache/activemq/artemis/utils/actors/BoundActor.java
##########
@@ -0,0 +1,79 @@
+/**
+ * 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.activemq.artemis.utils.actors;
+
+import java.util.concurrent.Executor;
+import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
+import java.util.function.ToIntFunction;
+
+public class BoundActor<T> extends ProcessorBase<Object> {
+
+   private static final AtomicIntegerFieldUpdater<BoundActor> SIZE_UPDATER = 
AtomicIntegerFieldUpdater.newUpdater(BoundActor.class, "size");
+   private volatile int size = 0;
+
+   private static final AtomicIntegerFieldUpdater<BoundActor> 
SCHEDULED_FUSH_UPDATER = AtomicIntegerFieldUpdater.newUpdater(BoundActor.class, 
"scheduledFlush");
+   private volatile int scheduledFlush = 0;
+
+   private static final Object FLUSH = new Object();
+
+
+   final int maxSize;
+   final ToIntFunction<T> sizeGetter;
+   ActorListener<T> listener;
+
+   Runnable overLimit;
+   Runnable clearLimit;
+
+   public BoundActor(Executor parent, ActorListener<T> listener, int maxSize, 
ToIntFunction<T> sizeGetter, Runnable overLimit, Runnable clearLimit) {
+      super(parent);
+      this.listener = listener;
+      this.maxSize = maxSize;
+      this.sizeGetter = sizeGetter;
+      this.overLimit = overLimit;
+      this.clearLimit = clearLimit;
+   }
+
+   @Override
+   protected final void doTask(Object task) {
+      if (task == FLUSH) {
+         this.scheduledFlush = 0;

Review comment:
       I know but given that is a racy behaviour it won't happen easily, like 
any concurrent bugs, but the execution I shown is valid and can still happen so 
worth to fix it.
   At worst it should fix your issue in this form too: run your existing new 
openwire tests and if they pass it means that is still working as expected, if 
not, feel free to merge it as is now and I'll find out later what can be wrong 
(if any).




-- 
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