XATransactionInfoWriter xref

View Javadoc

    1   /***
    2    *
    3    * Copyright 2004 Protique Ltd
    4    *
    5    * Licensed under the Apache License, Version 2.0 (the "License");
    6    * you may not use this file except in compliance with the License.
    7    * You may obtain a copy of the License at
    8    *
    9    * http://www.apache.org/licenses/LICENSE-2.0
    10   *
    11   * Unless required by applicable law or agreed to in writing, software
    12   * distributed under the License is distributed on an "AS IS" BASIS,
    13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14   * See the License for the specific language governing permissions and
    15   * limitations under the License.
    16   *
    17   **/
    18
    19  package org.codehaus.activemq.message;
    20
    21  import java.io.DataOutput;
    22  import java.io.IOException;
    23
    24  /***
    25   * Writes a TransactionInfo object to a Stream
    26   */
    27
    28  public class XATransactionInfoWriter extends AbstractPacketWriter {
    29
    30      /***
    31       * Return the type of Packet
    32       *
    33       * @return integer representation of the type of Packet
    34       */
    35
    36      public int getPacketType() {
    37          return Packet.XA_TRANSACTION_INFO;
    38      }
    39
    40      /***
    41       * Write a Packet instance to data output stream
    42       *
    43       * @param packet  the instance to be seralized
    44       * @param dataOut the output stream
    45       * @throws java.io.IOException thrown if an error occurs
    46       */
    47
    48      public void writePacket(Packet packet, DataOutput dataOut) throws IOException {
    49          super.writePacket(packet, dataOut);
    50          XATransactionInfo info = (XATransactionInfo) packet;
    51          dataOut.writeByte(info.getType());
    52          switch (info.getType()) {
    53              case TransactionType.START:
    54              case TransactionType.PRE_COMMIT:
    55              case TransactionType.COMMIT:
    56              case TransactionType.RECOVER:
    57              case TransactionType.ROLLBACK:
    58              case TransactionType.END:
    59              case TransactionType.FORGET:
    60              case TransactionType.JOIN:
    61              case TransactionType.COMMIT_ONE_PHASE:
    62                  assert info.getXid() != null;
    63                  info.getXid().write(dataOut);
    64                  break;
    65              case TransactionType.SET_TX_TIMEOUT:
    66                  dataOut.writeInt(info.getTransactionTimeout());
    67                  break;
    68              case TransactionType.XA_RECOVER:
    69                  //recover should take a flag.
    70                  break;
    71              case TransactionType.GET_TX_TIMEOUT:
    72              case TransactionType.GET_RM_ID:
    73                  break;
    74              default:
    75                  throw new IllegalArgumentException("Invalid type code: " + info.getType());
    76          }
    77      }
    78
    79  }