KickJava   Java API By Example, From Geeks To Geeks.

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


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  * An <code>AbstractJmsRequest</code> is a request sent by a Joram client
36  * to its proxy.
37  */

38 public abstract class AbstractJmsRequest extends AbstractJmsMessage {
39   /**
40    * Identifier of the request.
41    * Declared volatile to allow a thread that is not the thread sending the
42    * request to get the identifier in order to cancel it during a close.
43    */

44   protected volatile int requestId = -1;
45
46   /**
47    * Sets the request identifier.
48    */

49   public final void setRequestId(int requestId) {
50     this.requestId = requestId;
51   }
52   
53   /** Returns the request identifier. */
54   public final synchronized int getRequestId() {
55     return requestId;
56   }
57
58   /**
59    * The request target is either a destination agent name, or a subscription
60    * name.
61    */

62   protected String JavaDoc target = null;
63
64    /** Sets the request target name. */
65   public final void setTarget(String JavaDoc target) {
66     this.target = target;
67   }
68
69   /** Returns the request target name. */
70   public final String JavaDoc getTarget() {
71     return target;
72   }
73
74   /**
75    * Constructs an <code>AbstractJmsRequest</code>.
76    */

77   public AbstractJmsRequest() {}
78
79   /**
80    * Constructs an <code>AbstractJmsRequest</code>.
81    *
82    * @param target String identifier of the request target, either a queue
83    * name, or a subscription name.
84    */

85   public AbstractJmsRequest(String JavaDoc target) {
86     this.target = target;
87   }
88
89   public final String JavaDoc toString() {
90     StringBuffer JavaDoc strbuf = new StringBuffer JavaDoc();
91     toString(strbuf);
92     return strbuf.toString();
93   }
94
95   public void toString(StringBuffer JavaDoc strbuf) {
96     strbuf.append('(').append(super.toString());
97     strbuf.append(",requestId=").append(requestId);
98     strbuf.append(",target=").append(target);
99     strbuf.append(')');
100   }
101
102   /* ***** ***** ***** ***** *****
103    * Streamable interface
104    * ***** ***** ***** ***** ***** */

105
106   /**
107    * The object implements the writeTo method to write its contents to
108    * the output stream.
109    *
110    * @param os the stream to write the object to
111    */

112   public void writeTo(OutputStream JavaDoc os) throws IOException JavaDoc {
113     StreamUtil.writeTo(requestId, os);
114     StreamUtil.writeTo(target, os);
115   }
116
117   /**
118    * The object implements the readFrom method to restore its contents from
119    * the input stream.
120    *
121    * @param is the stream to read data from in order to restore the object
122    */

123   public void readFrom(InputStream JavaDoc is) throws IOException JavaDoc {
124     requestId = StreamUtil.readIntFrom(is);
125     target = StreamUtil.readStringFrom(is);
126   }
127 }
128
Popular Tags