You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by cl...@apache.org on 2017/08/23 02:14:33 UTC
[1/2] activemq-artemis git commit: This closes #1477
Repository: activemq-artemis
Updated Branches:
refs/heads/master ce01faeac -> a9606c9b0
This closes #1477
Project: http://git-wip-us.apache.org/repos/asf/activemq-artemis/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq-artemis/commit/a9606c9b
Tree: http://git-wip-us.apache.org/repos/asf/activemq-artemis/tree/a9606c9b
Diff: http://git-wip-us.apache.org/repos/asf/activemq-artemis/diff/a9606c9b
Branch: refs/heads/master
Commit: a9606c9b0e3b543fffe3d845a0efe6fc4591811c
Parents: ce01fae e088144
Author: Clebert Suconic <cl...@apache.org>
Authored: Tue Aug 22 22:12:26 2017 -0400
Committer: Clebert Suconic <cl...@apache.org>
Committed: Tue Aug 22 22:12:26 2017 -0400
----------------------------------------------------------------------
.../core/ServerSessionPacketHandler.java | 30 ++++++++++++++++----
1 file changed, 25 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
[2/2] activemq-artemis git commit: ARTEMIS-1356 Avoid allocations and
atomic operations to recognize handler's thread
Posted by cl...@apache.org.
ARTEMIS-1356 Avoid allocations and atomic operations to recognize handler's thread
Project: http://git-wip-us.apache.org/repos/asf/activemq-artemis/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq-artemis/commit/e0881448
Tree: http://git-wip-us.apache.org/repos/asf/activemq-artemis/tree/e0881448
Diff: http://git-wip-us.apache.org/repos/asf/activemq-artemis/diff/e0881448
Branch: refs/heads/master
Commit: e0881448c13ada1972f41685d2a6716681b7d192
Parents: ce01fae
Author: Francesco Nigro <ni...@gmail.com>
Authored: Mon Aug 21 15:03:17 2017 +0200
Committer: Clebert Suconic <cl...@apache.org>
Committed: Tue Aug 22 22:12:26 2017 -0400
----------------------------------------------------------------------
.../core/ServerSessionPacketHandler.java | 30 ++++++++++++++++----
1 file changed, 25 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/e0881448/artemis-server/src/main/java/org/apache/activemq/artemis/core/protocol/core/ServerSessionPacketHandler.java
----------------------------------------------------------------------
diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/protocol/core/ServerSessionPacketHandler.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/protocol/core/ServerSessionPacketHandler.java
index 7b45c9f..58518a9 100644
--- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/protocol/core/ServerSessionPacketHandler.java
+++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/protocol/core/ServerSessionPacketHandler.java
@@ -19,7 +19,6 @@ package org.apache.activemq.artemis.core.protocol.core;
import javax.transaction.xa.XAResource;
import javax.transaction.xa.Xid;
import java.util.List;
-import java.util.concurrent.atomic.AtomicBoolean;
import org.apache.activemq.artemis.api.core.ActiveMQException;
import org.apache.activemq.artemis.api.core.ActiveMQExceptionType;
@@ -159,7 +158,11 @@ public class ServerSessionPacketHandler implements ChannelHandler {
private final boolean direct;
- private static final ThreadLocal<AtomicBoolean> inHandler = ThreadLocal.withInitial(AtomicBoolean::new);
+ //marker instance used to recognize if a thread is performing a packet handling
+ private static final Object DUMMY = Boolean.TRUE;
+
+ //a thread that has its thread-local map populated with DUMMY is performing a packet handling
+ private static final ThreadLocal<Object> inHandler = new ThreadLocal<>();
public ServerSessionPacketHandler(final ActiveMQServer server,
final CoreProtocolManager manager,
@@ -227,8 +230,25 @@ public class ServerSessionPacketHandler implements ChannelHandler {
ActiveMQServerLogger.LOGGER.clearingUpSession(session.getName());
}
+ private static void onStartMessagePacketHandler() {
+ assert inHandler.get() != null : "recursion on packet handling is not supported";
+ inHandler.set(DUMMY);
+ }
+
+ private static boolean inHandler() {
+ final Object dummy = inHandler.get();
+ //sanity check: can't exist a thread using a marker different from DUMMY
+ assert ((dummy != null && dummy == DUMMY) || dummy == null) : "wrong marker";
+ return dummy != null;
+ }
+
+ private static void onExitMessagePacketHandler() {
+ assert inHandler.get() == null : "marker not set";
+ inHandler.set(null);
+ }
+
public void flushExecutor() {
- if (!inHandler.get().get()) {
+ if (!inHandler()) {
packetActor.flush();
callExecutor.flush();
}
@@ -261,7 +281,7 @@ public class ServerSessionPacketHandler implements ChannelHandler {
if (logger.isTraceEnabled()) {
logger.trace("ServerSessionPacketHandler::handlePacket," + packet);
}
- inHandler.get().set(true);
+ onStartMessagePacketHandler();
try {
final byte type = packet.getType();
switch (type) {
@@ -287,7 +307,7 @@ public class ServerSessionPacketHandler implements ChannelHandler {
break;
}
} finally {
- inHandler.get().set(false);
+ onExitMessagePacketHandler();
}
}