/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* <p>An RMI object representing a connector server. Remote clients
* can make connections using the {@link #newClient(Object)} method. This
* method returns an RMI object representing the connection.</p>
*
* <p>User code does not usually reference this class directly.
* RMI connection servers are usually created with the class {@link
* RMIConnectorServer}. Remote clients usually create connections
* either with {@link javax.management.remote.JMXConnectorFactory}
* or by instantiating {@link RMIConnector}.</p>
*
* <p>This is an abstract class. Concrete subclasses define the
* details of the client connection objects, such as whether they use
* JRMP or IIOP.</p>
*
* @since 1.5
*/
/**
* <p>Constructs a new <code>RMIServerImpl</code>.</p>
*
* @param env the environment containing attributes for the new
* <code>RMIServerImpl</code>. Can be null, which is equivalent
* to an empty Map.
*/
}
throws IOException {
this.connServer = connServer;
}
/**
* <p>Exports this RMI object.</p>
*
* @exception IOException if this RMI object cannot be exported.
*/
/**
* Returns a remotable stub for this server object.
* @return a remotable stub.
* @exception IOException if the stub cannot be obtained - e.g the
* RMIServerImpl has not been exported yet.
**/
/**
* <p>Sets the default <code>ClassLoader</code> for this connector
* server. New client connections will use this classloader.
* Existing client connections are unaffected.</p>
*
* @param cl the new <code>ClassLoader</code> to be used by this
* connector server.
*
* @see #getDefaultClassLoader
*/
}
/**
* <p>Gets the default <code>ClassLoader</code> used by this connector
* server.</p>
*
* @return the default <code>ClassLoader</code> used by this
* connector server.</p>
*
* @see #setDefaultClassLoader
*/
return cl;
}
/**
* <p>Sets the <code>MBeanServer</code> to which this connector
* server is attached. New client connections will interact
* with this <code>MBeanServer</code>. Existing client connections are
* unaffected.</p>
*
* @param mbs the new <code>MBeanServer</code>. Can be null, but
* new client connections will be refused as long as it is.
*
* @see #getMBeanServer
*/
this.mbeanServer = mbs;
}
/**
* <p>The <code>MBeanServer</code> to which this connector server
* is attached. This is the last value passed to {@link
* #setMBeanServer} on this object, or null if that method has
* never been called.</p>
*
* @return the <code>MBeanServer</code> to which this connector
* is attached.
*
* @see #setMBeanServer
*/
return mbeanServer;
}
// Expected format is: "protocol-version implementation-name"
try {
return "1.0 java_runtime_" +
} catch (SecurityException e) {
return "1.0 ";
}
}
/**
* <p>Creates a new client connection. This method calls {@link
* #makeClient makeClient} and adds the returned client connection
* object to an internal list. When this
* <code>RMIServerImpl</code> is shut down via its {@link
* #close()} method, the {@link RMIConnection#close() close()}
* method of each object remaining in the list is called.</p>
*
* <p>The fact that a client connection object is in this internal
* list does not prevent it from being garbage collected.</p>
*
* @param credentials this object specifies the user-defined
* credentials to be passed in to the server in order to
* authenticate the caller before creating the
* <code>RMIConnection</code>. Can be null.
*
* @return the newly-created <code>RMIConnection</code>. This is
* usually the object created by <code>makeClient</code>, though
* an implementation may choose to wrap that object in another
* object implementing <code>RMIConnection</code>.
*
* @exception IOException if the new client object cannot be
* created or exported.
*
* @exception SecurityException if the given credentials do not allow
* the server to authenticate the user successfully.
*
* @exception IllegalStateException if {@link #getMBeanServer()}
* is null.
*/
return doNewClient(credentials);
}
/**
* This method could be overridden by subclasses defined in this package
* to perform additional operations specific to the underlying transport
* before creating the new client connection.
*/
if (getMBeanServer() == null)
throw new IllegalStateException("Not attached to an MBean server");
if (authenticator == null) {
/*
* Create the JAAS-based authenticator only if authentication
* has been enabled
*/
}
}
if (authenticator != null) {
try {
} catch (SecurityException e) {
throw e;
}
}
if (tracing) {
}
if (tracing)
synchronized (clientList) {
}
synchronized (clientList) {
// can be removed only by a JMXConnectionNotification listener
throw new IOException("The connection is refused.");
}
}
if (tracing)
return client;
}
/**
* <p>Creates a new client connection. This method is called by
* the public method {@link #newClient(Object)}.</p>
*
* @param connectionId the ID of the new connection. Every
* connection opened by this connector server will have a
* different ID. The behavior is unspecified if this parameter is
* null.
*
* @param subject the authenticated subject. Can be null.
*
* @return the newly-created <code>RMIConnection</code>.
*
* @exception IOException if the new client object cannot be
* created or exported.
*/
throws IOException;
/**
* <p>Closes a client connection made by {@link #makeClient makeClient}.
*
* @param client a connection previously returned by
* <code>makeClient</code> on which the <code>closeClient</code>
* method has not previously been called. The behavior is
* unspecified if these conditions are violated, including the
* case where <code>client</code> is null.
*
* @exception IOException if the client connection cannot be
* closed.
*/
throws IOException;
/**
* <p>Returns the protocol string for this object. The string is
*
* @return the protocol string for this object.
*/
/**
* <p>Method called when a client connection created by {@link
* #makeClient makeClient} is closed. A subclass that defines
* <code>makeClient</code> must arrange for this method to be
* called when the resultant object's {@link RMIConnection#close()
* close} method is called. This enables it to be removed from
* the <code>RMIServerImpl</code>'s list of connections. It is
* not an error for <code>client</code> not to be in that
* list.</p>
*
* <p>After removing <code>client</code> from the list of
* connections, this method calls {@link #closeClient
* closeClient(client)}.</p>
*
* @param client the client connection that has been closed.
*
* @exception IOException if {@link #closeClient} throws this
* exception.
*
* @exception NullPointerException if <code>client</code> is null.
*/
throw new NullPointerException("Null client");
synchronized (clientList) {
break;
}
}
/* It is not a bug for this loop not to find the client. In
our close() method, we remove a client from the list before
calling its close() method. */
}
"Client connection closed", null);
}
/**
* <p>Closes this connection server. This method first calls the
* {@link #closeServer()} method so that no new client connections
* will be accepted. Then, for each remaining {@link
* RMIConnection} object returned by {@link #makeClient
* makeClient}, its {@link RMIConnection#close() close} method is
* called.</p>
*
* <p>The behavior when this method is called more than once is
* unspecified.</p>
*
* <p>If {@link #closeServer()} throws an
* <code>IOException</code>, the individual connections are
* nevertheless closed, and then the <code>IOException</code> is
* thrown from this method.</p>
*
* <p>If {@link #closeServer()} returns normally but one or more
* of the individual connections throws an
* <code>IOException</code>, then, after closing all the
* connections, one of those <code>IOException</code>s is thrown
* from this method. If more than one connection throws an
* <code>IOException</code>, it is unspecified which one is thrown
* from this method.</p>
*
* @exception IOException if {@link #closeServer()} or one of the
* {@link RMIConnection#close()} calls threw
* <code>IOException</code>.
*/
try {
closeServer();
} catch (IOException e) {
ioException = e;
}
// Loop to close all clients
while (true) {
synchronized (clientList) {
break;
/* Loop until we find a non-null client. Because we called
dropDeadReferences(), this will usually be the first
element of the list, but a garbage collection could have
happened in between. */
try {
} catch (IOException e) {
if (tracing)
if (ioException == null)
ioException = e;
}
break;
}
}
}
}
if(notifBuffer != null)
if (ioException != null) {
throw ioException;
}
}
/**
* <p>Called by {@link #close()} to close the connector server.
* After returning from this method, the connector server must
* not accept any new connections.</p>
*
* @exception IOException if the attempt to close the connector
* server failed.
*/
try {
/*
* According to the rules specified in the javax.management.remote
* package description, a numeric IPv6 address (detected by the
* presence of otherwise forbidden ":" character) forming a part
* of the connection id must be enclosed in square brackets.
*/
}
} catch (ServerNotActiveException e) {
}
sep = ";";
}
}
}
private void dropDeadReferences() {
synchronized (clientList) {
}
}
}
//Notification buffer is lazily created when the first client connects
if(notifBuffer == null)
env);
return notifBuffer;
}
/** List of WeakReference values. Each one references an
RMIConnection created by this object, or null if the
RMIConnection has been garbage-collected. */
private static int connectionIdNumber;
}