Github user michaelandrepearce commented on a diff in the pull request:

    https://github.com/apache/activemq-artemis/pull/1793#discussion_r165768314
  
    --- Diff: 
artemis-protocols/artemis-openwire-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/openwire/OpenWireCoreConverter.java
 ---
    @@ -0,0 +1,572 @@
    +/*
    + * 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.core.protocol.openwire;
    +
    +import java.io.ByteArrayOutputStream;
    +import java.io.DataInputStream;
    +import java.io.DataOutputStream;
    +import java.io.IOException;
    +import java.io.InputStream;
    +import java.io.OutputStream;
    +import java.util.Arrays;
    +import java.util.Map;
    +import java.util.Set;
    +import java.util.Map.Entry;
    +import java.util.zip.Deflater;
    +import java.util.zip.DeflaterOutputStream;
    +import java.util.zip.Inflater;
    +import java.util.zip.InflaterInputStream;
    +import java.util.zip.InflaterOutputStream;
    +
    +import org.apache.activemq.artemis.api.core.ActiveMQBuffer;
    +import org.apache.activemq.artemis.api.core.FilterConstants;
    +import org.apache.activemq.artemis.api.core.ICoreMessage;
    +import org.apache.activemq.artemis.api.core.SimpleString;
    +import org.apache.activemq.artemis.core.message.impl.CoreMessage;
    +import 
org.apache.activemq.artemis.core.message.impl.CoreMessageObjectPools;
    +import org.apache.activemq.artemis.reader.MessageUtil;
    +import org.apache.activemq.artemis.utils.DataConstants;
    +import org.apache.activemq.artemis.utils.collections.TypedProperties;
    +import org.apache.activemq.command.CommandTypes;
    +import org.apache.activemq.util.ByteArrayInputStream;
    +import org.apache.activemq.util.ByteSequence;
    +import org.apache.activemq.util.ByteSequenceData;
    +import org.apache.activemq.util.MarshallingSupport;
    +import org.fusesource.hawtbuf.UTF8Buffer;
    +
    +public class OpenWireCoreConverter {
    +   public static final SimpleString JMS_GROUPSEQ = new 
SimpleString("JMSXGroupSequence");
    +   public static final SimpleString JMS_XGROUPSEQ = new 
SimpleString("JMSXGroupSeq");
    +   public static final SimpleString JMS_GROUPID = new 
SimpleString("JMSXGroupID");
    +   private static final SimpleString AMQP_REPLYTOGROUPID = new 
SimpleString("JMS_AMQP_ReplyToGroupID");
    +   public static final SimpleString JMS_CONTENT_TYPE = new 
SimpleString("JMS_AMQP_ContentType");
    +   private static final SimpleString AMQP_CONTETTYPE = new 
SimpleString("JMS_AMQP_CONTENT_TYPE");
    +
    +   public static ICoreMessage toCore(final OpenWireMessage 
openwireMessage, final CoreMessageObjectPools coreMessageObjectPools)
    +         throws Exception {
    +      CoreMessage coreMessage = new CoreMessage(-1, 
openwireMessage.getMessageSize(), coreMessageObjectPools);
    +      final SimpleString type = 
openwireMessage.getSimpleStringProperty(OpenWireMessageConverter.JMS_TYPE_PROPERTY);
    +      if (type != null) {
    +         
coreMessage.putStringProperty(OpenWireMessageConverter.JMS_TYPE_PROPERTY, type);
    +      }
    +      coreMessage.setDurable(openwireMessage.isDurable());
    +      coreMessage.setExpiration(openwireMessage.getExpiration());
    +      coreMessage.setPriority(openwireMessage.getPriority());
    +      coreMessage.setTimestamp(openwireMessage.getTimestamp());
    +      final ActiveMQBuffer openWireMessageBuffer = 
openwireMessage.getReadOnlyBodyBuffer();
    +      final boolean isCompressed = 
openwireMessage.getBooleanProperty(OpenWireMessageConverter.AMQ_MSG_COMPRESSED);
    +      final byte coreType = openwireMessage.getType();
    +      coreMessage.setType(coreType);
    +      openWireMessageBuffer.resetReaderIndex();
    +      final byte[] bytes;
    +      bytes = readContentFromBody(openWireMessageBuffer, coreType, 
isCompressed);
    +      if (bytes != null) {
    +         ByteSequence content = new ByteSequence(bytes);
    +         ActiveMQBuffer coreMessageBuffer = coreMessage.getBodyBuffer();
    +         writeContentIntoBody(coreMessageBuffer, content, coreType, 
isCompressed);
    +      }
    +      coreMessage.putObjectProperty(FilterConstants.NATIVE_MESSAGE_ID,
    +            
openwireMessage.getObjectProperty(FilterConstants.NATIVE_MESSAGE_ID));
    +      coreMessage.setMessageID(openwireMessage.getMessageID());
    +      final String corrId = 
openwireMessage.getStringProperty(OpenWireMessageConverter.JMS_CORRELATION_ID_PROPERTY);
    +      if (corrId != null) {
    +         
coreMessage.putStringProperty(OpenWireMessageConverter.JMS_CORRELATION_ID_PROPERTY,
 corrId);
    +      }
    +      final String groupId = 
openwireMessage.getStringProperty(org.apache.activemq.artemis.api.core.Message.HDR_GROUP_ID);
    +      if (groupId != null) {
    +         
coreMessage.putStringProperty(org.apache.activemq.artemis.api.core.Message.HDR_GROUP_ID,
    +               new SimpleString(groupId));
    --- End diff --
    
    +1 good suggestion, i think maybe we can do this optimisation later though, 
this is a large change, and improves things anyhow. e.g. why dont we get this 
PR in, and then break loose on perf later?


---

Reply via email to