1 22 package org.jboss.tm.recovery; 23 24 import EDU.oswego.cs.dl.util.concurrent.Latch; 25 26 import java.nio.ByteBuffer ; 27 28 36 class PendingWriteRequest 37 { 38 42 static final int TYPE_TX_MULTI_TM = 1; 43 44 47 static final int TYPE_TX_SINGLE_TM = 0; 48 49 53 static final int TYPE_END = -1; 54 55 58 private ByteBuffer buffer; 59 60 63 private BatchLog log; 64 65 70 private Latch latch; 71 72 79 private TxCompletionHandler completionHandler; 80 81 85 private Exception failure; 86 87 93 private int type; 94 95 107 PendingWriteRequest(ByteBuffer buffer, 108 Latch latch, 109 boolean multiTmTransaction) 110 { 111 this.buffer = buffer; 112 this.latch = latch; 113 this.log = null; 114 type = (multiTmTransaction) ? TYPE_TX_MULTI_TM : TYPE_TX_SINGLE_TM; 115 } 116 117 130 PendingWriteRequest(ByteBuffer buffer, Latch latch, BatchLog log) 131 { 132 this.buffer = buffer; 133 this.latch = latch; 134 this.log = log; 135 type = TYPE_END; 136 } 137 138 147 TxCompletionHandler waitTilDone() 148 { 149 try 150 { 151 latch.acquire(); 152 if (failure != null) 153 throw failure; 154 return completionHandler; 155 } 156 catch (Exception e) 157 { 158 throw new RuntimeException (e); 159 } 160 } 161 162 167 ByteBuffer getBuffer() 168 { 169 return buffer; 170 } 171 172 178 int getType() 179 { 180 return type; 181 } 182 183 188 BatchLog getLogger() 189 { 190 return log; 191 } 192 193 199 void setCompletionHandler(TxCompletionHandler completionHandler) 200 { 201 this.completionHandler = completionHandler; 202 } 203 204 211 void setFailure(Exception failure) 212 { 213 this.failure = failure; 214 } 215 216 } 217 | Popular Tags |