1 22 package org.jboss.mq; 23 24 import java.io.Externalizable ; 25 import java.io.IOException ; 26 import java.io.ObjectInput ; 27 import java.io.ObjectOutput ; 28 import java.io.Serializable ; 29 30 import javax.transaction.xa.Xid ; 31 32 41 public class TransactionRequest implements Externalizable 42 { 43 44 static final long serialVersionUID = 5368191944552650149L; 45 46 47 public final static byte ONE_PHASE_COMMIT_REQUEST = 0; 48 49 public final static byte TWO_PHASE_COMMIT_PREPARE_REQUEST = 1; 50 51 public final static byte TWO_PHASE_COMMIT_COMMIT_REQUEST = 2; 52 53 public final static byte TWO_PHASE_COMMIT_ROLLBACK_REQUEST = 3; 54 55 56 public byte requestType = ONE_PHASE_COMMIT_REQUEST; 57 58 59 public Object xid; 60 61 62 public SpyMessage[] messages; 63 64 65 public AcknowledgementRequest[] acks; 66 67 public void readExternal(ObjectInput in) throws IOException , ClassNotFoundException 68 { 69 requestType = in.readByte(); 70 xid = in.readObject(); 71 int size = in.readInt(); 72 messages = new SpyMessage[size]; 73 for (int i = 0; i < size; ++i) 74 messages[i] = SpyMessage.readMessage(in); 75 size = in.readInt(); 76 acks = new AcknowledgementRequest[size]; 77 for (int i = 0; i < size; ++i) 78 { 79 acks[i] = new AcknowledgementRequest(); 80 acks[i].readExternal(in); 81 } 82 } 83 84 public void writeExternal(ObjectOutput out) throws IOException 85 { 86 out.writeByte(requestType); 87 if (xid != null && xid instanceof Xid && xid instanceof Serializable == false) 89 out.writeObject(new JBossMQXid((Xid ) xid)); 90 else 91 out.writeObject(xid); 92 if (messages == null) 93 out.writeInt(0); 94 else 95 { 96 out.writeInt(messages.length); 97 for (int i = 0; i < messages.length; ++i) 98 SpyMessage.writeMessage(messages[i], out); 99 } 100 if (acks == null) 101 out.writeInt(0); 102 else 103 { 104 out.writeInt(acks.length); 105 for (int i = 0; i < acks.length; ++i) 106 acks[i].writeExternal(out); 107 } 108 } 109 } | Popular Tags |