KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > mq > TransactionRequest


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2005, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 */

22 package org.jboss.mq;
23
24 import java.io.Externalizable JavaDoc;
25 import java.io.IOException JavaDoc;
26 import java.io.ObjectInput JavaDoc;
27 import java.io.ObjectOutput JavaDoc;
28 import java.io.Serializable JavaDoc;
29
30 import javax.transaction.xa.Xid JavaDoc;
31
32 /**
33  * This class contians all the data needed to perform a JMS transaction
34  *
35  * @author Hiram Chirino (Cojonudo14@hotmail.com)
36  * @author David Maplesden (David.Maplesden@orion.co.nz)
37  * @author <a HREF="mailto:adrian@jboss.org">Adrian Brock</a>
38  * @author Daniel Bloomfield Ramagem (daniel.ramagem@gmail.com)
39  * @version $Revision: 41427 $
40  */

41 public class TransactionRequest implements Externalizable JavaDoc
42 {
43    /** The serialVersionUID */
44    static final long serialVersionUID = 5368191944552650149L;
45    
46    /** One phase Commit request */
47    public final static byte ONE_PHASE_COMMIT_REQUEST = 0;
48    /** Two phase Prepare phase */
49    public final static byte TWO_PHASE_COMMIT_PREPARE_REQUEST = 1;
50    /** Two phase Commit phase */
51    public final static byte TWO_PHASE_COMMIT_COMMIT_REQUEST = 2;
52    /** Rollback request */
53    public final static byte TWO_PHASE_COMMIT_ROLLBACK_REQUEST = 3;
54    
55    /** Request type */
56    public byte requestType = ONE_PHASE_COMMIT_REQUEST;
57
58    /** For 2 phase commit, this identifies the transaction. */
59    public Object JavaDoc xid;
60
61    /** messages sent in the transaction */
62    public SpyMessage[] messages;
63
64    /** messages acknowleged in the transaction */
65    public AcknowledgementRequest[] acks;
66
67    public void readExternal(ObjectInput JavaDoc in) throws IOException JavaDoc, ClassNotFoundException JavaDoc
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 JavaDoc out) throws IOException JavaDoc
85    {
86       out.writeByte(requestType);
87       // Non Serializable Xid, use our wrapper
88
if (xid != null && xid instanceof Xid JavaDoc && xid instanceof Serializable JavaDoc == false)
89          out.writeObject(new JBossMQXid((Xid JavaDoc) 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