FileDocCategorySizeDatePackage
CachedCodeBase.javaAPI DocJava SE 5 API5632Fri Aug 26 14:54:20 BST 2005com.sun.corba.se.impl.encoding

CachedCodeBase

public class CachedCodeBase extends com.sun.org.omg.SendingContext._CodeBaseImplBase
Provides the reading side with a per connection cache of info obtained via calls to the remote CodeBase. Previously, most of this was in IIOPConnection. Features: Delays cache creation unless used Postpones remote calls until necessary Handles creating obj ref from IOR Maintains caches for the following maps: CodeBase IOR to obj ref (global) RepId to implementation URL(s) RepId to remote FVD RepId to superclass type list Needs cache management.

Fields Summary
private Hashtable
implementations
private Hashtable
fvds
private Hashtable
bases
private com.sun.org.omg.SendingContext.CodeBase
delegate
private com.sun.corba.se.spi.transport.CorbaConnection
conn
private static Hashtable
iorToCodeBaseObjMap
Constructors Summary
public CachedCodeBase(com.sun.corba.se.spi.transport.CorbaConnection connection)


       
        conn = connection;
    
Methods Summary
public java.lang.String[]bases(java.lang.String repId)


        String[] results = null;

        if (bases == null)
            bases = new Hashtable();
        else
            results = (String[])bases.get(repId);

        if (results == null && connectedCodeBase()) {
            results = delegate.bases(repId);

            if (results != null)
                bases.put(repId, results);
        }

        return results;
    
private booleanconnectedCodeBase()

        if (delegate != null)
            return true;

        // The delegate was null, so see if the connection's
        // IOR was set.  If so, then we just need to connect
        // it.  Otherwise, there is no hope of checking the
        // remote code base.  That could be bug if the
        // service context processing didn't occur, or it
        // could be that we're talking to a foreign ORB which
        // doesn't include this optional service context.
        if (conn.getCodeBaseIOR() == null) {
            // REVISIT.  Use Merlin logging service to report that
            // codebase functionality was requested but unavailable.
            if (conn.getBroker().transportDebugFlag)
                conn.dprint("CodeBase unavailable on connection: " + conn);

            return false;
        }

        synchronized(this) {

            // Recheck the condition to make sure another
            // thread didn't already do this while we waited
            if (delegate != null)
                return true;

            // Do we have a reference initialized by another connection?
            delegate = (CodeBase)CachedCodeBase.iorToCodeBaseObjMap.get(conn.getCodeBaseIOR());
            if (delegate != null)
                return true;
            
            // Connect the delegate and update the cache
            delegate = CodeBaseHelper.narrow(getObjectFromIOR());
            
            // Save it for the benefit of other connections
            CachedCodeBase.iorToCodeBaseObjMap.put(conn.getCodeBaseIOR(), 
                                                   delegate);
        }

        // It's now safe to use the delegate
        return true;
    
private final org.omg.CORBA.ObjectgetObjectFromIOR()

        return CDRInputStream_1_0.internalIORToObject(
	    conn.getCodeBaseIOR(), null /*stubFactory*/, conn.getBroker());
    
public com.sun.org.omg.CORBA.Repositoryget_ir()

        return null;
    
public java.lang.Stringimplementation(java.lang.String repId)

        String urlResult = null;

        if (implementations == null)
            implementations = new Hashtable();
        else
            urlResult = (String)implementations.get(repId);

        if (urlResult == null && connectedCodeBase()) {
            urlResult = delegate.implementation(repId);

            if (urlResult != null)
                implementations.put(repId, urlResult);
        }

        return urlResult;
    
public java.lang.String[]implementations(java.lang.String[] repIds)

        String[] urlResults = new String[repIds.length];

        for (int i = 0; i < urlResults.length; i++)
            urlResults[i] = implementation(repIds[i]);

        return urlResults;
    
public com.sun.org.omg.CORBA.ValueDefPackage.FullValueDescriptionmeta(java.lang.String repId)

        FullValueDescription result = null;

        if (fvds == null)
            fvds = new Hashtable();
        else
            result = (FullValueDescription)fvds.get(repId);

        if (result == null && connectedCodeBase()) {
            result = delegate.meta(repId);

            if (result != null)
                fvds.put(repId, result);
        }

        return result;
    
public com.sun.org.omg.CORBA.ValueDefPackage.FullValueDescription[]metas(java.lang.String[] repIds)

        FullValueDescription[] results 
            = new FullValueDescription[repIds.length];

        for (int i = 0; i < results.length; i++)
            results[i] = meta(repIds[i]);

        return results;