1 17 package org.apache.sandesha.storage.dao; 18 19 import org.apache.axis.components.logger.LogFactory; 20 import org.apache.commons.logging.Log; 21 import org.apache.sandesha.RMMessageContext; 22 import org.apache.sandesha.storage.queue.QueueException; 23 import org.apache.sandesha.storage.queue.SandeshaQueue; 24 25 import java.util.List ; 26 import java.util.Random ; 27 import java.util.Set ; 28 29 33 34 public class SandeshaQueueDAO implements ISandeshaDAO { 35 36 private static final Log log = LogFactory.getLog(SandeshaQueueDAO.class.getName()); 37 private byte endPoint; 38 39 public SandeshaQueueDAO(byte endPoint) { 40 super(); 41 this.endPoint = endPoint; 42 } 43 44 45 public boolean addIncomingSequence(String sequenceId) { 46 boolean result = false; 47 try { 48 SandeshaQueue sq = SandeshaQueue.getInstance(endPoint); 49 sq.createNewIncomingSequence(sequenceId); 50 result = true; 51 } catch (QueueException e) { 52 SandeshaQueueDAO.log.error(e); 53 } 54 return result; 55 } 56 57 public boolean addPriorityMessage(RMMessageContext msg) { 58 boolean result = false; 59 try { 60 SandeshaQueue sq = SandeshaQueue.getInstance(endPoint); 61 sq.addPriorityMessage(msg); 62 } catch (QueueException e) { 63 SandeshaQueueDAO.log.error(e); 64 } 65 return result; 66 } 67 68 public RMMessageContext getNextPriorityMessageContextToSend() { 69 RMMessageContext msg = null; 70 try { 71 SandeshaQueue sq = SandeshaQueue.getInstance(endPoint); 72 msg = sq.nextPriorityMessageToSend(); 73 } catch (QueueException e) { 74 SandeshaQueueDAO.log.error(e); 75 } 76 return msg; 77 } 78 79 public boolean addMessageToIncomingSequence(String sequenceId, Long msgNo, 80 RMMessageContext rmMessageContext) { 81 boolean result = false; 82 try { 83 SandeshaQueue sq = SandeshaQueue.getInstance(endPoint); 84 sq.addMessageToIncomingSequence(sequenceId, msgNo, rmMessageContext); 85 result = true; 86 } catch (QueueException e) { 87 SandeshaQueueDAO.log.error(e); 88 } 89 return result; 90 } 91 92 public boolean isIncomingSequenceExists(String sequenceId) { 93 SandeshaQueue sq = SandeshaQueue.getInstance(endPoint); 94 boolean exists = sq.isIncomingSequenceExists(sequenceId); 95 return exists; 96 } 97 98 public RMMessageContext getNextMsgContextToProcess(Object sequence) { 99 100 SandeshaQueue sq = SandeshaQueue.getInstance(endPoint); 101 RMMessageContext msg = null; 102 try { 103 msg = sq.nextIncomingMessageToProcess(sequence); 104 } catch (Exception e) { 105 SandeshaQueueDAO.log.error(e); 106 } 107 return msg; 108 } 109 110 public Object getRandomSeqToProcess() { 111 SandeshaQueue sq = SandeshaQueue.getInstance(endPoint); 112 List seqs = sq.nextAllSeqsToProcess(); 113 int size = seqs.size(); 114 if (size <= 0) 115 return null; 116 Random r = new Random (); 117 int number = r.nextInt(size); 118 119 return seqs.get(number); 120 } 121 122 123 public Set getAllReceivedMsgNumsOfIncomingSeq(String sequenceId) { 124 SandeshaQueue sq = SandeshaQueue.getInstance(endPoint); 125 return sq.getAllReceivedMsgNumsOfIncomingSeq(sequenceId); 126 } 127 128 public boolean isIncomingMessageExists(String sequenceId, Long msgNo) { 129 SandeshaQueue sq = SandeshaQueue.getInstance(endPoint); 130 return sq.isIncomingMessageExists(sequenceId, msgNo); 131 } 132 133 public boolean addMessageToOutgoingSequence(String sequenceId, 134 RMMessageContext rmMessageContext) { 135 boolean result = false; 136 try { 137 SandeshaQueue sq = SandeshaQueue.getInstance(endPoint); 138 sq.addMessageToOutgoingSequence(sequenceId, rmMessageContext); 139 result = true; 140 } catch (QueueException e) { 141 SandeshaQueueDAO.log.error(e); 142 } 143 return result; 144 } 145 146 public boolean addOutgoingSequence(String sequenceId) { 147 boolean result = false; 148 try { 149 SandeshaQueue sq = SandeshaQueue.getInstance(endPoint); 150 sq.createNewOutgoingSequence(sequenceId); 151 result = true; 152 } catch (QueueException e) { 153 SandeshaQueueDAO.log.error(e); 154 } 155 return result; 156 } 157 158 public boolean isOutgoingSequenceExists(String sequenceId) { 159 SandeshaQueue sq = SandeshaQueue.getInstance(endPoint); 160 boolean exists = sq.isOutgoingSequenceExists(sequenceId); 161 return exists; 162 } 163 164 public RMMessageContext getNextOutgoingMsgContextToSend() { 165 RMMessageContext msg = null; 166 try { 167 SandeshaQueue sq = SandeshaQueue.getInstance(endPoint); 168 msg = sq.nextOutgoingMessageToSend(); 169 } catch (QueueException e) { 170 SandeshaQueueDAO.log.error(e); 171 } 172 return msg; 173 } 174 175 public void setOutSequence(String seqId, String outSeqId) { 176 SandeshaQueue sq = SandeshaQueue.getInstance(endPoint); 177 sq.setOutSequence(seqId, outSeqId); 178 } 179 180 public void setOutSequenceApproved(String seqId, boolean approved) { 181 SandeshaQueue sq = SandeshaQueue.getInstance(endPoint); 182 sq.setOutSequenceApproved(seqId, approved); 183 184 } 185 186 public String getSequenceOfOutSequence(String outsequenceId) { 187 SandeshaQueue sq = SandeshaQueue.getInstance(endPoint); 188 return sq.getSequenceOfOutSequence(outsequenceId); 189 } 190 191 public void removeCreateSequenceMsg(String messageId) { 192 SandeshaQueue sq = SandeshaQueue.getInstance(endPoint); 194 sq.movePriorityMsgToBin(messageId); 195 } 196 197 public long getNextOutgoingMessageNumber(String sequenceId) { 198 SandeshaQueue sq = SandeshaQueue.getInstance(endPoint); 199 return sq.getNextOutgoingMessageNumber(sequenceId); 200 } 201 202 public RMMessageContext checkForResponseMessage(String requestId, String seqId) { 204 SandeshaQueue sq = SandeshaQueue.getInstance(endPoint); 205 RMMessageContext msg = sq.checkForResponseMessage(requestId, seqId); 206 return msg; 207 } 208 209 public String searchForSequenceId(String messageId) { 210 SandeshaQueue sq = SandeshaQueue.getInstance(endPoint); 211 String seqId = sq.searchForSequenceId(messageId); 212 return seqId; 213 } 214 215 216 220 public void markOutgoingMessageToDelete(String seqId, Long msgNo) { 221 SandeshaQueue sq = SandeshaQueue.getInstance(endPoint); 222 sq.markOutgoingMessageToDelete(seqId, msgNo); 223 } 224 225 226 public void addLowPriorityMessage(RMMessageContext msg) { 227 SandeshaQueue sq = SandeshaQueue.getInstance(endPoint); 228 try { 229 sq.addLowPriorityMessage(msg); 230 } catch (QueueException e) { 231 SandeshaQueueDAO.log.error(e); 232 } 233 234 } 235 236 public RMMessageContext getNextLowPriorityMessageContextToSend() { 237 SandeshaQueue sq = SandeshaQueue.getInstance(endPoint); 238 try { 239 return sq.getLowPriorityMessageIfAcked(); 240 } catch (Exception e) { 241 SandeshaQueueDAO.log.error(e); 242 } 243 244 return null; 245 } 246 247 public void setAckReceived(String seqId, long msgNo) { 248 SandeshaQueue sq = SandeshaQueue.getInstance(endPoint); 249 sq.setAckReceived(seqId, msgNo); 250 } 251 252 public void addSendMsgNo(String seqId, long msgNo) { 253 SandeshaQueue sq = SandeshaQueue.getInstance(endPoint); 254 sq.addSendMsgNo(seqId, msgNo); 255 } 256 257 public boolean isSentMsg(String seqId, long msgNo) { 258 SandeshaQueue sq = SandeshaQueue.getInstance(endPoint); 259 return sq.isSentMsg(seqId, msgNo); 260 } 261 262 public boolean hasLastIncomingMsgReceived(String seqId) { 263 SandeshaQueue sq = SandeshaQueue.getInstance(endPoint); 264 return sq.hasLastIncomingMsgReceived(seqId); 265 } 266 267 public long getLastIncomingMsgNo(String seqId) { 268 SandeshaQueue sq = SandeshaQueue.getInstance(endPoint); 269 return sq.getLastIncomingMsgNo(seqId); 270 } 271 272 public void addRequestedSequence(String seqId) { 273 SandeshaQueue sq = SandeshaQueue.getInstance(endPoint); 274 sq.addRequestedSequence(seqId); 275 } 276 277 public boolean isRequestedSeqPresent(String seqId) { 278 SandeshaQueue sq = SandeshaQueue.getInstance(endPoint); 279 return sq.isRequestedSeqPresent(seqId); 280 } 281 282 public String getKeyFromIncomingSequenceId(String seqID) { 283 SandeshaQueue sq = SandeshaQueue.getInstance(endPoint); 284 return sq.getKeyFromIncomingSequenceId(seqID); 285 } 286 287 public String getKeyFromOutgoingSequenceId(String seqID) { 288 SandeshaQueue sq = SandeshaQueue.getInstance(endPoint); 289 return sq.getKeyFromOutgoingSequenceId(seqID); 290 } 291 292 public boolean isAllOutgoingTerminateSent() { 293 SandeshaQueue sq = SandeshaQueue.getInstance(endPoint); 294 return sq.isAllOutgoingTerminateSent(); 295 } 296 297 public boolean isAllIncommingTerminateReceived() { 298 SandeshaQueue sq = SandeshaQueue.getInstance(endPoint); 299 return sq.isAllIncommingTerminateReceived(); 300 } 301 302 public void setTerminateSend(String seqId) { 303 SandeshaQueue sq = SandeshaQueue.getInstance(endPoint); 304 sq.setTerminateSend(seqId); 305 } 306 307 public void setTerminateReceived(String seqId) { 308 SandeshaQueue sq = SandeshaQueue.getInstance(endPoint); 309 sq.setTerminateReceived(seqId); 310 } 311 312 313 public void setAcksTo(String seqId, String acksTo) { 314 SandeshaQueue sq = SandeshaQueue.getInstance(endPoint); 315 sq.setAcksTo(seqId, acksTo); 316 } 317 318 public String getAcksTo(String seqId) { 319 SandeshaQueue sq = SandeshaQueue.getInstance(endPoint); 320 return sq.getAcksTo(seqId); 321 } 322 323 public void addOffer(String msgID, String offerID) { 324 SandeshaQueue sq = SandeshaQueue.getInstance(endPoint); 325 sq.addOffer(msgID, offerID); 326 } 327 328 public String getOffer(String msgID) { 329 SandeshaQueue sq = SandeshaQueue.getInstance(endPoint); 330 return sq.getOffer(msgID); 331 } 332 333 public void clear() { 334 SandeshaQueue sq = SandeshaQueue.getInstance(endPoint); 335 sq.clear(true); 336 } 337 338 public boolean isOutgoingTerminateSent(String seqId) { 339 SandeshaQueue sq = SandeshaQueue.getInstance(endPoint); 340 return sq.isOutgoingTerminateSent(seqId); 341 } 342 343 public boolean isIncommingTerminateReceived(String seqId) { 344 SandeshaQueue sq = SandeshaQueue.getInstance(endPoint); 345 return sq.isIncommingTerminateReceived(seqId); 346 } 347 348 public void updateFinalMessageArrivedTime(String sequenceID) { 349 SandeshaQueue sq = SandeshaQueue.getInstance(endPoint); 350 sq.updateFinalMessageArrivedTime(sequenceID); 351 } 352 353 public void sendAck(String sequenceId) { 354 SandeshaQueue sq = SandeshaQueue.getInstance(endPoint); 355 sq.sendAck(sequenceId); 356 } 357 358 public void removeAllAcks(String sequenceID) { 359 SandeshaQueue sq = SandeshaQueue.getInstance(endPoint); 360 sq.removeAllAcks(sequenceID); 361 } 362 } 363 | Popular Tags |