corba/src/share/classes/com/sun/corba/se/impl/encoding/CachedCodeBase.java
changeset 13171 1ac5e9a54a6e
parent 5555 b2b5ed3f0d0d
equal deleted inserted replaced
13082:9b19b2302c28 13171:1ac5e9a54a6e
     1 /*
     1 /*
     2  * Copyright (c) 2000, 2004, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     7  * published by the Free Software Foundation.  Oracle designates this
    20  *
    20  *
    21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    22  * or visit www.oracle.com if you need additional information or have any
    22  * or visit www.oracle.com if you need additional information or have any
    23  * questions.
    23  * questions.
    24  */
    24  */
    25 
       
    26 package com.sun.corba.se.impl.encoding;
    25 package com.sun.corba.se.impl.encoding;
    27 
    26 
    28 import java.util.Hashtable;
    27 import java.util.Hashtable;
    29 import com.sun.org.omg.CORBA.ValueDefPackage.FullValueDescription;
    28 import com.sun.org.omg.CORBA.ValueDefPackage.FullValueDescription;
    30 import com.sun.org.omg.SendingContext.CodeBase;
    29 import com.sun.org.omg.SendingContext.CodeBase;
    31 import com.sun.org.omg.SendingContext.CodeBaseHelper;
    30 import com.sun.org.omg.SendingContext.CodeBaseHelper;
    32 import com.sun.org.omg.SendingContext._CodeBaseImplBase;
    31 import com.sun.org.omg.SendingContext._CodeBaseImplBase;
    33 import com.sun.org.omg.SendingContext._CodeBaseStub;
    32 import com.sun.org.omg.SendingContext._CodeBaseStub;
    34 import com.sun.corba.se.spi.transport.CorbaConnection;
    33 import com.sun.corba.se.spi.transport.CorbaConnection;
    35 
    34 import com.sun.corba.se.spi.ior.IOR;
       
    35 import com.sun.corba.se.spi.orb.ORB;
    36 /**
    36 /**
    37  * Provides the reading side with a per connection cache of
    37  * Provides the reading side with a per connection cache of
    38  * info obtained via calls to the remote CodeBase.
    38  * info obtained via calls to the remote CodeBase.
    39  *
    39  *
    40  * Previously, most of this was in IIOPConnection.
    40  * Previously, most of this was in IIOPConnection.
    49  *         RepId to remote FVD
    49  *         RepId to remote FVD
    50  *         RepId to superclass type list
    50  *         RepId to superclass type list
    51  *
    51  *
    52  * Needs cache management.
    52  * Needs cache management.
    53  */
    53  */
    54 // REVISIT: revert to package protected after framework merge.
       
    55 public class CachedCodeBase extends _CodeBaseImplBase
    54 public class CachedCodeBase extends _CodeBaseImplBase
    56 {
    55 {
    57     private Hashtable implementations, fvds, bases;
    56     private Hashtable implementations, fvds, bases;
    58     private CodeBase delegate;
    57     private volatile CodeBase delegate;
    59     private CorbaConnection conn;
    58     private CorbaConnection conn;
    60 
    59 
    61     private static Hashtable iorToCodeBaseObjMap = new Hashtable();
    60     private static Object iorMapLock = new Object();
       
    61     private static Hashtable<IOR,CodeBase> iorMap = new Hashtable<>();
       
    62 
       
    63     public static synchronized void cleanCache( ORB orb ) {
       
    64         synchronized (iorMapLock) {
       
    65             for (IOR ior : iorMap.keySet()) {
       
    66                 if (ior.getORB() == orb) {
       
    67                     iorMap.remove(ior);
       
    68                 }
       
    69             }
       
    70         }
       
    71     }
    62 
    72 
    63     public CachedCodeBase(CorbaConnection connection) {
    73     public CachedCodeBase(CorbaConnection connection) {
    64         conn = connection;
    74         conn = connection;
    65     }
    75     }
    66 
    76 
    67     public com.sun.org.omg.CORBA.Repository get_ir () {
    77     public com.sun.org.omg.CORBA.Repository get_ir () {
    68         return null;
    78         return null;
    69     }
    79     }
    70 
    80 
    71     public String implementation (String repId) {
    81     public synchronized String implementation (String repId) {
    72         String urlResult = null;
    82         String urlResult = null;
    73 
    83 
    74         if (implementations == null)
    84         if (implementations == null)
    75             implementations = new Hashtable();
    85             implementations = new Hashtable();
    76         else
    86         else
    84         }
    94         }
    85 
    95 
    86         return urlResult;
    96         return urlResult;
    87     }
    97     }
    88 
    98 
    89     public String[] implementations (String[] repIds) {
    99     public synchronized String[] implementations (String[] repIds) {
    90         String[] urlResults = new String[repIds.length];
   100         String[] urlResults = new String[repIds.length];
    91 
   101 
    92         for (int i = 0; i < urlResults.length; i++)
   102         for (int i = 0; i < urlResults.length; i++)
    93             urlResults[i] = implementation(repIds[i]);
   103             urlResults[i] = implementation(repIds[i]);
    94 
   104 
    95         return urlResults;
   105         return urlResults;
    96     }
   106     }
    97 
   107 
    98     public FullValueDescription meta (String repId) {
   108     public synchronized FullValueDescription meta (String repId) {
    99         FullValueDescription result = null;
   109         FullValueDescription result = null;
   100 
   110 
   101         if (fvds == null)
   111         if (fvds == null)
   102             fvds = new Hashtable();
   112             fvds = new Hashtable();
   103         else
   113         else
   111         }
   121         }
   112 
   122 
   113         return result;
   123         return result;
   114     }
   124     }
   115 
   125 
   116     public FullValueDescription[] metas (String[] repIds) {
   126     public synchronized FullValueDescription[] metas (String[] repIds) {
   117         FullValueDescription[] results
   127         FullValueDescription[] results
   118             = new FullValueDescription[repIds.length];
   128             = new FullValueDescription[repIds.length];
   119 
   129 
   120         for (int i = 0; i < results.length; i++)
   130         for (int i = 0; i < results.length; i++)
   121             results[i] = meta(repIds[i]);
   131             results[i] = meta(repIds[i]);
   122 
   132 
   123         return results;
   133         return results;
   124     }
   134     }
   125 
   135 
   126     public String[] bases (String repId) {
   136     public synchronized String[] bases (String repId) {
   127 
   137 
   128         String[] results = null;
   138         String[] results = null;
   129 
   139 
   130         if (bases == null)
   140         if (bases == null)
   131             bases = new Hashtable();
   141             bases = new Hashtable();
   143     }
   153     }
   144 
   154 
   145     // Ensures that we've used the connection's IOR to create
   155     // Ensures that we've used the connection's IOR to create
   146     // a valid CodeBase delegate.  If this returns false, then
   156     // a valid CodeBase delegate.  If this returns false, then
   147     // it is not valid to access the delegate.
   157     // it is not valid to access the delegate.
   148     private boolean connectedCodeBase() {
   158     private synchronized boolean connectedCodeBase() {
   149         if (delegate != null)
   159         if (delegate != null)
   150             return true;
   160             return true;
   151 
   161 
   152         // The delegate was null, so see if the connection's
   162         // The delegate was null, so see if the connection's
   153         // IOR was set.  If so, then we just need to connect
   163         // IOR was set.  If so, then we just need to connect
   163                 conn.dprint("CodeBase unavailable on connection: " + conn);
   173                 conn.dprint("CodeBase unavailable on connection: " + conn);
   164 
   174 
   165             return false;
   175             return false;
   166         }
   176         }
   167 
   177 
   168         synchronized(this) {
   178         synchronized(iorMapLock) {
   169 
   179 
   170             // Recheck the condition to make sure another
   180             // Recheck the condition to make sure another
   171             // thread didn't already do this while we waited
   181             // thread didn't already do this while we waited
   172             if (delegate != null)
   182             if (delegate != null)
   173                 return true;
   183                 return true;
   174 
   184 
   175             // Do we have a reference initialized by another connection?
   185             // Do we have a reference initialized by another connection?
   176             delegate = (CodeBase)CachedCodeBase.iorToCodeBaseObjMap.get(conn.getCodeBaseIOR());
   186             delegate = CachedCodeBase.iorMap.get(conn.getCodeBaseIOR());
       
   187 
   177             if (delegate != null)
   188             if (delegate != null)
   178                 return true;
   189                 return true;
   179 
   190 
   180             // Connect the delegate and update the cache
   191             // Connect the delegate and update the cache
   181             delegate = CodeBaseHelper.narrow(getObjectFromIOR());
   192             delegate = CodeBaseHelper.narrow(getObjectFromIOR());
   182 
   193 
   183             // Save it for the benefit of other connections
   194             // Save it for the benefit of other connections
   184             CachedCodeBase.iorToCodeBaseObjMap.put(conn.getCodeBaseIOR(),
   195             CachedCodeBase.iorMap.put(conn.getCodeBaseIOR(), delegate);
   185                                                    delegate);
       
   186         }
   196         }
   187 
   197 
   188         // It's now safe to use the delegate
   198         // It's now safe to use the delegate
   189         return true;
   199         return true;
   190     }
   200     }