KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > joram > mom > notifications > ReceiveRequest


1 /*
2  * JORAM: Java(TM) Open Reliable Asynchronous Messaging
3  * Copyright (C) 2001 - 2006 ScalAgent Distributed Technologies
4  * Copyright (C) 1996 - 2000 Dyade
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA.
20  *
21  * Initial developer(s): Frederic Maistre (INRIA)
22  * Contributor(s): ScalAgent Distributed Technologies
23  */

24 package org.objectweb.joram.mom.notifications;
25
26 /**
27  * A <code>ReceiveRequest</code> instance is used by a client agent for
28  * requesting a message on a queue.
29  */

30 public class ReceiveRequest extends AbstractRequest {
31   /**
32    * String selector for filtering messages, null or empty for no selection.
33    */

34   private String JavaDoc selector;
35   /**
36    * The time-to-live value in milliseconds, during which a receive request
37    * is valid.
38    */

39   private long timeOut;
40   /** The expiration time of the request. */
41   private long expirationTime;
42   /**
43    * If <code>true</code>, the consumed message will be immediately
44    * deleted on the queue.
45    */

46   private boolean autoAck;
47   /**
48    * Identifier of the client requesting a message, set by the queue if
49    * storing the request.
50    */

51   public fr.dyade.aaa.agent.AgentId requester;
52
53   private String JavaDoc[] msgIds;
54
55   private int msgCount;
56
57   /**
58    * Constructs a <code>ReceiveRequest</code> instance.
59    *
60    * @param clientContext Identifies a client context.
61    * @param requestId Request identifier.
62    * @param selector Selector expression for filtering messages, null or empty
63    * for no selection.
64    * @param timeOut Time-to-live value. For immediate delivery, should be set
65    * to 0. For infinite time-to-live, should be negative.
66    * @param autoAck <code>true</code> for immediately acknowledging the
67    * delivered message on the queue, <code>false</code> otherwise.
68    */

69   public ReceiveRequest(int clientContext,
70                         int requestId,
71                         String JavaDoc selector,
72                         long timeOut,
73                         boolean autoAck,
74                         String JavaDoc[] msgIds,
75                         int msgCount) {
76     super(clientContext, requestId);
77     this.selector = selector;
78     this.timeOut = timeOut;
79     this.autoAck = autoAck;
80     this.msgIds = msgIds;
81     this.msgCount = msgCount;
82   }
83
84
85   /** Returns the selector of the request. */
86   public String JavaDoc getSelector() {
87     return selector;
88   }
89
90   /**
91    * Returns the time-to-live parameter of this request, in milliseconds (0 for
92    * immediate delivery, negative for infinite validity).
93    */

94   public long getTimeOut() {
95     return timeOut;
96   }
97
98   /** Checks the autoAck mode of this request. */
99   public boolean getAutoAck() {
100     return autoAck;
101   }
102
103   public final String JavaDoc[] getMessageIds() {
104     return msgIds;
105   }
106
107   /**
108    * Updates the expiration time field, if needed.
109    * This method calculate the expiration time of the request from the
110    * current time (1st argument) and the timeout attribute.
111    *
112    * @param startTime The starting time to calculate the expiration time.
113    */

114   public void setExpiration(long startTime) {
115     if (timeOut > 0)
116       this.expirationTime = startTime + timeOut;
117   }
118
119   /**
120    * Returns <code>false</code> if the request expired.
121    *
122    * @param currentTime The current time to verify the expiration time.
123    */

124   public boolean isValid(long currentTime) {
125     if (timeOut > 0)
126       return currentTime < expirationTime;
127     return true;
128   }
129
130   public final int getMessageCount() {
131     return msgCount;
132   }
133 }
134
Popular Tags