KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > scalagent > kjoram > TemporaryQueue


1 /*
2  * JORAM: Java(TM) Open Reliable Asynchronous Messaging
3  * Copyright (C) 2001 - ScalAgent Distributed Technologies
4  * Copyright (C) 1996 - 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): Nicolas Tachker (ScalAgent)
23  */

24 package com.scalagent.kjoram;
25
26 import com.scalagent.kjoram.jms.TempDestDeleteRequest;
27
28 import java.util.Vector JavaDoc;
29 import java.util.Hashtable JavaDoc;
30
31 import com.scalagent.kjoram.excepts.JMSException;
32 import com.scalagent.kjoram.excepts.JMSSecurityException;
33
34
35 public class TemporaryQueue extends Queue
36 {
37   /** The connection the queue belongs to, <code>null</code> if not known. */
38   private Connection cnx;
39
40   /**
41    * Constructs a temporary queue.
42    *
43    * @param agentId Identifier of the queue agent.
44    * @param cnx The connection the queue belongs to, <code>null</code> if
45    * not known.
46    */

47   public TemporaryQueue(String JavaDoc agentId, Connection cnx)
48   {
49     super(agentId);
50     this.cnx = cnx;
51   }
52
53   /**
54    * Constructs an empty temporary queue.
55    */

56   public TemporaryQueue()
57   {}
58
59   /** Returns a String image of the queue. */
60   public String JavaDoc toString()
61   {
62     return "TempQueue:" + agentId;
63   }
64
65   /**
66    * API method.
67    *
68    * @exception IllegalStateException If the connection is closed or broken.
69    * @exception JMSException If the request fails for any other reason.
70    */

71   public void delete() throws JMSException
72   {
73     if (cnx == null)
74       throw new JMSSecurityException("Forbidden call as this TemporaryQueue"
75                                      + " does not belong to this connection.");
76
77     if (JoramTracing.dbgClient)
78       JoramTracing.log(JoramTracing.DEBUG, "--- " + this
79                        + ": deleting...");
80
81     // Checking the connection's receivers:
82
Session sess;
83     MessageConsumer cons;
84     for (int i = 0; i < cnx.sessions.size(); i++) {
85       sess = (Session) cnx.sessions.elementAt(i);
86       for (int j = 0; j < sess.consumers.size(); j++) {
87         cons = (MessageConsumer) sess.consumers.elementAt(j);
88         if (agentId.equals(cons.targetName))
89           throw new JMSException("Consumers still exist for this temp."
90                                  + " queue.");
91       }
92     }
93     // Sending the request to the server:
94
cnx.syncRequest(new TempDestDeleteRequest(agentId));
95
96     if (JoramTracing.dbgClient)
97       JoramTracing.log(JoramTracing.DEBUG, this + ": deleted.");
98   }
99
100   /**
101    * Returns the connection this temporary queue belongs to,
102    * <code>null</code> if not known.
103    */

104   Connection getCnx()
105   {
106     return cnx;
107   }
108
109   public Hashtable JavaDoc code() {
110      return super.code();
111   }
112
113   public static Object JavaDoc decode(Hashtable JavaDoc h) {
114     TemporaryQueue ret = new TemporaryQueue();
115     ret.setAgentId((String JavaDoc) h.get("agentId"));
116     //ret.setId(ret.getClass().getName() + ":" + agentId);
117
ret.addInstanceTable(ret.getId(), ret);
118     return ret;
119   }
120 }
121
Popular Tags