From baef8f8ec20ed3057895f6ec1e02ca6ea75a33a1 Mon Sep 17 00:00:00 2001 From: Timothy Bish Date: Thu, 6 Oct 2016 14:19:54 -0400 Subject: [PATCH] https://issues.apache.org/jira/browse/AMQ-6444 Remove some unneeded instance of checks and used cached values where possible. --- .../JMSMappingOutboundTransformer.java | 30 +++++++++---------- .../JMSTransformationSpeedComparisonTest.java | 2 +- 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/activemq-amqp/src/main/java/org/apache/activemq/transport/amqp/message/JMSMappingOutboundTransformer.java b/activemq-amqp/src/main/java/org/apache/activemq/transport/amqp/message/JMSMappingOutboundTransformer.java index 69039eacf4..5b220994fa 100644 --- a/activemq-amqp/src/main/java/org/apache/activemq/transport/amqp/message/JMSMappingOutboundTransformer.java +++ b/activemq-amqp/src/main/java/org/apache/activemq/transport/amqp/message/JMSMappingOutboundTransformer.java @@ -54,15 +54,10 @@ import java.util.Date; import java.util.HashMap; import java.util.Map; -import javax.jms.Destination; import javax.jms.JMSException; import javax.jms.Message; import javax.jms.MessageEOFException; -import javax.jms.Queue; -import javax.jms.TemporaryQueue; -import javax.jms.TemporaryTopic; import javax.jms.TextMessage; -import javax.jms.Topic; import org.apache.activemq.command.ActiveMQBytesMessage; import org.apache.activemq.command.ActiveMQDestination; @@ -71,6 +66,7 @@ import org.apache.activemq.command.ActiveMQMessage; import org.apache.activemq.command.ActiveMQObjectMessage; import org.apache.activemq.command.ActiveMQStreamMessage; import org.apache.activemq.command.ActiveMQTextMessage; +import org.apache.activemq.command.CommandTypes; import org.apache.activemq.command.MessageId; import org.apache.activemq.transport.amqp.AmqpProtocolException; import org.apache.activemq.util.JMSExceptionSupport; @@ -140,7 +136,7 @@ public class JMSMappingOutboundTransformer implements OutboundTransformer { if (header == null) { header = new Header(); } - header.setPriority(new UnsignedByte(priority)); + header.setPriority(UnsignedByte.valueOf(priority)); } String type = message.getType(); if (type != null) { @@ -376,7 +372,9 @@ public class JMSMappingOutboundTransformer implements OutboundTransformer { // Ignore and stick with UNKNOWN } - if (message instanceof ActiveMQBytesMessage) { + int messageType = message.getDataStructureType(); + + if (messageType == CommandTypes.ACTIVEMQ_BYTES_MESSAGE) { Binary payload = getBinaryFromMessageBody((ActiveMQBytesMessage) message); if (payload == null) { @@ -395,7 +393,7 @@ public class JMSMappingOutboundTransformer implements OutboundTransformer { body = new Data(payload); break; } - } else if (message instanceof ActiveMQTextMessage) { + } else if (messageType == CommandTypes.ACTIVEMQ_TEXT_MESSAGE) { switch (orignalEncoding) { case AMQP_NULL: break; @@ -408,9 +406,9 @@ public class JMSMappingOutboundTransformer implements OutboundTransformer { body = new AmqpValue(((TextMessage) message).getText()); break; } - } else if (message instanceof ActiveMQMapMessage) { + } else if (messageType == CommandTypes.ACTIVEMQ_MAP_MESSAGE) { body = new AmqpValue(getMapFromMessageBody((ActiveMQMapMessage) message)); - } else if (message instanceof ActiveMQStreamMessage) { + } else if (messageType == CommandTypes.ACTIVEMQ_STREAM_MESSAGE) { ArrayList list = new ArrayList(); final ActiveMQStreamMessage m = (ActiveMQStreamMessage) message; try { @@ -430,7 +428,7 @@ public class JMSMappingOutboundTransformer implements OutboundTransformer { body = new AmqpValue(list); break; } - } else if (message instanceof ActiveMQObjectMessage) { + } else if (messageType == CommandTypes.ACTIVEMQ_OBJECT_MESSAGE) { Binary payload = getBinaryFromMessageBody((ActiveMQObjectMessage) message); if (payload == null) { @@ -461,15 +459,15 @@ public class JMSMappingOutboundTransformer implements OutboundTransformer { return body; } - private static byte destinationType(Destination destination) { - if (destination instanceof Queue) { - if (destination instanceof TemporaryQueue) { + private static byte destinationType(ActiveMQDestination destination) { + if (destination.isQueue()) { + if (destination.isTemporary()) { return TEMP_QUEUE_TYPE; } else { return QUEUE_TYPE; } - } else if (destination instanceof Topic) { - if (destination instanceof TemporaryTopic) { + } else if (destination.isTopic()) { + if (destination.isTemporary()) { return TEMP_TOPIC_TYPE; } else { return TOPIC_TYPE; diff --git a/activemq-amqp/src/test/java/org/apache/activemq/transport/amqp/message/JMSTransformationSpeedComparisonTest.java b/activemq-amqp/src/test/java/org/apache/activemq/transport/amqp/message/JMSTransformationSpeedComparisonTest.java index cd93af7af0..836ec36c0e 100644 --- a/activemq-amqp/src/test/java/org/apache/activemq/transport/amqp/message/JMSTransformationSpeedComparisonTest.java +++ b/activemq-amqp/src/test/java/org/apache/activemq/transport/amqp/message/JMSTransformationSpeedComparisonTest.java @@ -60,7 +60,7 @@ public class JMSTransformationSpeedComparisonTest { private final String transformer; - private final int WARM_CYCLES = 1000; + private final int WARM_CYCLES = 10000; private final int PROFILE_CYCLES = 1000000; public JMSTransformationSpeedComparisonTest(String transformer) {