Package org.hornetq.jms.transaction

Source Code of org.hornetq.jms.transaction.JMSTransactionDetail

/*
* Copyright 2010 Red Hat, Inc.
* Red Hat 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.hornetq.jms.transaction;

import java.io.ByteArrayInputStream;
import java.io.ObjectInputStream;
import java.io.Serializable;
import java.util.Map;

import javax.transaction.xa.Xid;

import org.hornetq.api.core.HornetQBuffer;
import org.hornetq.core.server.ServerMessage;
import org.hornetq.core.transaction.Transaction;
import org.hornetq.core.transaction.TransactionDetail;
import org.hornetq.jms.client.HornetQBytesMessage;
import org.hornetq.jms.client.HornetQMapMessage;
import org.hornetq.jms.client.HornetQMessage;
import org.hornetq.jms.client.HornetQObjectMessage;
import org.hornetq.jms.client.HornetQStreamMessage;
import org.hornetq.jms.client.HornetQTextMessage;
import org.hornetq.utils.TypedProperties;

/**
* A JMSTransactionDetail
*
* @author <a href="tm.igarashi@gmail.com">Tomohisa Igarashi</a>
*
*
*/
public class JMSTransactionDetail extends TransactionDetail
{
   public JMSTransactionDetail(Xid xid, Transaction tx, Long creation) throws Exception
   {
      super(xid,tx,creation);
   }
  
   @Override
   public String decodeMessageType(ServerMessage msg)
   {
      int type = msg.getType();
      switch (type)
      {
         case HornetQMessage.TYPE: // 0
            return "Default";
         case HornetQObjectMessage.TYPE: // 2
            return "ObjectMessage";
         case HornetQTextMessage.TYPE: // 3
            return "TextMessage";
         case HornetQBytesMessage.TYPE: // 4
            return "ByteMessage";
         case HornetQMapMessage.TYPE: // 5
            return "MapMessage";
         case HornetQStreamMessage.TYPE: // 6
            return "StreamMessage";
         default:
            return "(Unknown Type)";
      }
   }

   @Override
   public String decodeMessagePayload(ServerMessage msg)
   {
      int type = msg.getType();
      HornetQBuffer bodyBuffer = msg.getBodyBuffer();
     
      try
      {
         switch (type)
         {
            case HornetQObjectMessage.TYPE: // 2
               int len = bodyBuffer.readInt();
               byte[] data = new byte[len];
               bodyBuffer.readBytes(data);
               ByteArrayInputStream bais = new ByteArrayInputStream(data);
               ObjectInputStream ois = new org.hornetq.utils.ObjectInputStreamWithClassLoader(bais);
               Serializable object = (Serializable)ois.readObject();
               return object.toString();

            case HornetQTextMessage.TYPE: // 3
               return bodyBuffer.readNullableSimpleString().toString();

            case HornetQMapMessage.TYPE: // 5
               TypedProperties pmap = new TypedProperties();
               pmap.decode(msg.getBodyBuffer());
               return pmap.toString();
            default:
               return "(Not Available)";
         }
      }
      catch(Throwable t)
      {
         return "(Not Available)";
      }
   }

   @Override
   public Map<String, Object> decodeMessageProperties(ServerMessage msg)
   {
      try
      {
         return HornetQMessage.coreMaptoJMSMap(msg.toMap());
      }
      catch (Throwable t)
      {
         return null;
      }
   }
}
TOP

Related Classes of org.hornetq.jms.transaction.JMSTransactionDetail

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.