KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.util.Vector JavaDoc;
32
33 import org.objectweb.joram.shared.stream.Streamable;
34 import org.objectweb.joram.shared.stream.StreamUtil;
35
36 /**
37  * A <code>SessDenyRequest</code> instance is used by a <code>Session</code>
38  * for denying the messages it consumed.
39  */

40 public final class SessDenyRequest extends AbstractJmsRequest {
41   /** Vector of message identifiers. */
42   private Vector JavaDoc ids;
43
44   /** Sets the vector of identifiers. */
45   public void setIds(Vector JavaDoc ids) {
46     this.ids = ids;
47   }
48
49   public void addId(String JavaDoc id) {
50     if (ids == null)
51       ids = new Vector JavaDoc();
52     ids.addElement(id);
53   }
54
55   /** Returns the vector of denyed messages identifiers. */
56   public Vector JavaDoc getIds() {
57     return ids;
58   }
59
60   /** <code>true</code> if the request is destinated to a queue. */
61   private boolean queueMode;
62
63   /** Sets the target destination type. */
64   public void setQueueMode(boolean queueMode) {
65     this.queueMode = queueMode;
66   }
67
68   /** Returns <code>true</code> if the request is destinated to a queue. */
69   public boolean getQueueMode() {
70     return queueMode;
71   }
72
73   /** <code>true</code> if the request must not be acked by the server. */
74   private boolean doNotAck = false;
75
76   /** Sets the server ack policy. */
77   public void setDoNotAck(boolean doNotAck) {
78     this.doNotAck = doNotAck;
79   }
80
81   /**
82    * Returns <code>true</code> if the request must not be acked by the
83    * server.
84    */

85   public boolean getDoNotAck() {
86     return doNotAck;
87   }
88
89   protected int getClassId() {
90     return SESS_DENY_REQUEST;
91   }
92
93   /**
94    * Constructs a <code>SessDenyRequest</code> instance.
95    *
96    * @param targetName Name of the target queue or subscription.
97    * @param ids Vector of denied message identifiers.
98    * @param queueMode <code>true</code> if this request is destinated to a
99    * queue.
100    */

101   public SessDenyRequest(String JavaDoc targetName, Vector JavaDoc ids, boolean queueMode) {
102     super(targetName);
103     this.ids = ids;
104     this.queueMode = queueMode;
105   }
106
107   /**
108    * Constructs a <code>SessDenyRequest</code> instance.
109    *
110    * @param targetName Name of the target queue or subscription.
111    * @param ids Vector of denied message identifiers.
112    * @param queueMode <code>true</code> if this request is destinated to a
113    * queue.
114    * @param doNotAck <code>true</code> if this request must not be acked by
115    * the server.
116    */

117   public SessDenyRequest(String JavaDoc targetName, Vector JavaDoc ids, boolean queueMode,
118                          boolean doNotAck) {
119     super(targetName);
120     this.ids = ids;
121     this.queueMode = queueMode;
122     this.doNotAck = doNotAck;
123   }
124
125   /**
126    * Public no-arg constructor needed by Externalizable.
127    */

128   public SessDenyRequest() {}
129
130   /* ***** ***** ***** ***** *****
131    * Streamable interface
132    * ***** ***** ***** ***** ***** */

133
134   /**
135    * The object implements the writeTo method to write its contents to
136    * the output stream.
137    *
138    * @param os the stream to write the object to
139    */

140   public void writeTo(OutputStream JavaDoc os) throws IOException JavaDoc {
141     super.writeTo(os);
142     StreamUtil.writeVectorOfStringTo(ids, os);
143     StreamUtil.writeTo(queueMode, os);
144     StreamUtil.writeTo(doNotAck, os);
145   }
146
147   /**
148    * The object implements the readFrom method to restore its contents from
149    * the input stream.
150    *
151    * @param is the stream to read data from in order to restore the object
152    */

153   public void readFrom(InputStream JavaDoc is) throws IOException JavaDoc {
154     super.readFrom(is);
155     ids = StreamUtil.readVectorOfStringFrom(is);
156     queueMode = StreamUtil.readBooleanFrom(is);
157     doNotAck = StreamUtil.readBooleanFrom(is);
158   }
159 }
160
Popular Tags