Methods Summary |
---|
private void | createEnvironment()
env.clear();
handleSsl();
handleAuth();
|
private void | formJmxServiceUrl()
//Note that the Connector Server can only be
//started on the host where this method is called
if (protocol == RemoteJmxProtocol.RMIJRMP) {
this.url = JmxServiceUrlFactory.forRmiWithJndiInAppserver(
JmxServiceUrlFactory.localhost(), this.port);
this.jconsoleurl = JmxServiceUrlFactory.forJconsoleOverRmiWithJndiInAppserver(
JmxServiceUrlFactory.localhost(), this.port);
}
|
public static int | getFreePort()Gets a free port at the time of call to this method.
The logic leverages the built in java.net.ServerSocket implementation
which binds a server socket to a free port when instantiated with
a port 0 .
Note that this method guarantees the availability of the port
only at the time of call. The method does not bind to this port.
Checking for free port can fail for several reasons which may
indicate potential problems with the system. This method acknowledges
the fact and following is the general contract:
Best effort is made to find a port which can be bound to. All
the exceptional conditions in the due course are considered SEVERE.
If any exceptional condition is experienced, 0
is returned, indicating that the method failed for some reasons and
the callers should take the corrective action. (The method need not
always throw an exception for this).
Method is synchronized on this class.
int freePort = 0;
boolean portFound = false;
ServerSocket serverSocket = null;
synchronized (JmxConnectorServerDriver.class) {
try {
/*following call normally returns the free port,
to which the ServerSocket is bound. */
serverSocket = new ServerSocket(0);
freePort = serverSocket.getLocalPort();
portFound = true;
} catch(Exception e) {
//squelch the exception
} finally {
if (!portFound) freePort = 0;
try {
if (serverSocket != null) {
serverSocket.close();
if (! serverSocket.isClosed())
throw new Exception("local exception ...");
}
} catch(Exception e) {
//squelch the exception
freePort = 0;
}
}
return freePort;
}
|
private void | handleAuth()
if (protocol == RemoteJmxProtocol.RMIJRMP ||
protocol == RemoteJmxProtocol.RMIIIOP) {
if (auth) {
if (authenticator == null) {
String msg = "Internal: The authentication is on, but the authenticator is null";
throw new IllegalArgumentException("msg");
}
env.put(JMXConnectorServer.AUTHENTICATOR, authenticator);
}
}
|
private void | handleSsl()
if (protocol == RemoteJmxProtocol.RMIJRMP)
env.put(RMIConnectorServer.RMI_SERVER_SOCKET_FACTORY_ATTRIBUTE, rmissf);
if (ssl) env.put(RMIConnectorServer.RMI_CLIENT_SOCKET_FACTORY_ATTRIBUTE, rmicsf);
|
private void | logJconsoleStartup(javax.management.remote.JMXConnectorServer cs)
logger.log(Level.INFO, "rjmx.std.address", cs.getAddress().toString());
logger.log(Level.INFO, "rjmx.std.status", "" + cs.isActive());
|
private void | logStartup(javax.management.remote.JMXConnectorServer cs)
logger.log(Level.FINE, "rjmx.lc.address", cs.getAddress().toString());
logger.log(Level.FINE, "rjmx.lc.status", "" + cs.isActive());
|
private void | prepare()
if (protocol == RemoteJmxProtocol.RMIJRMP) {
RMIServerSocketFactory rmiregssf = new RMIServerSocketFactory() {
public ServerSocket createServerSocket(int port)
throws IOException {
return new ServerSocket(
port, 0, InetAddress.getByName(bindAddress));
}
};
new RmiStubRegistryHandler(port, secureRegistry, logger, rmiregssf);
}
|
public void | setAuthentication(boolean auth)Sets Authentication value. If true, then every connection establishment
should be authenticated. This is generally done by implementation of
JMXAuthenticator interface.
this.auth = auth;
|
public void | setAuthenticator(javax.management.remote.JMXAuthenticator authenticator)Sets the Authenticator Object. This Object is responsible for
authenticating the connection.
//TODO
//if (authenticator == null)
//throw new IllegalArgumentException ("null authenticator");
this.authenticator = authenticator;
|
public void | setBindAddress(java.lang.String bindAddress)Sets the bindAddress for the inprocess rmi registry to the given value.
this.bindAddress = bindAddress;
|
public void | setLogger(java.util.logging.Logger logger)Sets the Logger
if (logger == null)
throw new IllegalArgumentException("Internal: null logger");
this.logger = logger;
|
public void | setMBeanServer(javax.management.MBeanServer mbs)Sets the MBeanServer that will be associated with the created Connector Server.
May not be null.
if (mbs == null)
throw new IllegalArgumentException ("null mbs");
this.mbs = mbs;
|
public void | setPort(int port)Sets the port to the given value.
Note that NO checks whatsoever made for the validity of port
// not going to check for port validity
this.port = port;
|
public void | setProtocol(com.sun.enterprise.admin.jmx.remote.server.rmi.RemoteJmxProtocol protocol)Sets the protocol to one of the values in RemoteJmxProtocol.
this.protocol = protocol;
|
public void | setRmiClientSocketFactory(java.rmi.server.RMIClientSocketFactory f)Sets the RMIClientSocketFactory. This is the custom client socket factory that
RMI Connector Server would use. Really useful only if ssl is set to true by
using setSsl(true). If ssl is false, this value is not passed on to the
environmental map of connector server. If ssl is true this value can not be null.
if (ssl && f == null)
throw new IllegalArgumentException("Internal: null client socket factory passed with ssl ON");
this.rmicsf = f;
|
public void | setRmiRegistrySecureFlag(boolean secure)Sets if the rmi registry is secure.
this.secureRegistry = secure;
|
public void | setRmiServerSocketFactory(java.rmi.server.RMIServerSocketFactory f)Sets the RMIServerSocketFactory. This is the custom server socket factory that
RMI Connector Server would use. Really useful only if ssl is set to true by
using setSsl(true). If ssl is false, this value is not passed on to the
environmental map of connector server. If ssl is true then this value can not be null.
if (ssl && f == null)
throw new IllegalArgumentException("Internal: null server socket factory passed with ssl ON");
this.rmissf = f;
|
public void | setSsl(boolean ssl)Sets if Transport Layer Security is on. Additional configuration is needed when ssl is on.
this.ssl = ssl;
|
public javax.management.remote.JMXConnectorServer | startConnectorServer()Starts the configured ConnectorServer. Note that the same
connector server is returned. Internally the naming service may be
started if need be. In case of RMI Connector, as of June 2004 the
rmi registry is started.
//using the jndi form everywhere as stub-form is not usable.
prepare();
formJmxServiceUrl();
createEnvironment();
final JMXConnectorServer cs =
JMXConnectorServerFactory.newJMXConnectorServer(url, env, mbs);
cs.start();
logStartup(cs);
return ( cs );
|
public javax.management.remote.JMXConnectorServer | startJconsoleConnectorServer()
// This env is ditto with the System JMX Connector Server, except SSL ClientSocketFactory.
final RMIClientSocketFactory cf = new SslRMIClientSocketFactory();
final Map jconsoleenv = new HashMap(env);
if (ssl)
jconsoleenv.put(RMIConnectorServer.RMI_CLIENT_SOCKET_FACTORY_ATTRIBUTE, cf);
final JMXConnectorServer jconsolecs =
JMXConnectorServerFactory.newJMXConnectorServer(jconsoleurl, jconsoleenv, mbs);
jconsolecs.start();
logJconsoleStartup(jconsolecs);
return ( jconsolecs );
|
public void | stopConnectorServer(javax.management.remote.JMXConnectorServer cs)A wrapper to shutdown the passed connector server. This method, in that
regard just behaves like a static method. Note that ref may not
be null.
final String cad = cs.getAddress().toString();
if (cs.isActive()) {
logger.log(Level.FINE, "rjmx.lc.stopping", cad);
cs.stop();
}
else {
final String msg = "JMX Connector Server: " + cad + " is not active";
logger.fine(msg);
}
|