JmxConnectionHandler.java revision ea1068c292e9b341af6d6b563cd8988a96be20a9
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at legal-notices/CDDLv1_0.txt.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information:
* Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*
*
* Copyright 2006-2009 Sun Microsystems, Inc.
* Portions Copyright 2013-2015 ForgeRock AS
*/
/**
* This class defines a connection handler that will be used for
* communicating with administrative clients over JMX. The connection
* handler is responsible for accepting new connections, reading
* requests from the clients and parsing them as operations. A single
* request handler should be used.
*/
public final class JmxConnectionHandler extends
ConnectionHandler<JMXConnectionHandlerCfg> implements
/**
* Key that may be placed into a JMX connection environment map to
* provide a custom {@code javax.net.ssl.TrustManager} array
* for a connection.
*/
public static final String TRUST_MANAGER_ARRAY_KEY =
"org.opends.server.protocol.jmx.ssl.trust.manager.array";
/** The list of active client connection. */
/** The current configuration state. */
private JMXConnectionHandlerCfg currentConfig;
/** The JMX RMI Connector associated with the Connection handler. */
private RmiConnector rmiConnector;
/** The unique name for this connection handler. */
private String connectionHandlerName;
/** The protocol used to communicate with clients. */
/** The set of listeners for this connection handler. */
/**
* Creates a new instance of this JMX connection handler. It must be
* initialized before it may be used.
*/
public JmxConnectionHandler() {
super("JMX Connection Handler Thread");
}
/**
* {@inheritDoc}
*/
// Determine whether or not the RMI connection needs restarting.
boolean rmiConnectorRestart = false;
boolean portChanged = false;
rmiConnectorRestart = true;
portChanged = true;
}
{
rmiConnectorRestart = true;
}
rmiConnectorRestart = true;
}
config.getSSLCertNickname())) ||
currentConfig.getSSLCertNickname()))) {
rmiConnectorRestart = true;
}
// Save the configuration.
// Restart the connector if required.
if (rmiConnectorRestart) {
protocol = "JMX+SSL";
} else {
protocol = "JMX";
}
try
{
}
catch (RuntimeException e)
{
}
}
// If the port number has changed then update the JMX port information
// stored in the system properties.
if (portChanged)
{
}
return ccr;
}
/**
* {@inheritDoc}
*/
// Make sure that we don't get notified of any more changes.
// We should also close the RMI registry.
}
/**
* Retrieves the set of active client connections that have been
* established through this connection handler.
*
* @return The set of active client connections that have been
* established through this connection handler.
*/
return connectionList;
}
/**
* Retrieves the DN of the configuration entry with which this alert
* generator is associated.
*
* @return The DN of the configuration entry with which this alert
* generator is associated.
*/
public DN getComponentEntryDN() {
return currentConfig.dn();
}
/**
* Retrieves the DN of the key manager provider that should be used
* for operations associated with this connection handler which need
* access to a key manager.
*
* @return The DN of the key manager provider that should be used
* for operations associated with this connection handler
* which need access to a key manager, or {@code null} if no
* key manager provider has been configured for this
* connection handler.
*/
public DN getKeyManagerProviderDN() {
return currentConfig.getKeyManagerProviderDN();
}
/**
* Get the JMX connection handler's listen port.
*
* @return Returns the JMX connection handler's listen port.
*/
public int getListenPort() {
return currentConfig.getListenPort();
}
/**
* Get the JMX connection handler's rmi port.
*
* @return Returns the JMX connection handler's rmi port.
*/
public int getRmiPort() {
return currentConfig.getRmiPort();
}
/**
* Get the JMX connection handler's RMI connector.
*
* @return Returns the JMX connection handler's RMI connector.
*/
public RmiConnector getRMIConnector() {
return rmiConnector;
}
/**
* {@inheritDoc}
*/
public String getShutdownListenerName() {
return connectionHandlerName;
}
/**
* Retrieves the nickname of the server certificate that should be
* used in conjunction with this JMX connection handler.
*
* @return The nickname of the server certificate that should be
* used in conjunction with this JMX connection handler.
*/
public String getSSLServerCertNickname() {
return currentConfig.getSSLCertNickname();
}
/**
* {@inheritDoc}
*/
{
// Configuration is ok.
{
throw new InitializationException(message);
}
protocol = "JMX+SSL";
} else {
protocol = "JMX";
}
// Create a system property to store the JMX port the server is
// listening to. This information can be displayed with jinfo.
// Create the associated RMI Connector.
// Register this as a change listener.
config.addJMXChangeListener(this);
}
/**
* {@inheritDoc}
*/
public String getConnectionHandlerName() {
return connectionHandlerName;
}
/**
* {@inheritDoc}
*/
public String getProtocol() {
return protocol;
}
/**
* {@inheritDoc}
*/
return listeners;
}
/**
* {@inheritDoc}
*/
{
if ((currentConfig == null ||
{
return false;
}
(currentConfig == null ||
{
return false;
}
}
/**
* Attempt to bind to the port to verify whether the connection
* handler will be able to start.
* @return true is the port is free to use, false otherwise.
*/
try {
}
} catch (Exception e) {
return false;
}
return true;
}
/**
* {@inheritDoc}
*/
public boolean isConfigurationChangeAcceptable(
// All validation is performed by the admin framework.
return true;
}
/**
* Determines whether or not clients are allowed to connect over JMX
* using SSL.
*
* @return Returns {@code true} if clients are allowed to
* connect over JMX using SSL.
*/
public boolean isUseSSL() {
return currentConfig.isUseSSL();
}
/**
* {@inheritDoc}
*/
// We should also close the RMI registry.
}
/**
* Registers a client connection with this JMX connection handler.
*
* @param connection
* The client connection.
*/
}
/**
* Unregisters a client connection from this JMX connection handler.
*
* @param connection
* The client connection.
*/
}
/**
* {@inheritDoc}
*/
public void run() {
try
{
}
catch (RuntimeException ignore)
{
// Already caught and logged
}
}
/**
* {@inheritDoc}
*/
}
}