KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > joram > client > jms > TemporaryQueue


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.client.jms;
25
26 import java.util.Vector JavaDoc;
27 import java.util.Hashtable JavaDoc;
28
29 import javax.jms.JMSException JavaDoc;
30 import javax.jms.JMSSecurityException JavaDoc;
31 import javax.naming.NamingException JavaDoc;
32
33 import org.objectweb.joram.shared.client.TempDestDeleteRequest;
34
35 import org.objectweb.util.monolog.api.BasicLevel;
36 import org.objectweb.joram.shared.JoramTracing;
37
38 /**
39  * Implements the <code>javax.jms.TemporaryQueue</code> interface.
40  */

41 public class TemporaryQueue extends Queue implements javax.jms.TemporaryQueue JavaDoc {
42   private final static String JavaDoc TMP_QUEUE_TYPE = "queue.tmp";
43
44   public static boolean isTemporaryQueue(String JavaDoc type) {
45     return Destination.isAssignableTo(type, TMP_QUEUE_TYPE);
46   }
47
48   /** The connection the queue belongs to, <code>null</code> if not known. */
49   private Connection cnx;
50
51   // Used by jndi2 SoapObjectHelper
52
public TemporaryQueue() {}
53
54   /**
55    * Constructs a temporary queue.
56    *
57    * @param agentId Identifier of the queue agent.
58    * @param cnx The connection the queue belongs to, <code>null</code> if
59    * not known.
60    */

61   public TemporaryQueue(String JavaDoc agentId, Connection cnx) {
62     super(agentId, TMP_QUEUE_TYPE);
63     this.cnx = cnx;
64   }
65
66   /** Returns a String image of the queue. */
67   public String JavaDoc toString()
68   {
69     return "TempQueue:" + agentId;
70   }
71
72   /**
73    * API method.
74    *
75    * @exception IllegalStateException If the connection is closed or broken.
76    * @exception JMSException If the request fails for any other reason.
77    */

78   public void delete() throws JMSException JavaDoc
79   {
80     if (cnx == null)
81       throw new JMSSecurityException JavaDoc("Forbidden call as this TemporaryQueue"
82                                      + " does not belong to this connection.");
83
84     if (JoramTracing.dbgClient.isLoggable(BasicLevel.DEBUG))
85       JoramTracing.dbgClient.log(BasicLevel.DEBUG, "--- " + this
86                                  + ": deleting...");
87
88     // Checking the connection's receivers:
89
cnx.checkConsumers(agentId);
90
91     // Sending the request to the server:
92
cnx.syncRequest(new TempDestDeleteRequest(agentId));
93
94     if (JoramTracing.dbgClient.isLoggable(BasicLevel.DEBUG))
95       JoramTracing.dbgClient.log(BasicLevel.DEBUG, this + ": deleted.");
96   }
97
98   /**
99    * Returns the connection this temporary queue belongs to,
100    * <code>null</code> if not known.
101    */

102   public Connection getCnx()
103   {
104     return cnx;
105   }
106 }
107
Popular Tags