1 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 ; 37 import javax.jms.JMSException ; 38 import javax.jms.Message ; 39 import java.util.logging.Logger ; 40 41 44 public class AmqDestination extends AbstractDestination 45 implements Destination 46 { 47 private static final Logger 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 _url; 54 private String _host; 55 private int _port; 56 private String _name; 57 58 private AmqClient _client; 59 60 public AmqDestination() 61 { 62 } 63 64 67 public String getName() 68 { 69 return _name; 70 } 71 72 75 public void setUrl(String 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 host; 87 String 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 112 public boolean isTopic() 113 { 114 return false; 115 } 116 117 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 137 public void send(Message message) 138 throws JMSException 139 { 140 throw new UnsupportedOperationException (); 141 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 |