Remove some unneeded instance of checks and used cached values where
possible.
This commit is contained in:
Timothy Bish 2016-10-06 14:19:54 -04:00
parent b6759b33dc
commit baef8f8ec2
2 changed files with 15 additions and 17 deletions

View File

@ -54,15 +54,10 @@ import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import javax.jms.Destination;
import javax.jms.JMSException; import javax.jms.JMSException;
import javax.jms.Message; import javax.jms.Message;
import javax.jms.MessageEOFException; import javax.jms.MessageEOFException;
import javax.jms.Queue;
import javax.jms.TemporaryQueue;
import javax.jms.TemporaryTopic;
import javax.jms.TextMessage; import javax.jms.TextMessage;
import javax.jms.Topic;
import org.apache.activemq.command.ActiveMQBytesMessage; import org.apache.activemq.command.ActiveMQBytesMessage;
import org.apache.activemq.command.ActiveMQDestination; 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.ActiveMQObjectMessage;
import org.apache.activemq.command.ActiveMQStreamMessage; import org.apache.activemq.command.ActiveMQStreamMessage;
import org.apache.activemq.command.ActiveMQTextMessage; import org.apache.activemq.command.ActiveMQTextMessage;
import org.apache.activemq.command.CommandTypes;
import org.apache.activemq.command.MessageId; import org.apache.activemq.command.MessageId;
import org.apache.activemq.transport.amqp.AmqpProtocolException; import org.apache.activemq.transport.amqp.AmqpProtocolException;
import org.apache.activemq.util.JMSExceptionSupport; import org.apache.activemq.util.JMSExceptionSupport;
@ -140,7 +136,7 @@ public class JMSMappingOutboundTransformer implements OutboundTransformer {
if (header == null) { if (header == null) {
header = new Header(); header = new Header();
} }
header.setPriority(new UnsignedByte(priority)); header.setPriority(UnsignedByte.valueOf(priority));
} }
String type = message.getType(); String type = message.getType();
if (type != null) { if (type != null) {
@ -376,7 +372,9 @@ public class JMSMappingOutboundTransformer implements OutboundTransformer {
// Ignore and stick with UNKNOWN // Ignore and stick with UNKNOWN
} }
if (message instanceof ActiveMQBytesMessage) { int messageType = message.getDataStructureType();
if (messageType == CommandTypes.ACTIVEMQ_BYTES_MESSAGE) {
Binary payload = getBinaryFromMessageBody((ActiveMQBytesMessage) message); Binary payload = getBinaryFromMessageBody((ActiveMQBytesMessage) message);
if (payload == null) { if (payload == null) {
@ -395,7 +393,7 @@ public class JMSMappingOutboundTransformer implements OutboundTransformer {
body = new Data(payload); body = new Data(payload);
break; break;
} }
} else if (message instanceof ActiveMQTextMessage) { } else if (messageType == CommandTypes.ACTIVEMQ_TEXT_MESSAGE) {
switch (orignalEncoding) { switch (orignalEncoding) {
case AMQP_NULL: case AMQP_NULL:
break; break;
@ -408,9 +406,9 @@ public class JMSMappingOutboundTransformer implements OutboundTransformer {
body = new AmqpValue(((TextMessage) message).getText()); body = new AmqpValue(((TextMessage) message).getText());
break; break;
} }
} else if (message instanceof ActiveMQMapMessage) { } else if (messageType == CommandTypes.ACTIVEMQ_MAP_MESSAGE) {
body = new AmqpValue(getMapFromMessageBody((ActiveMQMapMessage) message)); body = new AmqpValue(getMapFromMessageBody((ActiveMQMapMessage) message));
} else if (message instanceof ActiveMQStreamMessage) { } else if (messageType == CommandTypes.ACTIVEMQ_STREAM_MESSAGE) {
ArrayList<Object> list = new ArrayList<Object>(); ArrayList<Object> list = new ArrayList<Object>();
final ActiveMQStreamMessage m = (ActiveMQStreamMessage) message; final ActiveMQStreamMessage m = (ActiveMQStreamMessage) message;
try { try {
@ -430,7 +428,7 @@ public class JMSMappingOutboundTransformer implements OutboundTransformer {
body = new AmqpValue(list); body = new AmqpValue(list);
break; break;
} }
} else if (message instanceof ActiveMQObjectMessage) { } else if (messageType == CommandTypes.ACTIVEMQ_OBJECT_MESSAGE) {
Binary payload = getBinaryFromMessageBody((ActiveMQObjectMessage) message); Binary payload = getBinaryFromMessageBody((ActiveMQObjectMessage) message);
if (payload == null) { if (payload == null) {
@ -461,15 +459,15 @@ public class JMSMappingOutboundTransformer implements OutboundTransformer {
return body; return body;
} }
private static byte destinationType(Destination destination) { private static byte destinationType(ActiveMQDestination destination) {
if (destination instanceof Queue) { if (destination.isQueue()) {
if (destination instanceof TemporaryQueue) { if (destination.isTemporary()) {
return TEMP_QUEUE_TYPE; return TEMP_QUEUE_TYPE;
} else { } else {
return QUEUE_TYPE; return QUEUE_TYPE;
} }
} else if (destination instanceof Topic) { } else if (destination.isTopic()) {
if (destination instanceof TemporaryTopic) { if (destination.isTemporary()) {
return TEMP_TOPIC_TYPE; return TEMP_TOPIC_TYPE;
} else { } else {
return TOPIC_TYPE; return TOPIC_TYPE;

View File

@ -60,7 +60,7 @@ public class JMSTransformationSpeedComparisonTest {
private final String transformer; private final String transformer;
private final int WARM_CYCLES = 1000; private final int WARM_CYCLES = 10000;
private final int PROFILE_CYCLES = 1000000; private final int PROFILE_CYCLES = 1000000;
public JMSTransformationSpeedComparisonTest(String transformer) { public JMSTransformationSpeedComparisonTest(String transformer) {