1 45 package org.exolab.jms.administration.net; 46 47 import java.rmi.NotBoundException ; 48 import java.rmi.RemoteException ; 49 import java.util.HashMap ; 50 import java.util.Map ; 51 import java.util.Vector ; 52 import javax.jms.JMSException ; 53 54 import org.apache.commons.logging.Log; 55 import org.apache.commons.logging.LogFactory; 56 57 import org.exolab.jms.administration.AdminConnection; 58 import org.exolab.jms.administration.JmsAdminServerIfc; 59 import org.exolab.jms.client.net.SharedORB; 60 import org.exolab.jms.net.orb.ORB; 61 import org.exolab.jms.net.registry.Registry; 62 import org.exolab.jms.server.net.RemoteJmsAdminConnectionIfc; 63 import org.exolab.jms.server.net.RemoteJmsAdminServerIfc; 64 65 66 73 public class JmsAdminConnectionImpl 74 implements JmsAdminServerIfc, AdminConnection { 75 76 79 private ORB _orb; 80 81 84 private RemoteJmsAdminConnectionIfc _connection; 85 86 87 94 public JmsAdminConnectionImpl(String url, String username, String password) 95 throws JMSException { 96 Map properties = new HashMap (); 97 properties.put(ORB.PROVIDER_URI, url); 98 if (username != null) { 99 properties.put(ORB.SECURITY_PRINCIPAL, username); 100 } 101 if (password != null) { 102 properties.put(ORB.SECURITY_CREDENTIALS, password); 103 } 104 105 Registry registry = null; 106 try { 107 _orb = SharedORB.getInstance(); 108 registry = _orb.getRegistry(properties); 109 } catch (RemoteException exception) { 110 JMSException error = new JMSException ( 111 "Failed to get registry service for URL: " + url); 112 error.setLinkedException(exception); 113 throw error; 114 } 115 116 try { 117 RemoteJmsAdminServerIfc admin = 118 (RemoteJmsAdminServerIfc) registry.lookup("admin"); 119 _connection = admin.createConnection(username, password); 120 } catch (NotBoundException exception) { 121 throw new JMSException ("Administration server is not bound in the registry for " 122 + "URL: " + url); 123 } catch (RemoteException exception) { 124 JMSException error = new JMSException ("Failed to lookup OpenJMS administration server at URL: " 125 + url); 126 error.setLinkedException(exception); 127 throw error; 128 } 129 } 130 131 public boolean addDurableConsumer(String topic, String name) 133 throws JMSException { 134 boolean result = false; 135 try { 136 result = _connection.addDurableConsumer(topic, name); 137 } catch (Exception exception) { 138 raise(exception); 139 } 140 return result; 141 } 142 143 public boolean removeDurableConsumer(String name) throws JMSException { 145 boolean result = false; 146 try { 147 result = _connection.removeDurableConsumer(name); 148 } catch (Exception exception) { 149 raise(exception); 150 } 151 return result; 152 } 153 154 public boolean durableConsumerExists(String name) throws JMSException { 156 boolean result = false; 157 try { 158 result = _connection.durableConsumerExists(name); 159 } catch (Exception exception) { 160 raise(exception); 161 } 162 return result; 163 } 164 165 public Vector getDurableConsumers(String topic) throws JMSException { 167 Vector result = null; 168 try { 169 result = _connection.getDurableConsumers(topic); 170 } catch (Exception exception) { 171 raise(exception); 172 } 173 return result; 174 } 175 176 public boolean unregisterConsumer(String name) throws JMSException { 178 boolean result = false; 179 try { 180 result = _connection.unregisterConsumer(name); 181 } catch (Exception exception) { 182 raise(exception); 183 } 184 return result; 185 } 186 187 public boolean isConnected(String name) throws JMSException { 189 boolean result = false; 190 try { 191 result = _connection.isConnected(name); 192 } catch (Exception exception) { 193 raise(exception); 194 } 195 return result; 196 } 197 198 public boolean addDestination(String destination, Boolean queue) 200 throws JMSException { 201 boolean result = false; 202 try { 203 result = _connection.addDestination(destination, queue); 204 } catch (Exception exception) { 205 raise(exception); 206 } 207 return result; 208 } 209 210 public boolean removeDestination(String name) throws JMSException { 212 boolean result = false; 213 try { 214 result = _connection.removeDestination(name); 215 } catch (Exception exception) { 216 raise(exception); 217 } 218 return result; 219 } 220 221 public boolean destinationExists(String name) throws JMSException { 223 boolean result = false; 224 try { 225 result = _connection.destinationExists(name); 226 } catch (Exception exception) { 227 raise(exception); 228 } 229 return result; 230 } 231 232 public Vector getAllDestinations() throws JMSException { 234 Vector result = null; 235 try { 236 result = _connection.getAllDestinations(); 237 } catch (Exception exception) { 238 raise(exception); 239 } 240 return result; 241 } 242 243 public int getDurableConsumerMessageCount(String topic, String name) 245 throws JMSException { 246 int result = 0; 247 try { 248 result = _connection.getDurableConsumerMessageCount(topic, name); 249 } catch (Exception exception) { 250 raise(exception); 251 } 252 return result; 253 } 254 255 public int getQueueMessageCount(String queue) throws JMSException { 257 int result = 0; 258 try { 259 result = _connection.getQueueMessageCount(queue); 260 } catch (Exception exception) { 261 raise(exception); 262 } 263 return result; 264 } 265 266 public int purgeMessages() throws JMSException { 268 int result = 0; 269 try { 270 result = _connection.purgeMessages(); 271 } catch (Exception exception) { 272 raise(exception); 273 } 274 return result; 275 } 276 277 public void stopServer() throws JMSException { 279 try { 280 _connection.stopServer(); 281 } catch (Exception exception) { 282 raise(exception); 283 } 284 } 285 286 public void close() { 288 } 289 290 public boolean addUser(String username, String password) 292 throws JMSException { 293 boolean result = false; 294 try { 295 result = _connection.addUser(username, password); 296 } catch (Exception exception) { 297 raise(exception); 298 } 299 return result; 300 } 301 302 public Vector getAllUsers() throws JMSException { 304 Vector result = null; 305 try { 306 result = _connection.getAllUsers(); 307 } catch (Exception exception) { 308 raise(exception); 309 } 310 return result; 311 } 312 313 public boolean removeUser(String username) 315 throws JMSException { 316 boolean result = false; 317 try { 318 result = _connection.removeUser(username); 319 } catch (Exception exception) { 320 raise(exception); 321 } 322 return result; 323 } 324 325 public boolean changePassword(String username, String password) 327 throws JMSException { 328 boolean result = false; 329 try { 330 result = _connection.changePassword(username, password); 331 } catch (Exception exception) { 332 raise(exception); 333 } 334 return result; 335 } 336 337 private void raise(Exception exception) throws JMSException { 338 if (exception instanceof JMSException ) { 339 throw (JMSException ) exception; 340 } else { 341 JMSException error = new JMSException (exception.getMessage()); 342 error.setLinkedException(exception); 343 throw error; 344 } 345 } 346 347 } 348 | Popular Tags |