KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > jms > amq > AmqDestination


1 /*
2  * Copyright (c) 1998-2006 Caucho Technology -- all rights reserved
3  *
4  * This file is part of Resin(R) Open Source
5  *
6  * Each copy or derived work must preserve the copyright notice and this
7  * notice unmodified.
8  *
9  * Resin Open Source is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * Resin Open Source is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
17  * of NON-INFRINGEMENT. See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with Resin Open Source; if not, write to the
22  *
23  * Free Software Foundation, Inc.
24  * 59 Temple Place, Suite 330
25  * Boston, MA 02111-1307 USA
26  *
27  * @author Scott Ferguson
28  */

29
30 package com.caucho.jms.amq;
31
32 import com.caucho.config.ConfigException;
33 import com.caucho.jms.AbstractDestination;
34 import com.caucho.util.L10N;
35
36 import javax.jms.Destination JavaDoc;
37 import javax.jms.JMSException JavaDoc;
38 import javax.jms.Message JavaDoc;
39 import java.util.logging.Logger JavaDoc;
40
41 /**
42  * An AMQ destination.
43  */

44 public class AmqDestination extends AbstractDestination
45   implements Destination
46 {
47   private static final Logger JavaDoc log
48     = Logger.getLogger(AmqDestination.class.getName());
49   private static final L10N L = new L10N(AmqDestination.class);
50
51   private int _id;
52   
53   private String JavaDoc _url;
54   private String JavaDoc _host;
55   private int _port;
56   private String JavaDoc _name;
57
58   private AmqClient _client;
59
60   public AmqDestination()
61   {
62   }
63
64   /**
65    * Gets the name.
66    */

67   public String JavaDoc getName()
68   {
69     return _name;
70   }
71
72   /**
73    * Sets the URL
74    */

75   public void setUrl(String JavaDoc url)
76     throws ConfigException
77   {
78     _url = url;
79
80     if (! url.startsWith("amq://"))
81       throw new ConfigException(L.l("AMQ URL '{0}' must start with 'amq://'",
82                     url));
83
84     url = url.substring("amq://".length());
85     int p = url.indexOf('/');
86     String JavaDoc host;
87     String JavaDoc tail;
88
89     if (p >= 0) {
90       host = url.substring(0, p);
91       tail = url.substring(p + 1);
92     }
93     else {
94       throw new ConfigException(L.l("AMQ URL '{0}' is missing destination name",
95                     _url));
96     }
97
98     p = host.indexOf(':');
99     if (p < 0)
100       throw new ConfigException(L.l("AMQ URL '{0}' is missing port name",
101                     _url));
102
103     _host = host.substring(0, p);
104     _port = Integer.parseInt(host.substring(p + 1));
105
106     _name = tail;
107   }
108
109   /**
110    * Returns true for a topic.
111    */

112   public boolean isTopic()
113   {
114     return false;
115   }
116
117   /**
118    * Initializes the JdbcQueue
119    */

120   public void init()
121     throws ConfigException
122   {
123     if (_url == null)
124       throw new ConfigException(L.l("URL must be set for an AMQ Queue or Topic."));
125
126     _client = new AmqClient(_host, _port);
127   }
128
129   protected AmqClient getClient()
130   {
131     return _client;
132   }
133
134   /**
135    * Sends the message to the queue.
136    */

137   public void send(Message JavaDoc message)
138     throws JMSException JavaDoc
139   {
140     throw new UnsupportedOperationException JavaDoc();
141     /*
142     try {
143       AmqClient client = getClient();
144
145       AmqChannel channel = client.openChannel();
146       try {
147     System.out.println("CHANNEL: " + channel);
148       } finally {
149     channel.close();
150       }
151     } catch (IOException e) {
152       throw new JMSExceptionWrapper(e);
153     }
154     */

155   }
156
157   public void close()
158   {
159     _client.close();
160   }
161
162   public void finalize()
163   {
164     close();
165   }
166 }
167
168
Popular Tags