corba/src/share/classes/com/sun/corba/se/impl/protocol/RequestDispatcherRegistryImpl.java
author ohair
Tue, 25 May 2010 15:52:11 -0700
changeset 5555 b2b5ed3f0d0d
parent 4 02bb8761fcce
permissions -rw-r--r--
6943119: Rebrand source copyright notices Reviewed-by: darcy
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4
02bb8761fcce Initial load
duke
parents:
diff changeset
     1
/*
5555
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
     2
 * Copyright (c) 2002, 2003, 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
02bb8761fcce Initial load
duke
parents:
diff changeset
    26
package com.sun.corba.se.impl.protocol;
02bb8761fcce Initial load
duke
parents:
diff changeset
    27
02bb8761fcce Initial load
duke
parents:
diff changeset
    28
import java.util.Set;
02bb8761fcce Initial load
duke
parents:
diff changeset
    29
import java.util.HashSet;
02bb8761fcce Initial load
duke
parents:
diff changeset
    30
import java.util.Map;
02bb8761fcce Initial load
duke
parents:
diff changeset
    31
import java.util.HashMap;
02bb8761fcce Initial load
duke
parents:
diff changeset
    32
import java.util.Collections;
02bb8761fcce Initial load
duke
parents:
diff changeset
    33
02bb8761fcce Initial load
duke
parents:
diff changeset
    34
import com.sun.corba.se.pept.protocol.ClientRequestDispatcher ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    35
02bb8761fcce Initial load
duke
parents:
diff changeset
    36
import com.sun.corba.se.spi.protocol.LocalClientRequestDispatcher ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    37
import com.sun.corba.se.spi.protocol.LocalClientRequestDispatcherFactory ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    38
import com.sun.corba.se.spi.protocol.CorbaServerRequestDispatcher ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    39
import com.sun.corba.se.spi.protocol.RequestDispatcherRegistry ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    40
02bb8761fcce Initial load
duke
parents:
diff changeset
    41
import com.sun.corba.se.spi.oa.ObjectAdapterFactory ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    42
02bb8761fcce Initial load
duke
parents:
diff changeset
    43
import com.sun.corba.se.spi.orb.ORB ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    44
02bb8761fcce Initial load
duke
parents:
diff changeset
    45
import com.sun.corba.se.impl.orbutil.ORBConstants ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    46
import com.sun.corba.se.impl.orbutil.DenseIntMapImpl ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    47
02bb8761fcce Initial load
duke
parents:
diff changeset
    48
/**
02bb8761fcce Initial load
duke
parents:
diff changeset
    49
 * This is a registry of all subcontract ID dependent objects.  This includes:
02bb8761fcce Initial load
duke
parents:
diff changeset
    50
 * LocalClientRequestDispatcherFactory, ClientRequestDispatcher, ServerSubcontract, and
02bb8761fcce Initial load
duke
parents:
diff changeset
    51
 * ObjectAdapterFactory.
02bb8761fcce Initial load
duke
parents:
diff changeset
    52
 */
02bb8761fcce Initial load
duke
parents:
diff changeset
    53
public class RequestDispatcherRegistryImpl implements RequestDispatcherRegistry {
02bb8761fcce Initial load
duke
parents:
diff changeset
    54
    private ORB orb;
02bb8761fcce Initial load
duke
parents:
diff changeset
    55
02bb8761fcce Initial load
duke
parents:
diff changeset
    56
    protected int defaultId;                    // The default subcontract ID to use if
02bb8761fcce Initial load
duke
parents:
diff changeset
    57
                                                // there is no more specific ID available.
02bb8761fcce Initial load
duke
parents:
diff changeset
    58
                                                // This happens when invoking a foreign IOR.
02bb8761fcce Initial load
duke
parents:
diff changeset
    59
    private DenseIntMapImpl SDRegistry ;        // ServerRequestDispatcher registry
02bb8761fcce Initial load
duke
parents:
diff changeset
    60
    private DenseIntMapImpl CSRegistry ;        // ClientRequestDispatcher registry
02bb8761fcce Initial load
duke
parents:
diff changeset
    61
    private DenseIntMapImpl OAFRegistry ;       // ObjectAdapterFactory registry
02bb8761fcce Initial load
duke
parents:
diff changeset
    62
    private DenseIntMapImpl LCSFRegistry ;      // LocalClientRequestDispatcherFactory registry
02bb8761fcce Initial load
duke
parents:
diff changeset
    63
    private Set objectAdapterFactories ;        // Set of all ObjectAdapterFactory instances
02bb8761fcce Initial load
duke
parents:
diff changeset
    64
    private Set objectAdapterFactoriesView ;    // Read-only view of oaf instances
02bb8761fcce Initial load
duke
parents:
diff changeset
    65
    private Map stringToServerSubcontract ;     // Map from obect key string to
02bb8761fcce Initial load
duke
parents:
diff changeset
    66
                                                // ServerSubcontract
02bb8761fcce Initial load
duke
parents:
diff changeset
    67
                                                // for special bootstrap IORs
02bb8761fcce Initial load
duke
parents:
diff changeset
    68
02bb8761fcce Initial load
duke
parents:
diff changeset
    69
    public RequestDispatcherRegistryImpl(ORB orb, int defaultId )
02bb8761fcce Initial load
duke
parents:
diff changeset
    70
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
    71
        this.orb = orb;
02bb8761fcce Initial load
duke
parents:
diff changeset
    72
        this.defaultId = defaultId;
02bb8761fcce Initial load
duke
parents:
diff changeset
    73
        SDRegistry = new DenseIntMapImpl() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    74
        CSRegistry = new DenseIntMapImpl() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    75
        OAFRegistry = new DenseIntMapImpl() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    76
        LCSFRegistry = new DenseIntMapImpl() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    77
        objectAdapterFactories = new HashSet() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    78
        objectAdapterFactoriesView = Collections.unmodifiableSet( objectAdapterFactories ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    79
        stringToServerSubcontract = new HashMap() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    80
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
    81
02bb8761fcce Initial load
duke
parents:
diff changeset
    82
    public synchronized void registerClientRequestDispatcher(
02bb8761fcce Initial load
duke
parents:
diff changeset
    83
        ClientRequestDispatcher csc, int scid)
02bb8761fcce Initial load
duke
parents:
diff changeset
    84
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
    85
        CSRegistry.set( scid, csc ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    86
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
    87
02bb8761fcce Initial load
duke
parents:
diff changeset
    88
    public synchronized void registerLocalClientRequestDispatcherFactory(
02bb8761fcce Initial load
duke
parents:
diff changeset
    89
        LocalClientRequestDispatcherFactory csc, int scid)
02bb8761fcce Initial load
duke
parents:
diff changeset
    90
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
    91
        LCSFRegistry.set( scid, csc ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    92
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
    93
02bb8761fcce Initial load
duke
parents:
diff changeset
    94
    public synchronized void registerServerRequestDispatcher(
02bb8761fcce Initial load
duke
parents:
diff changeset
    95
        CorbaServerRequestDispatcher ssc, int scid)
02bb8761fcce Initial load
duke
parents:
diff changeset
    96
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
    97
        SDRegistry.set( scid, ssc ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    98
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
    99
02bb8761fcce Initial load
duke
parents:
diff changeset
   100
    public synchronized void registerServerRequestDispatcher(
02bb8761fcce Initial load
duke
parents:
diff changeset
   101
        CorbaServerRequestDispatcher scc, String name )
02bb8761fcce Initial load
duke
parents:
diff changeset
   102
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   103
        stringToServerSubcontract.put( name, scc ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   104
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   105
02bb8761fcce Initial load
duke
parents:
diff changeset
   106
    public synchronized void registerObjectAdapterFactory(
02bb8761fcce Initial load
duke
parents:
diff changeset
   107
        ObjectAdapterFactory oaf, int scid)
02bb8761fcce Initial load
duke
parents:
diff changeset
   108
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   109
        objectAdapterFactories.add( oaf ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   110
        OAFRegistry.set( scid, oaf ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   111
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   112
02bb8761fcce Initial load
duke
parents:
diff changeset
   113
    // **************************************************
02bb8761fcce Initial load
duke
parents:
diff changeset
   114
    // Methods to find the subcontract side subcontract
02bb8761fcce Initial load
duke
parents:
diff changeset
   115
    // **************************************************
02bb8761fcce Initial load
duke
parents:
diff changeset
   116
02bb8761fcce Initial load
duke
parents:
diff changeset
   117
    // Note that both forms of getServerRequestDispatcher need to return
02bb8761fcce Initial load
duke
parents:
diff changeset
   118
    // the default server delegate if no other match is found.
02bb8761fcce Initial load
duke
parents:
diff changeset
   119
    // This is essential to proper handling of errors for
02bb8761fcce Initial load
duke
parents:
diff changeset
   120
    // malformed requests.  In particular, a bad MAGIC will
02bb8761fcce Initial load
duke
parents:
diff changeset
   121
    // result in a lookup in the named key table (stringToServerSubcontract),
02bb8761fcce Initial load
duke
parents:
diff changeset
   122
    // which must return a valid ServerRequestDispatcher.  A bad subcontract ID
02bb8761fcce Initial load
duke
parents:
diff changeset
   123
    // will similarly need to return the default ServerRequestDispatcher.
02bb8761fcce Initial load
duke
parents:
diff changeset
   124
02bb8761fcce Initial load
duke
parents:
diff changeset
   125
    public CorbaServerRequestDispatcher getServerRequestDispatcher(int scid)
02bb8761fcce Initial load
duke
parents:
diff changeset
   126
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   127
        CorbaServerRequestDispatcher sdel =
02bb8761fcce Initial load
duke
parents:
diff changeset
   128
            (CorbaServerRequestDispatcher)(SDRegistry.get(scid)) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   129
        if ( sdel == null )
02bb8761fcce Initial load
duke
parents:
diff changeset
   130
            sdel = (CorbaServerRequestDispatcher)(SDRegistry.get(defaultId)) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   131
02bb8761fcce Initial load
duke
parents:
diff changeset
   132
        return sdel;
02bb8761fcce Initial load
duke
parents:
diff changeset
   133
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   134
02bb8761fcce Initial load
duke
parents:
diff changeset
   135
    public CorbaServerRequestDispatcher getServerRequestDispatcher( String name )
02bb8761fcce Initial load
duke
parents:
diff changeset
   136
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   137
        CorbaServerRequestDispatcher sdel =
02bb8761fcce Initial load
duke
parents:
diff changeset
   138
            (CorbaServerRequestDispatcher)stringToServerSubcontract.get( name ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   139
02bb8761fcce Initial load
duke
parents:
diff changeset
   140
        if ( sdel == null )
02bb8761fcce Initial load
duke
parents:
diff changeset
   141
            sdel = (CorbaServerRequestDispatcher)(SDRegistry.get(defaultId)) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   142
02bb8761fcce Initial load
duke
parents:
diff changeset
   143
        return sdel;
02bb8761fcce Initial load
duke
parents:
diff changeset
   144
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   145
02bb8761fcce Initial load
duke
parents:
diff changeset
   146
    public LocalClientRequestDispatcherFactory getLocalClientRequestDispatcherFactory(
02bb8761fcce Initial load
duke
parents:
diff changeset
   147
        int scid )
02bb8761fcce Initial load
duke
parents:
diff changeset
   148
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   149
        LocalClientRequestDispatcherFactory factory =
02bb8761fcce Initial load
duke
parents:
diff changeset
   150
            (LocalClientRequestDispatcherFactory)(LCSFRegistry.get(scid)) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   151
        if (factory == null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   152
            factory = (LocalClientRequestDispatcherFactory)(LCSFRegistry.get(defaultId)) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   153
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   154
02bb8761fcce Initial load
duke
parents:
diff changeset
   155
        return factory ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   156
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   157
02bb8761fcce Initial load
duke
parents:
diff changeset
   158
    public ClientRequestDispatcher getClientRequestDispatcher( int scid )
02bb8761fcce Initial load
duke
parents:
diff changeset
   159
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   160
        ClientRequestDispatcher subcontract =
02bb8761fcce Initial load
duke
parents:
diff changeset
   161
            (ClientRequestDispatcher)(CSRegistry.get(scid)) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   162
        if (subcontract == null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   163
            subcontract = (ClientRequestDispatcher)(CSRegistry.get(defaultId)) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   164
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   165
02bb8761fcce Initial load
duke
parents:
diff changeset
   166
        return subcontract ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   167
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   168
02bb8761fcce Initial load
duke
parents:
diff changeset
   169
    public ObjectAdapterFactory getObjectAdapterFactory( int scid )
02bb8761fcce Initial load
duke
parents:
diff changeset
   170
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   171
        ObjectAdapterFactory oaf =
02bb8761fcce Initial load
duke
parents:
diff changeset
   172
            (ObjectAdapterFactory)(OAFRegistry.get(scid)) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   173
        if ( oaf == null )
02bb8761fcce Initial load
duke
parents:
diff changeset
   174
            oaf = (ObjectAdapterFactory)(OAFRegistry.get(defaultId)) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   175
02bb8761fcce Initial load
duke
parents:
diff changeset
   176
        return oaf;
02bb8761fcce Initial load
duke
parents:
diff changeset
   177
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   178
02bb8761fcce Initial load
duke
parents:
diff changeset
   179
    public Set getObjectAdapterFactories()
02bb8761fcce Initial load
duke
parents:
diff changeset
   180
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   181
        return objectAdapterFactoriesView ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   182
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   183
}