summaryrefslogtreecommitdiff
path: root/src/java.corba/share/classes/com/sun/corba/se/impl/transport/CorbaContactInfoListImpl.java
blob: cb8c895c3f8fef320dd8d67c2e235dc61f9e6dac (plain)
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
/*
 * Copyright (c) 2002, 2006, Oracle and/or its affiliates. All rights reserved.
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * 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.
 */

package com.sun.corba.se.impl.transport;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import com.sun.corba.se.pept.transport.ContactInfo;

import com.sun.corba.se.spi.ior.IOR ;
import com.sun.corba.se.spi.ior.iiop.IIOPProfile ;
import com.sun.corba.se.spi.ior.iiop.IIOPProfileTemplate ;
import com.sun.corba.se.spi.oa.ObjectAdapterFactory;
import com.sun.corba.se.spi.orb.ORB;
import com.sun.corba.se.spi.protocol.LocalClientRequestDispatcher;
import com.sun.corba.se.spi.protocol.LocalClientRequestDispatcherFactory;
import com.sun.corba.se.spi.transport.CorbaContactInfoList ;
import com.sun.corba.se.spi.transport.SocketInfo;

import com.sun.corba.se.impl.orbutil.ORBConstants;
import com.sun.corba.se.impl.protocol.NotLocalLocalCRDImpl;

/**
 * @author Harold Carr
 */
public class CorbaContactInfoListImpl
    implements
        CorbaContactInfoList
{
    protected ORB orb;
    protected LocalClientRequestDispatcher LocalClientRequestDispatcher;
    protected IOR targetIOR;
    protected IOR effectiveTargetIOR;
    protected List effectiveTargetIORContactInfoList;
    protected ContactInfo primaryContactInfo;

    // XREVISIT - is this used?
    public CorbaContactInfoListImpl(ORB orb)
    {
        this.orb = orb;
    }

    public CorbaContactInfoListImpl(ORB orb, IOR targetIOR)
    {
        this(orb);
        setTargetIOR(targetIOR);
    }

    ////////////////////////////////////////////////////
    //
    // pept.transport.ContactInfoList
    //

    public synchronized Iterator iterator()
    {
        createContactInfoList();
        return new CorbaContactInfoListIteratorImpl(
            orb, this, primaryContactInfo,
            effectiveTargetIORContactInfoList);
    }

    ////////////////////////////////////////////////////
    //
    // spi.transport.CorbaContactInfoList
    //

    public synchronized void setTargetIOR(IOR targetIOR)
    {
        this.targetIOR = targetIOR;
        setEffectiveTargetIOR(targetIOR);
    }

    public synchronized IOR getTargetIOR()
    {
        return targetIOR;
    }

    public synchronized void setEffectiveTargetIOR(IOR effectiveTargetIOR)
    {
        this.effectiveTargetIOR = effectiveTargetIOR;
        effectiveTargetIORContactInfoList = null;
        if (primaryContactInfo != null &&
            orb.getORBData().getIIOPPrimaryToContactInfo() != null)
        {
            orb.getORBData().getIIOPPrimaryToContactInfo()
                .reset(primaryContactInfo);
        }
        primaryContactInfo = null;
        setLocalSubcontract();
    }

    public synchronized IOR getEffectiveTargetIOR()
    {
        return effectiveTargetIOR;
    }

    public synchronized LocalClientRequestDispatcher getLocalClientRequestDispatcher()
    {
        return LocalClientRequestDispatcher;
    }

    ////////////////////////////////////////////////////
    //
    // org.omg.CORBA.portable.Delegate
    //

    // REVISIT - hashCode(org.omg.CORBA.Object self)

    ////////////////////////////////////////////////////
    //
    // java.lang.Object
    //

    public synchronized int hashCode()
    {
        return targetIOR.hashCode();
    }

    ////////////////////////////////////////////////////
    //
    // Implementation
    //

    protected void createContactInfoList()
    {
        if (effectiveTargetIORContactInfoList != null) {
            return;
        }

        effectiveTargetIORContactInfoList = new ArrayList();

        IIOPProfile iiopProfile = effectiveTargetIOR.getProfile();
        String hostname =
            ((IIOPProfileTemplate)iiopProfile.getTaggedProfileTemplate())
                .getPrimaryAddress().getHost().toLowerCase();
        int    port     =
            ((IIOPProfileTemplate)iiopProfile.getTaggedProfileTemplate())
                .getPrimaryAddress().getPort();
        // For use by "sticky manager" if one is registered.
        primaryContactInfo =
            createContactInfo(SocketInfo.IIOP_CLEAR_TEXT, hostname, port);

        if (iiopProfile.isLocal()) {
            // NOTE: IMPORTANT:
            // Only do local.  The APP Server interceptors check
            // effectiveTarget.isLocal - which is determined via
            // the IOR - so if we added other addresses then
            // transactions and interceptors would not execute.
            ContactInfo contactInfo = new SharedCDRContactInfoImpl(
                orb, this, effectiveTargetIOR,
                orb.getORBData().getGIOPAddressDisposition());
            effectiveTargetIORContactInfoList.add(contactInfo);
        } else {
            addRemoteContactInfos(effectiveTargetIOR,
                                  effectiveTargetIORContactInfoList);
        }
    }

    protected void addRemoteContactInfos(
        IOR  effectiveTargetIOR,
        List effectiveTargetIORContactInfoList)
    {
        ContactInfo contactInfo;
        List socketInfos = orb.getORBData()
            .getIORToSocketInfo().getSocketInfo(effectiveTargetIOR);
        Iterator iterator = socketInfos.iterator();
        while (iterator.hasNext()) {
            SocketInfo socketInfo = (SocketInfo) iterator.next();
            String type = socketInfo.getType();
            String host = socketInfo.getHost().toLowerCase();
            int    port = socketInfo.getPort();
            contactInfo = createContactInfo(type, host, port);
            effectiveTargetIORContactInfoList.add(contactInfo);
        }
    }

    protected ContactInfo createContactInfo(String type,
                                            String hostname, int port)
    {
        return new SocketOrChannelContactInfoImpl(
            orb, this,
            // XREVISIT - See Base Line 62
            effectiveTargetIOR,
            orb.getORBData().getGIOPAddressDisposition(),
            type, hostname, port);
    }

    /**
     * setLocalSubcontract sets cached information that is set whenever
     * the effectiveTargetIOR changes.
     *
     * Note: this must be maintained accurately whether or not the ORB
     * allows local optimization, because ServantManagers in the POA
     * ALWAYS use local optimization ONLY (they do not have a remote case).
     */
    protected void setLocalSubcontract()
    {
        if (!effectiveTargetIOR.getProfile().isLocal()) {
            LocalClientRequestDispatcher = new NotLocalLocalCRDImpl();
            return;
        }

        // XXX Note that this always uses the first IIOP profile to get the
        // scid.  What about multi-profile IORs?  This should perhaps be
        // tied to the current ContactInfo in some way, together with an
        // implementation of ClientDelegate that generally prefers co-located
        // ContactInfo.  This may in fact mean that we should do this at
        // the ContactInfo level, rather than the IOR/profile level.
        int scid = effectiveTargetIOR.getProfile().getObjectKeyTemplate().
            getSubcontractId() ;
        LocalClientRequestDispatcherFactory lcsf = orb.getRequestDispatcherRegistry().getLocalClientRequestDispatcherFactory( scid ) ;
        LocalClientRequestDispatcher = lcsf.create( scid, effectiveTargetIOR ) ;
    }
}

// End of file.