Package org.apache.activemq.store.amq

Source Code of org.apache.activemq.store.amq.MessageBodyFormatter

/**
* 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.store.amq;

import javax.jms.JMSException;

import org.apache.activemq.command.ActiveMQBlobMessage;
import org.apache.activemq.command.ActiveMQBytesMessage;
import org.apache.activemq.command.ActiveMQMapMessage;
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.util.ByteSequence;

public class MessageBodyFormatter {
  final ActiveMQMessage message;
 
  public MessageBodyFormatter(ActiveMQMessage message) {
    this.message=message;
  }

  @Override
  public String toString() {
    try {
      switch (message.getDataStructureType()) {
      case ActiveMQMessage.DATA_STRUCTURE_TYPE:
        return "";
      case ActiveMQBlobMessage.DATA_STRUCTURE_TYPE:
        ActiveMQBlobMessage blob = (ActiveMQBlobMessage) message;
        return blob.getRemoteBlobUrl();
      case ActiveMQMapMessage.DATA_STRUCTURE_TYPE:
        ActiveMQMapMessage map = (ActiveMQMapMessage)message;
        return map.getContentMap().toString();     
      case ActiveMQTextMessage.DATA_STRUCTURE_TYPE:
        ActiveMQTextMessage text = (ActiveMQTextMessage)message;
        return text.getText();
      case ActiveMQBytesMessage.DATA_STRUCTURE_TYPE:
      case ActiveMQObjectMessage.DATA_STRUCTURE_TYPE:
      case ActiveMQStreamMessage.DATA_STRUCTURE_TYPE:
        ByteSequence data = message.getContent();
        return "binary payload {length="+data.getLength()+", compressed="+message.isCompressed()+"}";
      }
    } catch (JMSException e) {
    }
    return "";
  }
}
TOP

Related Classes of org.apache.activemq.store.amq.MessageBodyFormatter

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.