KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > joram > shared > client > ConsumerReceiveRequest


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.shared.client;
25
26 import java.io.Externalizable JavaDoc;
27 import java.io.InputStream JavaDoc;
28 import java.io.OutputStream JavaDoc;
29 import java.io.IOException JavaDoc;
30
31 import org.objectweb.joram.shared.stream.Streamable;
32 import org.objectweb.joram.shared.stream.StreamUtil;
33
34 /**
35  * A <code>ConsumerReceiveRequest</code> is sent by a
36  * <code>MessageConsumer</code> when requesting a message.
37  */

38 public final class ConsumerReceiveRequest extends AbstractJmsRequest {
39   /** The selector for filtering messages on a queue. */
40   private String JavaDoc selector;
41
42   /** Sets the selector. */
43   public void setSelector(String JavaDoc selector) {
44     this.selector = selector;
45   }
46
47   /** Returns the selector for filtering the messages. */
48   public String JavaDoc getSelector() {
49     return selector;
50   }
51
52   /** The time to live value of the request (negative for infinite). */
53   private long timeToLive;
54
55   /** Sets the time to live value. */
56   public void setTimeToLive(long timeToLive) {
57     this.timeToLive = timeToLive;
58   }
59
60   /** Returns the time to live value in milliseconds. */
61   public long getTimeToLive() {
62     return timeToLive;
63   }
64
65   /** <code>true</code> if the request is destinated to a queue. */
66   private boolean queueMode;
67
68   /** Sets the target destination type. */
69   public void setQueueMode(boolean queueMode) {
70     this.queueMode = queueMode;
71   }
72
73   /** Returns <code>true</code> if the request is destinated to a queue. */
74   public boolean getQueueMode() {
75     return queueMode;
76   }
77
78   private boolean receiveAck;
79
80   public void setReceiveAck(boolean receiveAck) {
81     this.receiveAck = receiveAck;
82   }
83
84   public final boolean getReceiveAck() {
85     return receiveAck;
86   }
87
88   protected int getClassId() {
89     return CONSUMER_RECEIVE_REQUEST;
90   }
91
92   /**
93    * Constructs a <code>ConsumerReceiveRequest</code>.
94    *
95    * @param targetName Name of the target queue or subscription.
96    * @param selector The selector for filtering messages, if any.
97    * @param timeToLive Time to live value in milliseconds, negative for
98    * infinite.
99    * @param queueMode <code>true</code> if this request is destinated to a
100    * queue.
101    */

102   public ConsumerReceiveRequest(String JavaDoc targetName, String JavaDoc selector,
103                                 long timeToLive, boolean queueMode) {
104     super(targetName);
105     this.selector = selector;
106     this.timeToLive = timeToLive;
107     this.queueMode = queueMode;
108     receiveAck = false;
109   }
110
111   /**
112    * Constructs a <code>ConsumerReceiveRequest</code>.
113    */

114   public ConsumerReceiveRequest() {}
115
116   /* ***** ***** ***** ***** *****
117    * Streamable interface
118    * ***** ***** ***** ***** ***** */

119
120   /**
121    * The object implements the writeTo method to write its contents to
122    * the output stream.
123    *
124    * @param os the stream to write the object to
125    */

126   public void writeTo(OutputStream JavaDoc os) throws IOException JavaDoc {
127     super.writeTo(os);
128     StreamUtil.writeTo(selector, os);
129     StreamUtil.writeTo(timeToLive, os);
130     StreamUtil.writeTo(queueMode, os);
131     StreamUtil.writeTo(receiveAck, os);
132   }
133
134   /**
135    * The object implements the readFrom method to restore its contents from
136    * the input stream.
137    *
138    * @param is the stream to read data from in order to restore the object
139    */

140   public void readFrom(InputStream JavaDoc is) throws IOException JavaDoc {
141     super.readFrom(is);
142     selector = StreamUtil.readStringFrom(is);
143     timeToLive = StreamUtil.readLongFrom(is);
144     queueMode = StreamUtil.readBooleanFrom(is);
145     receiveAck = StreamUtil.readBooleanFrom(is);
146   }
147 }
148
Popular Tags