001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.mq;
023:
024: import java.io.Externalizable;
025: import java.io.IOException;
026: import java.io.ObjectInput;
027: import java.io.ObjectOutput;
028: import java.io.Serializable;
029:
030: import javax.transaction.xa.Xid;
031:
032: /**
033: * This class contians all the data needed to perform a JMS transaction
034: *
035: * @author Hiram Chirino (Cojonudo14@hotmail.com)
036: * @author David Maplesden (David.Maplesden@orion.co.nz)
037: * @author <a href="mailto:adrian@jboss.org">Adrian Brock</a>
038: * @author Daniel Bloomfield Ramagem (daniel.ramagem@gmail.com)
039: * @version $Revision: 57198 $
040: */
041: public class TransactionRequest implements Externalizable {
042: /** The serialVersionUID */
043: static final long serialVersionUID = 5368191944552650149L;
044:
045: /** One phase Commit request */
046: public final static byte ONE_PHASE_COMMIT_REQUEST = 0;
047: /** Two phase Prepare phase */
048: public final static byte TWO_PHASE_COMMIT_PREPARE_REQUEST = 1;
049: /** Two phase Commit phase */
050: public final static byte TWO_PHASE_COMMIT_COMMIT_REQUEST = 2;
051: /** Rollback request */
052: public final static byte TWO_PHASE_COMMIT_ROLLBACK_REQUEST = 3;
053:
054: /** Request type */
055: public byte requestType = ONE_PHASE_COMMIT_REQUEST;
056:
057: /** For 2 phase commit, this identifies the transaction. */
058: public Object xid;
059:
060: /** messages sent in the transaction */
061: public SpyMessage[] messages;
062:
063: /** messages acknowleged in the transaction */
064: public AcknowledgementRequest[] acks;
065:
066: public void readExternal(ObjectInput in) throws IOException,
067: ClassNotFoundException {
068: requestType = in.readByte();
069: xid = in.readObject();
070: int size = in.readInt();
071: messages = new SpyMessage[size];
072: for (int i = 0; i < size; ++i)
073: messages[i] = SpyMessage.readMessage(in);
074: size = in.readInt();
075: acks = new AcknowledgementRequest[size];
076: for (int i = 0; i < size; ++i) {
077: acks[i] = new AcknowledgementRequest();
078: acks[i].readExternal(in);
079: }
080: }
081:
082: public void writeExternal(ObjectOutput out) throws IOException {
083: out.writeByte(requestType);
084: // Non Serializable Xid, use our wrapper
085: if (xid != null && xid instanceof Xid
086: && xid instanceof Serializable == false)
087: out.writeObject(new JBossMQXid((Xid) xid));
088: else
089: out.writeObject(xid);
090: if (messages == null)
091: out.writeInt(0);
092: else {
093: out.writeInt(messages.length);
094: for (int i = 0; i < messages.length; ++i)
095: SpyMessage.writeMessage(messages[i], out);
096: }
097: if (acks == null)
098: out.writeInt(0);
099: else {
100: out.writeInt(acks.length);
101: for (int i = 0; i < acks.length; ++i)
102: acks[i].writeExternal(out);
103: }
104: }
105: }
|