01: /*
02: * Copyright (C) The MX4J Contributors.
03: * All rights reserved.
04: *
05: * This software is distributed under the terms of the MX4J License version 1.0.
06: * See the terms of the MX4J License in the documentation provided with this software.
07: */
08:
09: package javax.management.remote.rmi;
10:
11: import java.io.IOException;
12: import java.rmi.Remote;
13: import java.rmi.server.RMIClientSocketFactory;
14: import java.rmi.server.RMIServerSocketFactory;
15: import java.rmi.server.RemoteObject;
16: import java.rmi.server.UnicastRemoteObject;
17: import java.util.Map;
18: import javax.security.auth.Subject;
19:
20: /**
21: * @version $Revision: 1.10 $
22: */
23: public class RMIJRMPServerImpl extends RMIServerImpl {
24: private final int port;
25: private final RMIClientSocketFactory clientFactory;
26: private final RMIServerSocketFactory serverFactory;
27:
28: public RMIJRMPServerImpl(int port, RMIClientSocketFactory csf,
29: RMIServerSocketFactory ssf, Map env) throws IOException {
30: super (env);
31: this .port = port;
32: this .clientFactory = csf;
33: this .serverFactory = ssf;
34: }
35:
36: protected void export() throws IOException {
37: UnicastRemoteObject.exportObject(this , port, clientFactory,
38: serverFactory);
39: }
40:
41: protected String getProtocol() {
42: return "rmi";
43: }
44:
45: public Remote toStub() throws IOException {
46: return RemoteObject.toStub(this );
47: }
48:
49: protected RMIConnection makeClient(String connectionId,
50: Subject subject) throws IOException {
51: RMIConnectionImpl client = new RMIConnectionImpl(this ,
52: connectionId, getDefaultClassLoader(), subject,
53: getEnvironment());
54: client.setContext(getContext());
55: UnicastRemoteObject.exportObject(client, port, clientFactory,
56: serverFactory);
57: return client;
58: }
59:
60: protected void closeClient(RMIConnection client) throws IOException {
61: // The force parameter must be true, since a connector can be closed by the client code.
62: // In this case there is a remote call pending (close() itself) and the object will not be exported.
63: UnicastRemoteObject.unexportObject(client, true);
64: }
65:
66: protected void closeServer() throws IOException {
67: // The force parameter must be true, since a when I close a server I don't want that a pending call
68: // to newClient() will avoid to unexport this server.
69: UnicastRemoteObject.unexportObject(this , true);
70: }
71: }
|