View Javadoc
1 /*** 2 * Redistribution and use of this software and associated documentation 3 * ("Software"), with or without modification, are permitted provided 4 * that the following conditions are met: 5 * 6 * 1. Redistributions of source code must retain copyright 7 * statements and notices. Redistributions must also contain a 8 * copy of this document. 9 * 10 * 2. Redistributions in binary form must reproduce the 11 * above copyright notice, this list of conditions and the 12 * following disclaimer in the documentation and/or other 13 * materials provided with the distribution. 14 * 15 * 3. The name "Exolab" must not be used to endorse or promote 16 * products derived from this Software without prior written 17 * permission of Exoffice Technologies. For written permission, 18 * please contact info@exolab.org. 19 * 20 * 4. Products derived from this Software may not be called "Exolab" 21 * nor may "Exolab" appear in their names without prior written 22 * permission of Exoffice Technologies. Exolab is a registered 23 * trademark of Exoffice Technologies. 24 * 25 * 5. Due credit should be given to the Exolab Project 26 * (http://www.exolab.org/). 27 * 28 * THIS SOFTWARE IS PROVIDED BY EXOFFICE TECHNOLOGIES AND CONTRIBUTORS 29 * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT 30 * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 31 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 32 * EXOFFICE TECHNOLOGIES OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 33 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 34 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 35 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 36 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 37 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 38 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 39 * OF THE POSSIBILITY OF SUCH DAMAGE. 40 * 41 * Copyright 2000-2001,2003 (C) Exoffice Technologies Inc. All Rights Reserved. 42 * 43 * $Id: RmiJmsAdminConnection.java,v 1.14 2003/08/07 13:32:48 tanderson Exp $ 44 * 45 * Date Author Changes 46 * $Date jimm Created 47 */ 48 package org.exolab.jms.administration.rmi; 49 50 import java.rmi.Naming; 51 import java.util.Vector; 52 53 import javax.jms.JMSException; 54 55 import org.apache.commons.logging.Log; 56 import org.apache.commons.logging.LogFactory; 57 58 import org.exolab.jms.administration.AdminConnection; 59 import org.exolab.jms.administration.JmsAdminServerIfc; 60 import org.exolab.jms.server.rmi.RemoteJmsAdminConnectionIfc; 61 import org.exolab.jms.server.rmi.RemoteJmsAdminServerIfc; 62 import org.exolab.jms.util.UUID; 63 64 65 /*** 66 * This class is repsonsible for an admin connection to the RMI server 67 * 68 * @version $Revision: 1.14 $ $Date: 2003/08/07 13:32:48 $ 69 * @author <a href="mailto:mourikis@intalio.com">Jim Mourikis</a> 70 * @see org.exolab.jms.server.rmi.RmiJmsAdminServer 71 * @see org.exolab.jms.administration.AdminConnectionFactory 72 */ 73 public class RmiJmsAdminConnection 74 implements JmsAdminServerIfc, AdminConnection { 75 76 /*** 77 * The rmi connection to the OpenJMS server 78 */ 79 private RemoteJmsAdminServerIfc _delegate = null; 80 81 /*** 82 * The rmi connection to the OpenJMS server 83 */ 84 private RemoteJmsAdminConnectionIfc _admin = null; 85 86 /*** 87 * The logger 88 */ 89 private static final Log _log = 90 LogFactory.getLog(RmiJmsAdminConnection.class); 91 92 /*** 93 * The server host address 94 */ 95 private String _serverAddress; 96 97 /*** 98 * The server name 99 */ 100 private String _name; 101 102 /*** 103 * The port number the server is listening to 104 */ 105 private int _port; 106 107 /*** 108 * The clientId 109 */ 110 private String _clientId = null; 111 112 113 /*** 114 * Create the connection to the server, using the specified host, port 115 * and registry binding 116 * 117 * @param host the server host 118 * @param port the server port 119 * @param name the name of the admin server, bound in the registry. May 120 * be null 121 */ 122 public RmiJmsAdminConnection(String host, int port, String name, 123 String username, String password) 124 throws JMSException { 125 _serverAddress = host; 126 _port = port; 127 _name = name; 128 _clientId = UUID.next(); 129 130 connect(_clientId, username, password); 131 } 132 133 // implementation of JmsAdminServerIfc.addDurableConsumer 134 public boolean addDurableConsumer(String topic, String name) 135 throws JMSException { 136 boolean result = false; 137 try { 138 result = _admin.addDurableConsumer(topic, name); 139 } catch (Exception exception) { 140 raise(exception); 141 } 142 return result; 143 } 144 145 // implementation of JmsAdminServerIfc.removeDurableConsumer 146 public boolean removeDurableConsumer(String name) throws JMSException { 147 boolean result = false; 148 try { 149 result = _admin.removeDurableConsumer(name); 150 } catch (Exception exception) { 151 raise(exception); 152 } 153 return result; 154 } 155 156 // implementation of JmsAdminServerIfc.durableConsumerExists 157 public boolean durableConsumerExists(String name) throws JMSException { 158 boolean result = false; 159 try { 160 result = _admin.durableConsumerExists(name); 161 } catch (Exception exception) { 162 raise(exception); 163 } 164 return result; 165 } 166 167 // implementation of JmsAdminServerIfc.getDurableConsumers 168 public Vector getDurableConsumers(String topic) throws JMSException { 169 Vector result = null; 170 try { 171 result = _admin.getDurableConsumers(topic); 172 } catch (Exception exception) { 173 raise(exception); 174 } 175 return result; 176 } 177 178 // implementation of JmsAdminServerIfc.unregisterConsumer 179 public boolean unregisterConsumer(String name) throws JMSException { 180 boolean result = false; 181 try { 182 result = _admin.unregisterConsumer(name); 183 } catch (Exception exception) { 184 raise(exception); 185 } 186 return result; 187 } 188 189 // implementation of JmsAdminServerIfc.isConnected 190 public boolean isConnected(String name) throws JMSException { 191 boolean result = false; 192 try { 193 result = _admin.isConnected(name); 194 } catch (Exception exception) { 195 raise(exception); 196 } 197 return result; 198 } 199 200 // implementation of JmsAdminServerIfc.addDestination 201 public boolean addDestination(String destination, Boolean queue) 202 throws JMSException { 203 boolean result = false; 204 try { 205 result = _admin.addDestination(destination, queue); 206 } catch (Exception exception) { 207 raise(exception); 208 } 209 return result; 210 } 211 212 // implementation of JmsAdminServerIfc.removeDestination 213 public boolean removeDestination(String name) throws JMSException { 214 boolean result = false; 215 try { 216 result = _admin.removeDestination(name); 217 } catch (Exception exception) { 218 raise(exception); 219 } 220 return result; 221 } 222 223 // implementation of JmsAdminServerIfc.destinationExists 224 public boolean destinationExists(String name) throws JMSException { 225 boolean result = false; 226 try { 227 result = _admin.destinationExists(name); 228 } catch (Exception exception) { 229 raise(exception); 230 } 231 return result; 232 } 233 234 // implementation of JmsAdminServerIfc.getAllDestinations 235 public Vector getAllDestinations() throws JMSException { 236 Vector result = null; 237 try { 238 result = _admin.getAllDestinations(); 239 } catch (Exception exception) { 240 raise(exception); 241 } 242 return result; 243 } 244 245 // implementation of JmsAdminServerIfc.getDurableConsumerMessageCount 246 public int getDurableConsumerMessageCount(String topic, String name) 247 throws JMSException { 248 int result = 0; 249 try { 250 result = _admin.getDurableConsumerMessageCount(topic, name); 251 } catch (Exception exception) { 252 raise(exception); 253 } 254 return result; 255 } 256 257 // implementation of JmsAdminServerIfc.getDurableConsumerMessageCount 258 public int getQueueMessageCount(String queue) throws JMSException { 259 int result = 0; 260 try { 261 result = _admin.getQueueMessageCount(queue); 262 } catch (Exception exception) { 263 raise(exception); 264 } 265 return result; 266 } 267 268 // implementation of JmsAdminServerIfc.purgeMessages 269 public int purgeMessages() throws JMSException { 270 int result = 0; 271 try { 272 result = _admin.purgeMessages(); 273 } catch (Exception exception) { 274 raise(exception); 275 } 276 return result; 277 } 278 279 // implementation of JmsAdminServerIfc.stopServer 280 public void stopServer() throws JMSException { 281 try { 282 _admin.stopServer(); 283 } catch (Exception exception) { 284 raise(exception); 285 } 286 } 287 288 // implementation of JmsAdminServerIfc.close 289 public void close() { 290 _admin = null; 291 } 292 293 protected void openConnection() throws JMSException { 294 try { 295 if (_name == null) { 296 _name = "JmsAdminServer"; 297 } 298 String url = "//" + _serverAddress + ":" + _port + "/" + _name; 299 _delegate = (RemoteJmsAdminServerIfc) Naming.lookup(url); 300 } catch (Exception exception) { 301 raise(exception); 302 } 303 } 304 305 /*** 306 * Authenticates username/password 307 * 308 * @param clientId the client's id 309 * @param username the user's name 310 * @param password the user's password 311 * @throws JMSException if the client cannot be authenticated 312 */ 313 private void connect(String clientId, String username, String password) 314 throws JMSException { 315 openConnection(); 316 317 try { 318 _admin = getDelegate(). 319 createConnection(clientId, username, password); 320 } catch (Exception exception) { 321 raise(exception); 322 } 323 } 324 325 private void raise(Exception exception) throws JMSException { 326 if (exception instanceof JMSException) { 327 throw (JMSException) exception; 328 } else { 329 JMSException error = new JMSException(exception.getMessage()); 330 error.setLinkedException(exception); 331 throw error; 332 } 333 } 334 335 // implementation of JmsAdminServerIfc.addUser 336 public boolean addUser(String username, String password) 337 throws JMSException { 338 boolean result = false; 339 try { 340 result = _admin.addUser(username, password); 341 } catch (Exception exception) { 342 raise(exception); 343 } 344 return result; 345 } 346 347 // implementation of JmsAdminServerIfc.getAllUsers 348 public Vector getAllUsers() throws JMSException { 349 Vector result = null; 350 try { 351 result = _admin.getAllUsers(); 352 } catch (Exception exception) { 353 raise(exception); 354 } 355 return result; 356 } 357 358 // implementation of JmsAdminServerIfc.removeUser 359 public boolean removeUser(String username) 360 throws JMSException { 361 boolean result = false; 362 try { 363 result = _admin.removeUser(username); 364 } catch (Exception exception) { 365 raise(exception); 366 } 367 return result; 368 } 369 370 // implementation of JmsAdminServerIfc.changePassword 371 public boolean changePassword(String username, String password) 372 throws JMSException { 373 boolean result = false; 374 try { 375 result = _admin.changePassword(username, password); 376 } catch (Exception exception) { 377 raise(exception); 378 } 379 return result; 380 } 381 382 /*** Getter for property _delegate. 383 * @return Value of property _delegate. 384 * 385 */ 386 public RemoteJmsAdminServerIfc getDelegate() { 387 return _delegate; 388 } 389 390 } //-- RmiJmsAdminConnection

This page was automatically generated by Maven