KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > sandesha > storage > dao > SandeshaQueueDAO


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */

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 JavaDoc;
26 import java.util.Random JavaDoc;
27 import java.util.Set JavaDoc;
28
29 /**
30  * @author Chamikara Jayalath
31  * @author Jaliya Ekanayaka
32  */

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 JavaDoc 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 JavaDoc sequenceId, Long JavaDoc 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 JavaDoc sequenceId) {
93         SandeshaQueue sq = SandeshaQueue.getInstance(endPoint);
94         boolean exists = sq.isIncomingSequenceExists(sequenceId);
95         return exists;
96     }
97
98     public RMMessageContext getNextMsgContextToProcess(Object JavaDoc sequence) {
99
100         SandeshaQueue sq = SandeshaQueue.getInstance(endPoint);
101         RMMessageContext msg = null;
102         try {
103             msg = sq.nextIncomingMessageToProcess(sequence);
104         } catch (Exception JavaDoc e) {
105             SandeshaQueueDAO.log.error(e);
106         }
107         return msg;
108     }
109
110     public Object JavaDoc getRandomSeqToProcess() {
111         SandeshaQueue sq = SandeshaQueue.getInstance(endPoint);
112         List JavaDoc seqs = sq.nextAllSeqsToProcess();
113         int size = seqs.size();
114         if (size <= 0)
115             return null;
116         Random JavaDoc r = new Random JavaDoc();
117         int number = r.nextInt(size);
118
119         return seqs.get(number);
120     }
121
122
123     public Set JavaDoc getAllReceivedMsgNumsOfIncomingSeq(String JavaDoc sequenceId) {
124         SandeshaQueue sq = SandeshaQueue.getInstance(endPoint);
125         return sq.getAllReceivedMsgNumsOfIncomingSeq(sequenceId);
126     }
127
128     public boolean isIncomingMessageExists(String JavaDoc sequenceId, Long JavaDoc msgNo) {
129         SandeshaQueue sq = SandeshaQueue.getInstance(endPoint);
130         return sq.isIncomingMessageExists(sequenceId, msgNo);
131     }
132
133     public boolean addMessageToOutgoingSequence(String JavaDoc 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 JavaDoc 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 JavaDoc 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 JavaDoc seqId, String JavaDoc outSeqId) {
176         SandeshaQueue sq = SandeshaQueue.getInstance(endPoint);
177         sq.setOutSequence(seqId, outSeqId);
178     }
179
180     public void setOutSequenceApproved(String JavaDoc seqId, boolean approved) {
181         SandeshaQueue sq = SandeshaQueue.getInstance(endPoint);
182         sq.setOutSequenceApproved(seqId, approved);
183
184     }
185
186     public String JavaDoc getSequenceOfOutSequence(String JavaDoc outsequenceId) {
187         SandeshaQueue sq = SandeshaQueue.getInstance(endPoint);
188         return sq.getSequenceOfOutSequence(outsequenceId);
189     }
190
191     public void removeCreateSequenceMsg(String JavaDoc messageId) {
192         // TODO Auto-generated method stub
193
SandeshaQueue sq = SandeshaQueue.getInstance(endPoint);
194         sq.movePriorityMsgToBin(messageId);
195     }
196
197     public long getNextOutgoingMessageNumber(String JavaDoc sequenceId) {
198         SandeshaQueue sq = SandeshaQueue.getInstance(endPoint);
199         return sq.getNextOutgoingMessageNumber(sequenceId);
200     }
201
202     //Only for client.
203
public RMMessageContext checkForResponseMessage(String JavaDoc requestId, String JavaDoc seqId) {
204         SandeshaQueue sq = SandeshaQueue.getInstance(endPoint);
205         RMMessageContext msg = sq.checkForResponseMessage(requestId, seqId);
206         return msg;
207     }
208
209     public String JavaDoc searchForSequenceId(String JavaDoc messageId) {
210         SandeshaQueue sq = SandeshaQueue.getInstance(endPoint);
211         String JavaDoc seqId = sq.searchForSequenceId(messageId);
212         return seqId;
213     }
214
215
216     /*
217      *
218      *
219      */

220     public void markOutgoingMessageToDelete(String JavaDoc seqId, Long JavaDoc 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 JavaDoc e) {
241             SandeshaQueueDAO.log.error(e);
242         }
243
244         return null;
245     }
246
247     public void setAckReceived(String JavaDoc seqId, long msgNo) {
248         SandeshaQueue sq = SandeshaQueue.getInstance(endPoint);
249         sq.setAckReceived(seqId, msgNo);
250     }
251
252     public void addSendMsgNo(String JavaDoc seqId, long msgNo) {
253         SandeshaQueue sq = SandeshaQueue.getInstance(endPoint);
254         sq.addSendMsgNo(seqId, msgNo);
255     }
256
257     public boolean isSentMsg(String JavaDoc seqId, long msgNo) {
258         SandeshaQueue sq = SandeshaQueue.getInstance(endPoint);
259         return sq.isSentMsg(seqId, msgNo);
260     }
261
262     public boolean hasLastIncomingMsgReceived(String JavaDoc seqId) {
263         SandeshaQueue sq = SandeshaQueue.getInstance(endPoint);
264         return sq.hasLastIncomingMsgReceived(seqId);
265     }
266
267     public long getLastIncomingMsgNo(String JavaDoc seqId) {
268         SandeshaQueue sq = SandeshaQueue.getInstance(endPoint);
269         return sq.getLastIncomingMsgNo(seqId);
270     }
271
272     public void addRequestedSequence(String JavaDoc seqId) {
273         SandeshaQueue sq = SandeshaQueue.getInstance(endPoint);
274         sq.addRequestedSequence(seqId);
275     }
276
277     public boolean isRequestedSeqPresent(String JavaDoc seqId) {
278         SandeshaQueue sq = SandeshaQueue.getInstance(endPoint);
279         return sq.isRequestedSeqPresent(seqId);
280     }
281
282     public String JavaDoc getKeyFromIncomingSequenceId(String JavaDoc seqID) {
283         SandeshaQueue sq = SandeshaQueue.getInstance(endPoint);
284         return sq.getKeyFromIncomingSequenceId(seqID);
285     }
286
287     public String JavaDoc getKeyFromOutgoingSequenceId(String JavaDoc 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 JavaDoc seqId) {
303         SandeshaQueue sq = SandeshaQueue.getInstance(endPoint);
304         sq.setTerminateSend(seqId);
305     }
306
307     public void setTerminateReceived(String JavaDoc seqId) {
308         SandeshaQueue sq = SandeshaQueue.getInstance(endPoint);
309         sq.setTerminateReceived(seqId);
310     }
311
312
313     public void setAcksTo(String JavaDoc seqId, String JavaDoc acksTo) {
314         SandeshaQueue sq = SandeshaQueue.getInstance(endPoint);
315         sq.setAcksTo(seqId, acksTo);
316     }
317
318     public String JavaDoc getAcksTo(String JavaDoc seqId) {
319         SandeshaQueue sq = SandeshaQueue.getInstance(endPoint);
320         return sq.getAcksTo(seqId);
321     }
322
323     public void addOffer(String JavaDoc msgID, String JavaDoc offerID) {
324         SandeshaQueue sq = SandeshaQueue.getInstance(endPoint);
325         sq.addOffer(msgID, offerID);
326     }
327
328     public String JavaDoc getOffer(String JavaDoc 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 JavaDoc seqId) {
339         SandeshaQueue sq = SandeshaQueue.getInstance(endPoint);
340         return sq.isOutgoingTerminateSent(seqId);
341     }
342
343     public boolean isIncommingTerminateReceived(String JavaDoc seqId) {
344         SandeshaQueue sq = SandeshaQueue.getInstance(endPoint);
345         return sq.isIncommingTerminateReceived(seqId);
346     }
347
348     public void updateFinalMessageArrivedTime(String JavaDoc sequenceID) {
349         SandeshaQueue sq = SandeshaQueue.getInstance(endPoint);
350         sq.updateFinalMessageArrivedTime(sequenceID);
351     }
352
353     public void sendAck(String JavaDoc sequenceId) {
354         SandeshaQueue sq = SandeshaQueue.getInstance(endPoint);
355         sq.sendAck(sequenceId);
356     }
357
358     public void removeAllAcks(String JavaDoc sequenceID) {
359         SandeshaQueue sq = SandeshaQueue.getInstance(endPoint);
360         sq.removeAllAcks(sequenceID);
361     }
362 }
363
Popular Tags