com/scalagent/kjoram/TemporaryQueue.java

00001 /*
00002  * JORAM: Java(TM) Open Reliable Asynchronous Messaging
00003  * Copyright (C) 2001 - ScalAgent Distributed Technologies
00004  * Copyright (C) 1996 - Dyade
00005  *
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2.1 of the License, or any later version.
00010  * 
00011  * This library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Lesser General Public License for more details.
00015  * 
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with this library; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
00019  * USA.
00020  *
00021  * Initial developer(s): Frederic Maistre (INRIA)
00022  * Contributor(s): Nicolas Tachker (ScalAgent)
00023  */
00024 package com.scalagent.kjoram;
00025 
00026 import com.scalagent.kjoram.jms.TempDestDeleteRequest;
00027 
00028 import java.util.Vector;
00029 import java.util.Hashtable;
00030 
00031 import com.scalagent.kjoram.excepts.JMSException;
00032 import com.scalagent.kjoram.excepts.JMSSecurityException;
00033 
00034 
00035 public class TemporaryQueue extends Queue
00036 {
00038   private Connection cnx;
00039 
00047   public TemporaryQueue(String agentId, Connection cnx)
00048   {
00049     super(agentId);
00050     this.cnx = cnx;
00051   }
00052 
00056   public TemporaryQueue()
00057   {}
00058 
00060   public String toString()
00061   {
00062     return "TempQueue:" + agentId;
00063   }
00064 
00071   public void delete() throws JMSException
00072   {
00073     if (cnx == null)
00074       throw new JMSSecurityException("Forbidden call as this TemporaryQueue"
00075                                      + " does not belong to this connection.");
00076 
00077     if (JoramTracing.dbgClient)
00078       JoramTracing.log(JoramTracing.DEBUG, "--- " + this
00079                        + ": deleting...");
00080 
00081     // Checking the connection's receivers:
00082     Session sess;
00083     MessageConsumer cons;
00084     for (int i = 0; i < cnx.sessions.size(); i++) {
00085       sess = (Session) cnx.sessions.elementAt(i);
00086       for (int j = 0; j < sess.consumers.size(); j++) {
00087         cons = (MessageConsumer) sess.consumers.elementAt(j);
00088         if (agentId.equals(cons.targetName))
00089           throw new JMSException("Consumers still exist for this temp."
00090                                  + " queue.");
00091       }
00092     }
00093     // Sending the request to the server:
00094     cnx.syncRequest(new TempDestDeleteRequest(agentId));
00095 
00096     if (JoramTracing.dbgClient)
00097       JoramTracing.log(JoramTracing.DEBUG, this + ": deleted.");
00098   }
00099 
00104   Connection getCnx()
00105   {
00106     return cnx;
00107   }
00108 
00109   public Hashtable code() {
00110      return super.code();
00111   }
00112 
00113   public static Object decode(Hashtable h) {
00114     TemporaryQueue ret = new TemporaryQueue();
00115     ret.setAgentId((String) h.get("agentId"));
00116     //ret.setId(ret.getClass().getName() + ":" + agentId);
00117     ret.addInstanceTable(ret.getId(), ret);
00118     return ret;
00119   }
00120 }

Generated on Tue Sep 16 16:14:25 2008 for joram by  doxygen 1.5.0