corba/src/share/classes/com/sun/corba/se/impl/encoding/CachedCodeBase.java
author coffeys
Wed, 27 Jun 2012 21:09:29 +0100
changeset 13171 1ac5e9a54a6e
parent 5555 b2b5ed3f0d0d
permissions -rw-r--r--
7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8 Reviewed-by: lancea
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4
02bb8761fcce Initial load
duke
parents:
diff changeset
     1
/*
13171
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
     2
 * Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved.
4
02bb8761fcce Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
02bb8761fcce Initial load
duke
parents:
diff changeset
     4
 *
02bb8761fcce Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
02bb8761fcce Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5555
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
4
02bb8761fcce Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5555
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
4
02bb8761fcce Initial load
duke
parents:
diff changeset
    10
 *
02bb8761fcce Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
02bb8761fcce Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
02bb8761fcce Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
02bb8761fcce Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
02bb8761fcce Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
02bb8761fcce Initial load
duke
parents:
diff changeset
    16
 *
02bb8761fcce Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
02bb8761fcce Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
02bb8761fcce Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
02bb8761fcce Initial load
duke
parents:
diff changeset
    20
 *
5555
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
    23
 * questions.
4
02bb8761fcce Initial load
duke
parents:
diff changeset
    24
 */
02bb8761fcce Initial load
duke
parents:
diff changeset
    25
package com.sun.corba.se.impl.encoding;
02bb8761fcce Initial load
duke
parents:
diff changeset
    26
02bb8761fcce Initial load
duke
parents:
diff changeset
    27
import java.util.Hashtable;
02bb8761fcce Initial load
duke
parents:
diff changeset
    28
import com.sun.org.omg.CORBA.ValueDefPackage.FullValueDescription;
02bb8761fcce Initial load
duke
parents:
diff changeset
    29
import com.sun.org.omg.SendingContext.CodeBase;
02bb8761fcce Initial load
duke
parents:
diff changeset
    30
import com.sun.org.omg.SendingContext.CodeBaseHelper;
02bb8761fcce Initial load
duke
parents:
diff changeset
    31
import com.sun.org.omg.SendingContext._CodeBaseImplBase;
02bb8761fcce Initial load
duke
parents:
diff changeset
    32
import com.sun.org.omg.SendingContext._CodeBaseStub;
02bb8761fcce Initial load
duke
parents:
diff changeset
    33
import com.sun.corba.se.spi.transport.CorbaConnection;
13171
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
    34
import com.sun.corba.se.spi.ior.IOR;
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
    35
import com.sun.corba.se.spi.orb.ORB;
4
02bb8761fcce Initial load
duke
parents:
diff changeset
    36
/**
02bb8761fcce Initial load
duke
parents:
diff changeset
    37
 * Provides the reading side with a per connection cache of
02bb8761fcce Initial load
duke
parents:
diff changeset
    38
 * info obtained via calls to the remote CodeBase.
02bb8761fcce Initial load
duke
parents:
diff changeset
    39
 *
02bb8761fcce Initial load
duke
parents:
diff changeset
    40
 * Previously, most of this was in IIOPConnection.
02bb8761fcce Initial load
duke
parents:
diff changeset
    41
 *
02bb8761fcce Initial load
duke
parents:
diff changeset
    42
 * Features:
02bb8761fcce Initial load
duke
parents:
diff changeset
    43
 *    Delays cache creation unless used
02bb8761fcce Initial load
duke
parents:
diff changeset
    44
 *    Postpones remote calls until necessary
02bb8761fcce Initial load
duke
parents:
diff changeset
    45
 *    Handles creating obj ref from IOR
02bb8761fcce Initial load
duke
parents:
diff changeset
    46
 *    Maintains caches for the following maps:
02bb8761fcce Initial load
duke
parents:
diff changeset
    47
 *         CodeBase IOR to obj ref (global)
02bb8761fcce Initial load
duke
parents:
diff changeset
    48
 *         RepId to implementation URL(s)
02bb8761fcce Initial load
duke
parents:
diff changeset
    49
 *         RepId to remote FVD
02bb8761fcce Initial load
duke
parents:
diff changeset
    50
 *         RepId to superclass type list
02bb8761fcce Initial load
duke
parents:
diff changeset
    51
 *
02bb8761fcce Initial load
duke
parents:
diff changeset
    52
 * Needs cache management.
02bb8761fcce Initial load
duke
parents:
diff changeset
    53
 */
02bb8761fcce Initial load
duke
parents:
diff changeset
    54
public class CachedCodeBase extends _CodeBaseImplBase
02bb8761fcce Initial load
duke
parents:
diff changeset
    55
{
02bb8761fcce Initial load
duke
parents:
diff changeset
    56
    private Hashtable implementations, fvds, bases;
13171
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
    57
    private volatile CodeBase delegate;
4
02bb8761fcce Initial load
duke
parents:
diff changeset
    58
    private CorbaConnection conn;
02bb8761fcce Initial load
duke
parents:
diff changeset
    59
13171
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
    60
    private static Object iorMapLock = new Object();
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
    61
    private static Hashtable<IOR,CodeBase> iorMap = new Hashtable<>();
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
    62
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
    63
    public static synchronized void cleanCache( ORB orb ) {
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
    64
        synchronized (iorMapLock) {
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
    65
            for (IOR ior : iorMap.keySet()) {
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
    66
                if (ior.getORB() == orb) {
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
    67
                    iorMap.remove(ior);
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
    68
                }
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
    69
            }
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
    70
        }
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
    71
    }
4
02bb8761fcce Initial load
duke
parents:
diff changeset
    72
02bb8761fcce Initial load
duke
parents:
diff changeset
    73
    public CachedCodeBase(CorbaConnection connection) {
02bb8761fcce Initial load
duke
parents:
diff changeset
    74
        conn = connection;
02bb8761fcce Initial load
duke
parents:
diff changeset
    75
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
    76
02bb8761fcce Initial load
duke
parents:
diff changeset
    77
    public com.sun.org.omg.CORBA.Repository get_ir () {
02bb8761fcce Initial load
duke
parents:
diff changeset
    78
        return null;
02bb8761fcce Initial load
duke
parents:
diff changeset
    79
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
    80
13171
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
    81
    public synchronized String implementation (String repId) {
4
02bb8761fcce Initial load
duke
parents:
diff changeset
    82
        String urlResult = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
    83
02bb8761fcce Initial load
duke
parents:
diff changeset
    84
        if (implementations == null)
02bb8761fcce Initial load
duke
parents:
diff changeset
    85
            implementations = new Hashtable();
02bb8761fcce Initial load
duke
parents:
diff changeset
    86
        else
02bb8761fcce Initial load
duke
parents:
diff changeset
    87
            urlResult = (String)implementations.get(repId);
02bb8761fcce Initial load
duke
parents:
diff changeset
    88
02bb8761fcce Initial load
duke
parents:
diff changeset
    89
        if (urlResult == null && connectedCodeBase()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
    90
            urlResult = delegate.implementation(repId);
02bb8761fcce Initial load
duke
parents:
diff changeset
    91
02bb8761fcce Initial load
duke
parents:
diff changeset
    92
            if (urlResult != null)
02bb8761fcce Initial load
duke
parents:
diff changeset
    93
                implementations.put(repId, urlResult);
02bb8761fcce Initial load
duke
parents:
diff changeset
    94
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
    95
02bb8761fcce Initial load
duke
parents:
diff changeset
    96
        return urlResult;
02bb8761fcce Initial load
duke
parents:
diff changeset
    97
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
    98
13171
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
    99
    public synchronized String[] implementations (String[] repIds) {
4
02bb8761fcce Initial load
duke
parents:
diff changeset
   100
        String[] urlResults = new String[repIds.length];
02bb8761fcce Initial load
duke
parents:
diff changeset
   101
02bb8761fcce Initial load
duke
parents:
diff changeset
   102
        for (int i = 0; i < urlResults.length; i++)
02bb8761fcce Initial load
duke
parents:
diff changeset
   103
            urlResults[i] = implementation(repIds[i]);
02bb8761fcce Initial load
duke
parents:
diff changeset
   104
02bb8761fcce Initial load
duke
parents:
diff changeset
   105
        return urlResults;
02bb8761fcce Initial load
duke
parents:
diff changeset
   106
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   107
13171
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   108
    public synchronized FullValueDescription meta (String repId) {
4
02bb8761fcce Initial load
duke
parents:
diff changeset
   109
        FullValueDescription result = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   110
02bb8761fcce Initial load
duke
parents:
diff changeset
   111
        if (fvds == null)
02bb8761fcce Initial load
duke
parents:
diff changeset
   112
            fvds = new Hashtable();
02bb8761fcce Initial load
duke
parents:
diff changeset
   113
        else
02bb8761fcce Initial load
duke
parents:
diff changeset
   114
            result = (FullValueDescription)fvds.get(repId);
02bb8761fcce Initial load
duke
parents:
diff changeset
   115
02bb8761fcce Initial load
duke
parents:
diff changeset
   116
        if (result == null && connectedCodeBase()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   117
            result = delegate.meta(repId);
02bb8761fcce Initial load
duke
parents:
diff changeset
   118
02bb8761fcce Initial load
duke
parents:
diff changeset
   119
            if (result != null)
02bb8761fcce Initial load
duke
parents:
diff changeset
   120
                fvds.put(repId, result);
02bb8761fcce Initial load
duke
parents:
diff changeset
   121
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   122
02bb8761fcce Initial load
duke
parents:
diff changeset
   123
        return result;
02bb8761fcce Initial load
duke
parents:
diff changeset
   124
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   125
13171
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   126
    public synchronized FullValueDescription[] metas (String[] repIds) {
4
02bb8761fcce Initial load
duke
parents:
diff changeset
   127
        FullValueDescription[] results
02bb8761fcce Initial load
duke
parents:
diff changeset
   128
            = new FullValueDescription[repIds.length];
02bb8761fcce Initial load
duke
parents:
diff changeset
   129
02bb8761fcce Initial load
duke
parents:
diff changeset
   130
        for (int i = 0; i < results.length; i++)
02bb8761fcce Initial load
duke
parents:
diff changeset
   131
            results[i] = meta(repIds[i]);
02bb8761fcce Initial load
duke
parents:
diff changeset
   132
02bb8761fcce Initial load
duke
parents:
diff changeset
   133
        return results;
02bb8761fcce Initial load
duke
parents:
diff changeset
   134
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   135
13171
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   136
    public synchronized String[] bases (String repId) {
4
02bb8761fcce Initial load
duke
parents:
diff changeset
   137
02bb8761fcce Initial load
duke
parents:
diff changeset
   138
        String[] results = null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   139
02bb8761fcce Initial load
duke
parents:
diff changeset
   140
        if (bases == null)
02bb8761fcce Initial load
duke
parents:
diff changeset
   141
            bases = new Hashtable();
02bb8761fcce Initial load
duke
parents:
diff changeset
   142
        else
02bb8761fcce Initial load
duke
parents:
diff changeset
   143
            results = (String[])bases.get(repId);
02bb8761fcce Initial load
duke
parents:
diff changeset
   144
02bb8761fcce Initial load
duke
parents:
diff changeset
   145
        if (results == null && connectedCodeBase()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   146
            results = delegate.bases(repId);
02bb8761fcce Initial load
duke
parents:
diff changeset
   147
02bb8761fcce Initial load
duke
parents:
diff changeset
   148
            if (results != null)
02bb8761fcce Initial load
duke
parents:
diff changeset
   149
                bases.put(repId, results);
02bb8761fcce Initial load
duke
parents:
diff changeset
   150
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   151
02bb8761fcce Initial load
duke
parents:
diff changeset
   152
        return results;
02bb8761fcce Initial load
duke
parents:
diff changeset
   153
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   154
02bb8761fcce Initial load
duke
parents:
diff changeset
   155
    // Ensures that we've used the connection's IOR to create
02bb8761fcce Initial load
duke
parents:
diff changeset
   156
    // a valid CodeBase delegate.  If this returns false, then
02bb8761fcce Initial load
duke
parents:
diff changeset
   157
    // it is not valid to access the delegate.
13171
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   158
    private synchronized boolean connectedCodeBase() {
4
02bb8761fcce Initial load
duke
parents:
diff changeset
   159
        if (delegate != null)
02bb8761fcce Initial load
duke
parents:
diff changeset
   160
            return true;
02bb8761fcce Initial load
duke
parents:
diff changeset
   161
02bb8761fcce Initial load
duke
parents:
diff changeset
   162
        // The delegate was null, so see if the connection's
02bb8761fcce Initial load
duke
parents:
diff changeset
   163
        // IOR was set.  If so, then we just need to connect
02bb8761fcce Initial load
duke
parents:
diff changeset
   164
        // it.  Otherwise, there is no hope of checking the
02bb8761fcce Initial load
duke
parents:
diff changeset
   165
        // remote code base.  That could be bug if the
02bb8761fcce Initial load
duke
parents:
diff changeset
   166
        // service context processing didn't occur, or it
02bb8761fcce Initial load
duke
parents:
diff changeset
   167
        // could be that we're talking to a foreign ORB which
02bb8761fcce Initial load
duke
parents:
diff changeset
   168
        // doesn't include this optional service context.
02bb8761fcce Initial load
duke
parents:
diff changeset
   169
        if (conn.getCodeBaseIOR() == null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   170
            // REVISIT.  Use Merlin logging service to report that
02bb8761fcce Initial load
duke
parents:
diff changeset
   171
            // codebase functionality was requested but unavailable.
02bb8761fcce Initial load
duke
parents:
diff changeset
   172
            if (conn.getBroker().transportDebugFlag)
02bb8761fcce Initial load
duke
parents:
diff changeset
   173
                conn.dprint("CodeBase unavailable on connection: " + conn);
02bb8761fcce Initial load
duke
parents:
diff changeset
   174
02bb8761fcce Initial load
duke
parents:
diff changeset
   175
            return false;
02bb8761fcce Initial load
duke
parents:
diff changeset
   176
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   177
13171
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   178
        synchronized(iorMapLock) {
4
02bb8761fcce Initial load
duke
parents:
diff changeset
   179
02bb8761fcce Initial load
duke
parents:
diff changeset
   180
            // Recheck the condition to make sure another
02bb8761fcce Initial load
duke
parents:
diff changeset
   181
            // thread didn't already do this while we waited
02bb8761fcce Initial load
duke
parents:
diff changeset
   182
            if (delegate != null)
02bb8761fcce Initial load
duke
parents:
diff changeset
   183
                return true;
02bb8761fcce Initial load
duke
parents:
diff changeset
   184
02bb8761fcce Initial load
duke
parents:
diff changeset
   185
            // Do we have a reference initialized by another connection?
13171
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   186
            delegate = CachedCodeBase.iorMap.get(conn.getCodeBaseIOR());
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   187
4
02bb8761fcce Initial load
duke
parents:
diff changeset
   188
            if (delegate != null)
02bb8761fcce Initial load
duke
parents:
diff changeset
   189
                return true;
02bb8761fcce Initial load
duke
parents:
diff changeset
   190
02bb8761fcce Initial load
duke
parents:
diff changeset
   191
            // Connect the delegate and update the cache
02bb8761fcce Initial load
duke
parents:
diff changeset
   192
            delegate = CodeBaseHelper.narrow(getObjectFromIOR());
02bb8761fcce Initial load
duke
parents:
diff changeset
   193
02bb8761fcce Initial load
duke
parents:
diff changeset
   194
            // Save it for the benefit of other connections
13171
1ac5e9a54a6e 7162902: Umbrella port of a number of corba bug fixes from JDK 6 to jdk7u/8
coffeys
parents: 5555
diff changeset
   195
            CachedCodeBase.iorMap.put(conn.getCodeBaseIOR(), delegate);
4
02bb8761fcce Initial load
duke
parents:
diff changeset
   196
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   197
02bb8761fcce Initial load
duke
parents:
diff changeset
   198
        // It's now safe to use the delegate
02bb8761fcce Initial load
duke
parents:
diff changeset
   199
        return true;
02bb8761fcce Initial load
duke
parents:
diff changeset
   200
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   201
02bb8761fcce Initial load
duke
parents:
diff changeset
   202
    private final org.omg.CORBA.Object getObjectFromIOR() {
02bb8761fcce Initial load
duke
parents:
diff changeset
   203
        return CDRInputStream_1_0.internalIORToObject(
02bb8761fcce Initial load
duke
parents:
diff changeset
   204
            conn.getCodeBaseIOR(), null /*stubFactory*/, conn.getBroker());
02bb8761fcce Initial load
duke
parents:
diff changeset
   205
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   206
}
02bb8761fcce Initial load
duke
parents:
diff changeset
   207
02bb8761fcce Initial load
duke
parents:
diff changeset
   208
// End of file.