| Constructor: |
public RMIConnectorServer(JMXServiceURL url,
Map environment) throws IOException {
this(url, environment, (MBeanServer) null);
}
Parameters:
url - the URL defining how to create the connector server.
Cannot be null.
environment - attributes governing the creation and
storing of the RMI object. Can be null, which is equivalent to
an empty Map.
Throws:
IllegalArgumentException - if url is null.
MalformedURLException - if url does not
conform to the syntax for an RMI connector, or if its protocol
is not recognized by this implementation. Only "rmi" and "iiop"
are valid when this constructor is used.
IOException - if the connector server cannot be created
for some reason or if it is inevitable that its start method will fail.
- exception:
IllegalArgumentException - if url is null.
- exception:
MalformedURLException - if url does not
conform to the syntax for an RMI connector, or if its protocol
is not recognized by this implementation. Only "rmi" and "iiop"
are valid when this constructor is used.
- exception:
IOException - if the connector server cannot be created
for some reason or if it is inevitable that its start method will fail.
|
public RMIConnectorServer(JMXServiceURL url,
Map environment,
MBeanServer mbeanServer) throws IOException {
this(url, environment, (RMIServerImpl) null, mbeanServer);
}
Parameters:
url - the URL defining how to create the connector server.
Cannot be null.
environment - attributes governing the creation and
storing of the RMI object. Can be null, which is equivalent to
an empty Map.
mbeanServer - the MBean server to which the new connector
server is attached, or null if it will be attached by being
registered as an MBean in the MBean server.
Throws:
IllegalArgumentException - if url is null.
MalformedURLException - if url does not
conform to the syntax for an RMI connector, or if its protocol
is not recognized by this implementation. Only "rmi" and "iiop"
are valid when this constructor is used.
IOException - if the connector server cannot be created
for some reason or if it is inevitable that its start method will fail.
- exception:
IllegalArgumentException - if url is null.
- exception:
MalformedURLException - if url does not
conform to the syntax for an RMI connector, or if its protocol
is not recognized by this implementation. Only "rmi" and "iiop"
are valid when this constructor is used.
- exception:
IOException - if the connector server cannot be created
for some reason or if it is inevitable that its start method will fail.
|
public RMIConnectorServer(JMXServiceURL url,
Map environment,
RMIServerImpl rmiServerImpl,
MBeanServer mbeanServer) throws IOException {
super(mbeanServer);
if (url == null) throw new
IllegalArgumentException("Null JMXServiceURL");
if (rmiServerImpl == null) {
final String prt = url.getProtocol();
if (prt == null || !(prt.equals("rmi") || prt.equals("iiop"))) {
final String msg = "Invalid protocol type: " + prt;
throw new MalformedURLException(msg);
}
final String urlPath = url.getURLPath();
if (!urlPath.equals("")
&& !urlPath.equals("/")
&& !urlPath.startsWith("/jndi/")) {
final String msg = "URL path must be empty or start with " +
"/jndi/";
throw new MalformedURLException(msg);
}
}
if (environment == null)
this.attributes = Collections.emptyMap();
else {
EnvHelp.checkAttributes(environment);
this.attributes = Collections.unmodifiableMap(environment);
}
this.address = url;
this.rmiServerImpl = rmiServerImpl;
}
Parameters:
url - the URL defining how to create the connector server.
Cannot be null.
environment - attributes governing the creation and
storing of the RMI object. Can be null, which is equivalent to
an empty Map.
rmiServerImpl - An implementation of the RMIServer interface,
consistent with the protocol type specified in url.
If this parameter is non null, the protocol type specified by
url is not constrained, and is assumed to be valid.
Otherwise, only "rmi" and "iiop" will be recognized.
mbeanServer - the MBean server to which the new connector
server is attached, or null if it will be attached by being
registered as an MBean in the MBean server.
Throws:
IllegalArgumentException - if url is null.
MalformedURLException - if url does not
conform to the syntax for an RMI connector, or if its protocol
is not recognized by this implementation. Only "rmi" and "iiop"
are recognized when rmiServerImpl is null.
IOException - if the connector server cannot be created
for some reason or if it is inevitable that its start method will fail.
Also see:
- start
- exception:
IllegalArgumentException - if url is null.
- exception:
MalformedURLException - if url does not
conform to the syntax for an RMI connector, or if its protocol
is not recognized by this implementation. Only "rmi" and "iiop"
are recognized when rmiServerImpl is null.
- exception:
IOException - if the connector server cannot be created
for some reason or if it is inevitable that its start method will fail.
|
| Method from javax.management.remote.rmi.RMIConnectorServer Detail: |
void bind(String jndiUrl,
Hashtable attributes,
RMIServer rmiServer,
boolean rebind) throws MalformedURLException, NamingException {
// if jndiURL is not null, we nust bind the stub to a
// directory.
InitialContext ctx =
new InitialContext(attributes);
if (rebind)
ctx.rebind(jndiUrl, rmiServer);
else
ctx.bind(jndiUrl, rmiServer);
ctx.close();
}
Bind a stub to a registry. |
protected void connectionClosed(String connectionId,
String message,
Object userData) {
super.connectionClosed(connectionId, message, userData);
}
|
protected void connectionFailed(String connectionId,
String message,
Object userData) {
super.connectionFailed(connectionId, message, userData);
}
|
protected void connectionOpened(String connectionId,
String message,
Object userData) {
super.connectionOpened(connectionId, message, userData);
}
|
static String encodeIIOPStub(RMIServer rmiServer,
Map env) throws IOException {
try {
javax.rmi.CORBA.Stub stub =
(javax.rmi.CORBA.Stub) rmiServer;
return stub._orb().object_to_string(stub);
} catch (org.omg.CORBA.BAD_OPERATION x) {
throw newIOException(x.getMessage(), x);
}
}
|
static String encodeJRMPStub(RMIServer rmiServer,
Map env) throws IOException {
ByteArrayOutputStream bout = new ByteArrayOutputStream();
ObjectOutputStream oout = new ObjectOutputStream(bout);
oout.writeObject(rmiServer);
oout.close();
byte[] bytes = bout.toByteArray();
return byteArrayToBase64(bytes);
}
|
static String encodeStub(RMIServer rmiServer,
Map env) throws IOException {
if (rmiServer instanceof javax.rmi.CORBA.Stub)
return "/ior/" + encodeIIOPStub(rmiServer, env);
else
return "/stub/" + encodeJRMPStub(rmiServer, env);
}
Returns the IOR of the given rmiServer. |
public JMXServiceURL getAddress() {
if (!isActive())
return null;
return address;
}
|
public Map getAttributes() {
Map< String, ? > map = EnvHelp.filterAttributes(attributes);
return Collections.unmodifiableMap(map);
}
|
public synchronized boolean isActive() {
return (state == STARTED);
}
|
static boolean isIiopURL(JMXServiceURL directoryURL,
boolean strict) throws MalformedURLException {
String protocol = directoryURL.getProtocol();
if (protocol.equals("rmi"))
return false;
else if (protocol.equals("iiop"))
return true;
else if (strict) {
throw new MalformedURLException("URL must have protocol " +
"\"rmi\" or \"iiop\": \"" +
protocol + "\"");
}
return false;
}
|
RMIServerImpl newServer() throws IOException {
final boolean iiop = isIiopURL(address,true);
final int port;
if (address == null)
port = 0;
else
port = address.getPort();
if (iiop)
return newIIOPServer(attributes);
else
return newJRMPServer(attributes, port);
}
Creates a new RMIServerImpl. |
public synchronized void setMBeanServerForwarder(MBeanServerForwarder mbsf) {
super.setMBeanServerForwarder(mbsf);
if (rmiServerImpl != null)
rmiServerImpl.setMBeanServer(getMBeanServer());
}
|
public synchronized void start() throws IOException {
final boolean tracing = logger.traceOn();
if (state == STARTED) {
if (tracing) logger.trace("start", "already started");
return;
} else if (state == STOPPED) {
if (tracing) logger.trace("start", "already stopped");
throw new IOException("The server has been stopped.");
}
if (getMBeanServer() == null)
throw new IllegalStateException("This connector server is not " +
"attached to an MBean server");
// Check the internal access file property to see
// if an MBeanServerForwarder is to be provided
//
if (attributes != null) {
// Check if access file property is specified
//
String accessFile =
(String) attributes.get("jmx.remote.x.access.file");
if (accessFile != null) {
// Access file property specified, create an instance
// of the MBeanServerFileAccessController class
//
MBeanServerForwarder mbsf;
try {
mbsf = new MBeanServerFileAccessController(accessFile);
} catch (IOException e) {
throw EnvHelp.initCause(
new IllegalArgumentException(e.getMessage()), e);
}
// Set the MBeanServerForwarder
//
setMBeanServerForwarder(mbsf);
}
}
try {
if (tracing) logger.trace("start", "setting default class loader");
defaultClassLoader =
EnvHelp.resolveServerClassLoader(attributes, getMBeanServer());
} catch (InstanceNotFoundException infc) {
IllegalArgumentException x = new
IllegalArgumentException("ClassLoader not found: "+infc);
throw EnvHelp.initCause(x,infc);
}
if (tracing) logger.trace("start", "setting RMIServer object");
final RMIServerImpl rmiServer;
if (rmiServerImpl != null)
rmiServer = rmiServerImpl;
else
rmiServer = newServer();
rmiServer.setMBeanServer(getMBeanServer());
rmiServer.setDefaultClassLoader(defaultClassLoader);
rmiServer.setRMIConnectorServer(this);
rmiServer.export();
try {
if (tracing) logger.trace("start", "getting RMIServer object to export");
final RMIServer objref = objectToBind(rmiServer, attributes);
if (address != null && address.getURLPath().startsWith("/jndi/")) {
final String jndiUrl = address.getURLPath().substring(6);
if (tracing)
logger.trace("start", "Using external directory: " + jndiUrl);
final boolean rebind = EnvHelp.computeBooleanFromString(
attributes,
JNDI_REBIND_ATTRIBUTE);
if (tracing)
logger.trace("start", JNDI_REBIND_ATTRIBUTE + "=" + rebind);
try {
if (tracing) logger.trace("start", "binding to " + jndiUrl);
final Hashtable usemap = EnvHelp.mapToHashtable(attributes);
bind(jndiUrl, usemap, objref, rebind);
boundJndiUrl = jndiUrl;
} catch (NamingException e) {
// fit e in the nested exception if we are on 1.4
throw newIOException("Cannot bind to URL ["+jndiUrl+"]: "
+ e, e);
}
} else {
// if jndiURL is null, we must encode the stub into the URL.
if (tracing) logger.trace("start", "Encoding URL");
encodeStubInAddress(objref, attributes);
if (tracing) logger.trace("start", "Encoded URL: " + this.address);
}
} catch (Exception e) {
try {
rmiServer.close();
} catch (Exception x) {
// OK: we are already throwing another exception
}
if (e instanceof RuntimeException)
throw (RuntimeException) e;
else if (e instanceof IOException)
throw (IOException) e;
else
throw newIOException("Got unexpected exception while " +
"starting the connector server: "
+ e, e);
}
rmiServerImpl = rmiServer;
synchronized(openedServers) {
openedServers.add(this);
}
state = STARTED;
if (tracing) {
logger.trace("start", "Connector Server Address = " + address);
logger.trace("start", "started.");
}
}
Activates the connector server, that is starts listening for
client connections. Calling this method when the connector
server is already active has no effect. Calling this method
when the connector server has been stopped will generate an
IOException.
The behavior of this method when called for the first time
depends on the parameters that were supplied at construction,
as described below.
First, an object of a subclass of RMIServerImpl is
required, to export the connector server through RMI:
- If an
RMIServerImpl was supplied to the
constructor, it is used.
- Otherwise, if the protocol part of the
JMXServiceURL supplied to the constructor was
iiop, an object of type RMIIIOPServerImpl
is created.
- Otherwise, if the
JMXServiceURL
was null, or its protocol part was rmi, an object
of type RMIJRMPServerImpl is created.
- Otherwise, the implementation can create an
implementation-specific RMIServerImpl or it can throw
MalformedURLException .
If the given address includes a JNDI directory URL as
specified in the package documentation for javax.management.remote.rmi , then this
RMIConnectorServer will bootstrap by binding the
RMIServerImpl to the given address.
If the URL path part of the JMXServiceURL was
empty or a single slash (/), then the RMI object
will not be bound to a directory. Instead, a reference to it
will be encoded in the URL path of the RMIConnectorServer
address (returned by #getAddress() ). The encodings for
rmi and iiop are described in the
package documentation for javax.management.remote.rmi .
The behavior when the URL path is neither empty nor a JNDI
directory URL, or when the protocol is neither rmi
nor iiop, is implementation defined, and may
include throwing MalformedURLException when the
connector server is created or when it is started.
|
public void stop() throws IOException {
final boolean tracing = logger.traceOn();
synchronized (this) {
if (state == STOPPED) {
if (tracing) logger.trace("stop","already stopped.");
return;
} else if (state == CREATED) {
if (tracing) logger.trace("stop","not started yet.");
}
if (tracing) logger.trace("stop", "stopping.");
state = STOPPED;
}
synchronized(openedServers) {
openedServers.remove(this);
}
IOException exception = null;
// rmiServerImpl can be null if stop() called without start()
if (rmiServerImpl != null) {
try {
if (tracing) logger.trace("stop", "closing RMI server.");
rmiServerImpl.close();
} catch (IOException e) {
if (tracing) logger.trace("stop", "failed to close RMI server: " + e);
if (logger.debugOn()) logger.debug("stop",e);
exception = e;
}
}
if (boundJndiUrl != null) {
try {
if (tracing)
logger.trace("stop",
"unbind from external directory: " + boundJndiUrl);
final Hashtable usemap = EnvHelp.mapToHashtable(attributes);
InitialContext ctx =
new InitialContext(usemap);
ctx.unbind(boundJndiUrl);
ctx.close();
} catch (NamingException e) {
if (tracing) logger.trace("stop", "failed to unbind RMI server: "+e);
if (logger.debugOn()) logger.debug("stop",e);
// fit e in as the nested exception if we are on 1.4
if (exception == null)
exception = newIOException("Cannot bind to URL: " + e, e);
}
}
if (exception != null) throw exception;
if (tracing) logger.trace("stop", "stopped");
}
Deactivates the connector server, that is, stops listening for
client connections. Calling this method will also close all
client connections that were made by this server. After this
method returns, whether normally or with an exception, the
connector server will not create any new client
connections.
Once a connector server has been stopped, it cannot be started
again.
Calling this method when the connector server has already
been stopped has no effect. Calling this method when the
connector server has not yet been started will disable the
connector server object permanently.
If closing a client connection produces an exception, that
exception is not thrown from this method. A JMXConnectionNotification is emitted from this MBean with the
connection ID of the connection that could not be closed.
Closing a connector server is a potentially slow operation.
For example, if a client machine with an open connection has
crashed, the close operation might have to wait for a network
protocol timeout. Callers that do not want to block in a close
operation should do it in a separate thread.
This method calls the method close on the connector server's RMIServerImpl
object.
If the RMIServerImpl was bound to a JNDI
directory by the start method, it is unbound
from the directory by this method.
|
public JMXConnector toJMXConnector(Map env) throws IOException {
// The serialized for of rmiServerImpl is automatically
// a RMI server stub.
if (!isActive()) throw new
IllegalStateException("Connector is not active");
// Merge maps
Map< String, Object > usemap = new HashMap< String, Object >(
(this.attributes==null)?Collections.< String, Object >emptyMap():
this.attributes);
if (env != null) {
EnvHelp.checkAttributes(env);
usemap.putAll(env);
}
usemap = EnvHelp.filterAttributes(usemap);
final RMIServer stub=(RMIServer)rmiServerImpl.toStub();
return new RMIConnector(stub, usemap);
}
Returns a client stub for this connector server. A client
stub is a serializable object whose connect method can be used to make
one new connection to this connector server.
|