1 24 package org.objectweb.joram.shared.client; 25 26 import java.io.InputStream ; 27 import java.io.OutputStream ; 28 import java.io.IOException ; 29 import java.util.Enumeration ; 30 import java.util.Hashtable ; 31 import java.util.Vector ; 32 33 import org.objectweb.joram.shared.stream.Streamable; 34 import org.objectweb.joram.shared.stream.StreamUtil; 35 36 public final class CommitRequest extends AbstractJmsRequest { 37 40 private Vector producerMessages; 41 42 45 private Vector ackRequests; 46 47 52 private boolean asyncSend = false; 53 54 protected int getClassId() { 55 return COMMIT_REQUEST; 56 } 57 58 public CommitRequest() {} 59 60 public void addProducerMessages(ProducerMessages pm) { 61 if (producerMessages == null) producerMessages = new Vector (); 62 producerMessages.addElement(pm); 63 } 64 65 public void addAckRequest(SessAckRequest sar) { 66 if (ackRequests == null) ackRequests = new Vector (); 67 ackRequests.addElement(sar); 68 } 69 70 public Enumeration getProducerMessages() { 71 if (producerMessages != null) { 72 return producerMessages.elements(); 73 } else { 74 return null; 75 } 76 } 77 78 public Enumeration getAckRequests() { 79 if (ackRequests != null) { 80 return ackRequests.elements(); 81 } else { 82 return null; 83 } 84 } 85 86 public void setAsyncSend(boolean b) { 87 asyncSend = b; 88 } 89 90 public final boolean getAsyncSend() { 91 return asyncSend; 92 } 93 94 public void toString(StringBuffer strbuf) { 95 super.toString(strbuf); 96 strbuf.append(",producerMessages=").append(producerMessages); 97 strbuf.append(",ackRequests=").append(ackRequests); 98 strbuf.append(",asyncSend=").append(asyncSend); 99 strbuf.append(')'); 100 } 101 102 108 public void writeTo(OutputStream os) throws IOException { 109 super.writeTo(os); 110 111 if (producerMessages == null) { 113 StreamUtil.writeTo(-1, os); 114 } else { 115 int size = producerMessages.size(); 116 StreamUtil.writeTo(size, os); 117 for (int i=0; i<size; i++) { 118 ProducerMessages pm = (ProducerMessages) producerMessages.elementAt(i); 119 pm.writeTo(os); 120 } 121 } 122 123 if (ackRequests == null) { 125 StreamUtil.writeTo(-1, os); 126 } else { 127 int size = ackRequests.size(); 128 StreamUtil.writeTo(size, os); 129 for (int i=0; i<size; i++) { 130 SessAckRequest sar = (SessAckRequest) ackRequests.elementAt(i); 131 sar.writeTo(os); 132 } 133 } 134 135 StreamUtil.writeTo(asyncSend, os); 136 } 137 138 144 public void readFrom(InputStream is) throws IOException { 145 super.readFrom(is); 146 147 int size = StreamUtil.readIntFrom(is); 149 if (size == -1) { 150 producerMessages = null; 151 } else { 152 producerMessages = new Vector (size); 153 for (int i=0; i<size; i++) { 154 ProducerMessages pm = new ProducerMessages(); 155 pm.readFrom(is); 156 producerMessages.addElement(pm); 157 } 158 } 159 160 size = StreamUtil.readIntFrom(is); 162 if (size == -1) { 163 ackRequests = null; 164 } else { 165 ackRequests = new Vector (size); 166 for (int i=0; i<size; i++) { 167 SessAckRequest sar = new SessAckRequest(); 168 sar.readFrom(is); 169 ackRequests.addElement(sar); 170 } 171 } 172 173 asyncSend = StreamUtil.readBooleanFrom(is); 174 } 175 } 176 | Popular Tags |