📄 adminconnection.java
字号:
return result;
}
/**
* De-Activate an active persistent consumer.
*
* @param name name of the consumer
* @return boolean true if successful
*/
public boolean unregisterConsumer(String name) {
boolean success = false;
try {
ConsumerManager.instance().deleteDurableConsumerEndpoint(name);
success = true;
} catch (JMSException exception) {
//
}
return success;
}
/**
* Check to see if the given consumer is currently connected to the
* OpenJMSServer. This is only valid when in online mode.
*
* @param name The name of the onsumer.
* @return boolean True if the consumer is connected.
*/
public boolean isConnected(String name) {
return ConsumerManager.instance().isDurableConsumerActive(name);
}
/**
* Return a list of all registered destinations.
*
* @return Vector collection of strings
*/
public Vector getAllDestinations() {
Enumeration iter = null;
Vector result = new Vector();
Connection connection = null;
try {
connection = DatabaseService.getConnection();
iter = DatabaseService.getAdapter().getAllDestinations(connection);
// copy the elements into the vector
while (iter.hasMoreElements()) {
result.addElement(iter.nextElement());
}
connection.commit();
} catch (Exception exception) {
_log.error("Failed to get all destinations", exception);
SQLHelper.rollback(connection);
} finally {
SQLHelper.close(connection);
}
return result;
}
/**
* Add an administered destination with the specified name
*
* @param name destination name
* @param queue whether it is queue or a topic
* @return boolean true if successful
*/
public boolean addDestination(String name, Boolean queue) {
boolean success = false;
// create the appropriate destination object
JmsDestination destination = (queue.booleanValue())
? (JmsDestination) new JmsQueue(name)
: (JmsDestination) new JmsTopic(name);
destination.setPersistent(true);
// create the administered destination
try {
success = DestinationManager.instance().
createAdministeredDestination(destination);
} catch (JMSException exception) {
_log.error("Failed to add destination=" + name, exception);
}
return success;
}
/**
* Destroy the specified destination and all associated messsages and
* consumers. This is a very dangerous operation to execute while there are
* clients online
*
* @param name destination to destroy
* @return boolean true if successful
*/
public boolean removeDestination(String name) {
boolean success = false;
JmsDestination dest =
DestinationManager.instance().getDestination(name);
// ensure that the destination actually translates to a valid
// object.
if (dest != null) {
try {
DestinationManager.instance().deleteAdministeredDestination(
dest);
success = true;
} catch (JMSException exception) {
_log.error("Failed to remove destination=" + name, exception);
}
}
return success;
}
/**
* Check whether the specified destination exists
*
* @param name - the name of the destination to check
* @return boolean - true if it does and false otherwise
*/
public boolean destinationExists(String name) {
boolean exists = false;
DestinationManager mgr = DestinationManager.instance();
JmsDestination dest = mgr.getDestination(name);
if (dest != null) {
exists = mgr.destinationExists(dest);
}
return exists;
}
/**
* Terminate the JMS Server. If it is running as a standalone application
* then exit the application. It is running as an embedded application then
* just terminate the thread
*/
public void stopServer() {
boolean isEmbedded = false;
Configuration config = ConfigurationManager.getConfig();
Connector[] connectors = config.getConnectors().getConnector();
for (int i = 0; i < connectors.length; ++i) {
if (connectors[i].getScheme().equals(SchemeType.EMBEDDED)) {
isEmbedded = true;
break;
}
}
final boolean exit = !isEmbedded;
Runnable r = new Runnable() {
public void run() {
try {
// give the caller a chance to return before shutting
// down services
Thread.sleep(1000);
} catch (InterruptedException ignore) {
}
_log.info("Stopping all services");
ServiceManager.instance().removeAll();
if (exit) {
_log.info("Server shutdown scheduled for 5 secs");
try {
Thread.sleep(5000);
} catch (InterruptedException ignore) {
}
System.exit(0);
}
}
};
Thread t = new Thread(r);
t.start();
}
/**
* Purge all processed messages from the database
*
* @return int number of messages purged
*/
public int purgeMessages() {
return DatabaseService.getAdapter().purgeMessages();
}
/**
* Add a user with the specified name
*
* @param username the users name
* @param password the users password
* @return <code>true</code> if the user is added otherwise
* <code>false</code>
*/
public boolean addUser(String username, String password) {
return AuthenticationMgr.instance().addUser(
new User(username, password));
}
/**
* Change password for the specified user
*
* @param username the users name
* @param password the users password
* @return <code>true</code> if the password is changed otherwise
* <code>false</code>
*/
public boolean changePassword(String username, String password) {
return AuthenticationMgr.instance().updateUser(
new User(username, password));
}
/**
* Remove the specified user
*
* @param username the users name
* @return <code>true</code> if the user is removed otherwise
* <code>false</code>
*/
public boolean removeUser(String username) {
return AuthenticationMgr.instance().removeUser(
new User(username, null));
}
/**
* Return a list of all registered users.
*
* @return Vector of users
*/
public Vector getAllUsers() {
Enumeration iter = null;
Vector result = new Vector();
Connection connection = null;
try {
connection = DatabaseService.getConnection();
iter = DatabaseService.getAdapter().getAllUsers(connection);
// copy the elements into the vector
while (iter.hasMoreElements()) {
result.addElement(iter.nextElement());
}
connection.commit();
} catch (Exception exception) {
_log.error("Failed on get all users", exception);
SQLHelper.rollback(connection);
} finally {
SQLHelper.close(connection);
}
return result;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -