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



##########
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:
       No bud this is a bug, because that listeners calls are not supposed to 
run in random order, but in the right sequence.
   The leaky act in the example shouldn't call again set auto-read false (is it 
already false)  and most importantly it shouldn't call setauto read false and 
true in parallel (while the current implementation allows it)

##########
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:
       No bud this is a bug, because that listeners calls are not supposed to 
run in random order, but in the right sequence.
   The leaky act in the example shouldn't call again set auto-read false (is it 
already false)  and most importantly it shouldn't allows the 2 threads to call 
set auto read false and true in parallel.
   
   The leaky act should stay there unless some new one arrive adding a new 
flush after the previous one has been completed

##########
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:
       Ok, but I don't understand why you don't consider it a bug: listeners 
must not be called concurrently right? The compare and set is there to prevent 
it

##########
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:
       Ok, but I don't understand why you don't consider it a bug: listeners 
must not be called concurrently right? The compare and set is there to prevent 
it.
   I can send a separate or to fix it but is a one line change here so maybe it 
worth to already address it now...
   If not, I will send a pr later 

##########
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:
       Ok, but I don't understand why you don't consider it a bug: listeners 
must not be called concurrently right? The compare and set is there to prevent 
it.
   I can send a separate pr to fix it but is a one line change here so maybe it 
worth to already address it now...
   If not, I will send a pr later 

##########
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 would still fix your issue: run your existing tests and if it 
pass it means that is still working as you expect, if not, feel free to merge 
it as is now and I'll find out later what can be wrong (if any).

##########
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 you expect, 
if not, feel free to merge it as is now and I'll find out later what can be 
wrong (if any).

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