API Overview API Index Package Overview Direct link to this page
JDK 1.6
  javax.management.remote.rmi. RMIIIOPServerImpl View Javadoc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142

/*
 * @(#)RMIIIOPServerImpl.java	1.26 05/11/17
 * 
 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
 * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */

package javax.management.remote.rmi;

import java.io.IOException;
import java.rmi.Remote;
import java.security.AccessControlContext;
import java.security.AccessController;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
import java.util.Map;
import java.util.Collections;
import javax.rmi.PortableRemoteObject;
import javax.security.auth.Subject;

/**
 * <p>An {@link RMIServerImpl} that is exported through IIOP and that
 * creates client connections as RMI objects exported through IIOP.
 * User code does not usually reference this class directly.</p>
 *
 * @see RMIServerImpl
 *
 * @since 1.5
 * @since.unbundled 1.0
 */
public class RMIIIOPServerImpl extends RMIServerImpl {
    /**
     * <p>Creates a new {@link RMIServerImpl}.</p>
     *
     * @param env the environment containing attributes for the new
     * <code>RMIServerImpl</code>.  Can be null, which is equivalent
     * to an empty Map.
     *
     * @exception IOException if the RMI object cannot be created.
     */
    public RMIIIOPServerImpl(Map<String,?> env)
	    throws IOException {
	super(env);

	this.env = (env == null) ? Collections.EMPTY_MAP : env;

        callerACC = AccessController.getContext();
    }

    protected void export() throws IOException {
	PortableRemoteObject.exportObject(this);
    }

    protected String getProtocol() {
	return "iiop";
    }

    /**
     * <p>Returns an IIOP stub.</p>
     * The stub might not yet be connected to the ORB. The stub will
     * be serializable only if it is connected to the ORB.
     * @return an IIOP stub.
     * @exception IOException if the stub cannot be created - e.g the
     *            RMIIIOPServerImpl has not been exported yet.
     **/
    public Remote toStub() throws IOException {
	// javax.rmi.CORBA.Stub stub = 
	//    (javax.rmi.CORBA.Stub) PortableRemoteObject.toStub(this);
	final Remote stub = PortableRemoteObject.toStub(this);
	// java.lang.System.out.println("NON CONNECTED STUB " + stub);
	// org.omg.CORBA.ORB orb =
	//    org.omg.CORBA.ORB.init((String[])null, (Properties)null);
	// stub.connect(orb);
	// java.lang.System.out.println("CONNECTED STUB " + stub);
	return (Remote) stub;
    }

    /**
     * <p>Creates a new client connection as an RMI object exported
     * through IIOP.
     *
     * @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.
     */
    protected RMIConnection makeClient(String connectionId, Subject subject)
	    throws IOException {

	if (connectionId == null)
	    throw new NullPointerException("Null connectionId");

	RMIConnection client =
	    new RMIConnectionImpl(this, connectionId, getDefaultClassLoader(),
				  subject, env);
	PortableRemoteObject.exportObject(client);
	return client;
    }

    protected void closeClient(RMIConnection client) throws IOException {
	PortableRemoteObject.unexportObject(client);
    }
    
    /**
     * <p>Called by {@link #close()} to close the connector server by
     * unexporting this object.  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.
     */
    protected void closeServer() throws IOException {
	PortableRemoteObject.unexportObject(this);
    }
@Override
    RMIConnection doNewClient(final Object credentials) throws IOException {
        try {
            return AccessController.doPrivileged(
                new PrivilegedExceptionAction<RMIConnection>() {
                    public RMIConnection run() throws IOException {
                        return superDoNewClient(credentials);
                    }
            }, callerACC);
        } catch (PrivilegedActionException pae) {
            throw (IOException) pae.getCause();
        }
    }

    RMIConnection superDoNewClient(Object credentials) throws IOException {
        return super.doNewClient(credentials);
    }

    private final Map env;
    private final AccessControlContext callerACC;
}

Generated By: JavaOnTracks Doclet 0.1.4     ©Thibaut Colar