📄 rmijmsadminconnection.java
字号:
/**
* Redistribution and use of this software and associated documentation
* ("Software"), with or without modification, are permitted provided
* that the following conditions are met:
*
* 1. Redistributions of source code must retain copyright
* statements and notices. Redistributions must also contain a
* copy of this document.
*
* 2. Redistributions in binary form must reproduce the
* above copyright notice, this list of conditions and the
* following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* 3. The name "Exolab" must not be used to endorse or promote
* products derived from this Software without prior written
* permission of Exoffice Technologies. For written permission,
* please contact info@exolab.org.
*
* 4. Products derived from this Software may not be called "Exolab"
* nor may "Exolab" appear in their names without prior written
* permission of Exoffice Technologies. Exolab is a registered
* trademark of Exoffice Technologies.
*
* 5. Due credit should be given to the Exolab Project
* (http://www.exolab.org/).
*
* THIS SOFTWARE IS PROVIDED BY EXOFFICE TECHNOLOGIES AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
* NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* EXOFFICE TECHNOLOGIES OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Copyright 2000-2001,2003 (C) Exoffice Technologies Inc. All Rights Reserved.
*
* $Id: RmiJmsAdminConnection.java,v 1.14 2003/08/07 13:32:48 tanderson Exp $
*
* Date Author Changes
* $Date jimm Created
*/
package org.exolab.jms.administration.rmi;
import java.rmi.Naming;
import java.util.Vector;
import javax.jms.JMSException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.exolab.jms.administration.AdminConnection;
import org.exolab.jms.administration.JmsAdminServerIfc;
import org.exolab.jms.server.rmi.RemoteJmsAdminConnectionIfc;
import org.exolab.jms.server.rmi.RemoteJmsAdminServerIfc;
import org.exolab.jms.util.UUID;
/**
* This class is repsonsible for an admin connection to the RMI server
*
* @version $Revision: 1.14 $ $Date: 2003/08/07 13:32:48 $
* @author <a href="mailto:mourikis@intalio.com">Jim Mourikis</a>
* @see org.exolab.jms.server.rmi.RmiJmsAdminServer
* @see org.exolab.jms.administration.AdminConnectionFactory
*/
public class RmiJmsAdminConnection
implements JmsAdminServerIfc, AdminConnection {
/**
* The rmi connection to the OpenJMS server
*/
private RemoteJmsAdminServerIfc _delegate = null;
/**
* The rmi connection to the OpenJMS server
*/
private RemoteJmsAdminConnectionIfc _admin = null;
/**
* The logger
*/
private static final Log _log =
LogFactory.getLog(RmiJmsAdminConnection.class);
/**
* The server host address
*/
private String _serverAddress;
/**
* The server name
*/
private String _name;
/**
* The port number the server is listening to
*/
private int _port;
/**
* The clientId
*/
private String _clientId = null;
/**
* Create the connection to the server, using the specified host, port
* and registry binding
*
* @param host the server host
* @param port the server port
* @param name the name of the admin server, bound in the registry. May
* be null
*/
public RmiJmsAdminConnection(String host, int port, String name,
String username, String password)
throws JMSException {
_serverAddress = host;
_port = port;
_name = name;
_clientId = UUID.next();
connect(_clientId, username, password);
}
// implementation of JmsAdminServerIfc.addDurableConsumer
public boolean addDurableConsumer(String topic, String name)
throws JMSException {
boolean result = false;
try {
result = _admin.addDurableConsumer(topic, name);
} catch (Exception exception) {
raise(exception);
}
return result;
}
// implementation of JmsAdminServerIfc.removeDurableConsumer
public boolean removeDurableConsumer(String name) throws JMSException {
boolean result = false;
try {
result = _admin.removeDurableConsumer(name);
} catch (Exception exception) {
raise(exception);
}
return result;
}
// implementation of JmsAdminServerIfc.durableConsumerExists
public boolean durableConsumerExists(String name) throws JMSException {
boolean result = false;
try {
result = _admin.durableConsumerExists(name);
} catch (Exception exception) {
raise(exception);
}
return result;
}
// implementation of JmsAdminServerIfc.getDurableConsumers
public Vector getDurableConsumers(String topic) throws JMSException {
Vector result = null;
try {
result = _admin.getDurableConsumers(topic);
} catch (Exception exception) {
raise(exception);
}
return result;
}
// implementation of JmsAdminServerIfc.unregisterConsumer
public boolean unregisterConsumer(String name) throws JMSException {
boolean result = false;
try {
result = _admin.unregisterConsumer(name);
} catch (Exception exception) {
raise(exception);
}
return result;
}
// implementation of JmsAdminServerIfc.isConnected
public boolean isConnected(String name) throws JMSException {
boolean result = false;
try {
result = _admin.isConnected(name);
} catch (Exception exception) {
raise(exception);
}
return result;
}
// implementation of JmsAdminServerIfc.addDestination
public boolean addDestination(String destination, Boolean queue)
throws JMSException {
boolean result = false;
try {
result = _admin.addDestination(destination, queue);
} catch (Exception exception) {
raise(exception);
}
return result;
}
// implementation of JmsAdminServerIfc.removeDestination
public boolean removeDestination(String name) throws JMSException {
boolean result = false;
try {
result = _admin.removeDestination(name);
} catch (Exception exception) {
raise(exception);
}
return result;
}
// implementation of JmsAdminServerIfc.destinationExists
public boolean destinationExists(String name) throws JMSException {
boolean result = false;
try {
result = _admin.destinationExists(name);
} catch (Exception exception) {
raise(exception);
}
return result;
}
// implementation of JmsAdminServerIfc.getAllDestinations
public Vector getAllDestinations() throws JMSException {
Vector result = null;
try {
result = _admin.getAllDestinations();
} catch (Exception exception) {
raise(exception);
}
return result;
}
// implementation of JmsAdminServerIfc.getDurableConsumerMessageCount
public int getDurableConsumerMessageCount(String topic, String name)
throws JMSException {
int result = 0;
try {
result = _admin.getDurableConsumerMessageCount(topic, name);
} catch (Exception exception) {
raise(exception);
}
return result;
}
// implementation of JmsAdminServerIfc.getDurableConsumerMessageCount
public int getQueueMessageCount(String queue) throws JMSException {
int result = 0;
try {
result = _admin.getQueueMessageCount(queue);
} catch (Exception exception) {
raise(exception);
}
return result;
}
// implementation of JmsAdminServerIfc.purgeMessages
public int purgeMessages() throws JMSException {
int result = 0;
try {
result = _admin.purgeMessages();
} catch (Exception exception) {
raise(exception);
}
return result;
}
// implementation of JmsAdminServerIfc.stopServer
public void stopServer() throws JMSException {
try {
_admin.stopServer();
} catch (Exception exception) {
raise(exception);
}
}
// implementation of JmsAdminServerIfc.close
public void close() {
_admin = null;
}
protected void openConnection() throws JMSException {
try {
if (_name == null) {
_name = "JmsAdminServer";
}
String url = "//" + _serverAddress + ":" + _port + "/" + _name;
_delegate = (RemoteJmsAdminServerIfc) Naming.lookup(url);
} catch (Exception exception) {
raise(exception);
}
}
/**
* Authenticates username/password
*
* @param clientId the client's id
* @param username the user's name
* @param password the user's password
* @throws JMSException if the client cannot be authenticated
*/
private void connect(String clientId, String username, String password)
throws JMSException {
openConnection();
try {
_admin = getDelegate().
createConnection(clientId, username, password);
} catch (Exception exception) {
raise(exception);
}
}
private void raise(Exception exception) throws JMSException {
if (exception instanceof JMSException) {
throw (JMSException) exception;
} else {
JMSException error = new JMSException(exception.getMessage());
error.setLinkedException(exception);
throw error;
}
}
// implementation of JmsAdminServerIfc.addUser
public boolean addUser(String username, String password)
throws JMSException {
boolean result = false;
try {
result = _admin.addUser(username, password);
} catch (Exception exception) {
raise(exception);
}
return result;
}
// implementation of JmsAdminServerIfc.getAllUsers
public Vector getAllUsers() throws JMSException {
Vector result = null;
try {
result = _admin.getAllUsers();
} catch (Exception exception) {
raise(exception);
}
return result;
}
// implementation of JmsAdminServerIfc.removeUser
public boolean removeUser(String username)
throws JMSException {
boolean result = false;
try {
result = _admin.removeUser(username);
} catch (Exception exception) {
raise(exception);
}
return result;
}
// implementation of JmsAdminServerIfc.changePassword
public boolean changePassword(String username, String password)
throws JMSException {
boolean result = false;
try {
result = _admin.changePassword(username, password);
} catch (Exception exception) {
raise(exception);
}
return result;
}
/** Getter for property _delegate.
* @return Value of property _delegate.
*
*/
public RemoteJmsAdminServerIfc getDelegate() {
return _delegate;
}
} //-- RmiJmsAdminConnection
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -