src/share/classes/com/sun/corba/se/impl/protocol/LocalClientRequestDispatcherBase.java

Wed, 28 Mar 2012 02:50:50 -0700

author
mbankal
date
Wed, 28 Mar 2012 02:50:50 -0700
changeset 371
e324dfb90c9e
parent 158
91006f157c46
child 748
6845b95cba6b
permissions
-rw-r--r--

7079902: Refine CORBA data models
Reviewed-by: coffeys

duke@1 1 /*
mbankal@371 2 * Copyright (c) 2002, 2012, Oracle and/or its affiliates. All rights reserved.
duke@1 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@1 4 *
duke@1 5 * This code is free software; you can redistribute it and/or modify it
duke@1 6 * under the terms of the GNU General Public License version 2 only, as
ohair@158 7 * published by the Free Software Foundation. Oracle designates this
duke@1 8 * particular file as subject to the "Classpath" exception as provided
ohair@158 9 * by Oracle in the LICENSE file that accompanied this code.
duke@1 10 *
duke@1 11 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@1 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@1 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@1 14 * version 2 for more details (a copy is included in the LICENSE file that
duke@1 15 * accompanied this code).
duke@1 16 *
duke@1 17 * You should have received a copy of the GNU General Public License version
duke@1 18 * 2 along with this work; if not, write to the Free Software Foundation,
duke@1 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@1 20 *
ohair@158 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ohair@158 22 * or visit www.oracle.com if you need additional information or have any
ohair@158 23 * questions.
duke@1 24 */
duke@1 25
duke@1 26 package com.sun.corba.se.impl.protocol;
duke@1 27
duke@1 28 import org.omg.CORBA.portable.ServantObject;
duke@1 29
duke@1 30 import com.sun.corba.se.spi.protocol.LocalClientRequestDispatcher;
duke@1 31 import com.sun.corba.se.spi.protocol.RequestDispatcherRegistry;
duke@1 32
duke@1 33 import com.sun.corba.se.spi.orb.ORB;
duke@1 34 import com.sun.corba.se.spi.ior.IOR ;
duke@1 35 import com.sun.corba.se.spi.oa.ObjectAdapterFactory;
duke@1 36
duke@1 37 import com.sun.corba.se.spi.ior.ObjectAdapterId;
duke@1 38 import com.sun.corba.se.spi.ior.TaggedProfile;
duke@1 39 import com.sun.corba.se.spi.ior.ObjectKeyTemplate;
duke@1 40 import com.sun.corba.se.spi.ior.ObjectId;
duke@1 41
duke@1 42 public abstract class LocalClientRequestDispatcherBase implements LocalClientRequestDispatcher
duke@1 43 {
duke@1 44 protected ORB orb;
duke@1 45 int scid;
duke@1 46
duke@1 47 // Cached information needed for local dispatch
duke@1 48 protected boolean servantIsLocal ;
duke@1 49 protected ObjectAdapterFactory oaf ;
duke@1 50 protected ObjectAdapterId oaid ;
duke@1 51 protected byte[] objectId ;
duke@1 52
duke@1 53 // If isNextIsLocalValid.get() == Boolean.TRUE,
duke@1 54 // the next call to isLocal should be valid
mbankal@371 55 private static final ThreadLocal isNextCallValid = new ThreadLocal() {
duke@1 56 protected synchronized Object initialValue() {
duke@1 57 return Boolean.TRUE;
duke@1 58 }
duke@1 59 };
duke@1 60
duke@1 61 protected LocalClientRequestDispatcherBase(ORB orb, int scid, IOR ior)
duke@1 62 {
duke@1 63 this.orb = orb ;
duke@1 64
duke@1 65 TaggedProfile prof = ior.getProfile() ;
duke@1 66 servantIsLocal = orb.getORBData().isLocalOptimizationAllowed() &&
duke@1 67 prof.isLocal();
duke@1 68
duke@1 69 ObjectKeyTemplate oktemp = prof.getObjectKeyTemplate() ;
duke@1 70 this.scid = oktemp.getSubcontractId() ;
duke@1 71 RequestDispatcherRegistry sreg = orb.getRequestDispatcherRegistry() ;
duke@1 72 oaf = sreg.getObjectAdapterFactory( scid ) ;
duke@1 73 oaid = oktemp.getObjectAdapterId() ;
duke@1 74 ObjectId oid = prof.getObjectId() ;
duke@1 75 objectId = oid.getId() ;
duke@1 76 }
duke@1 77
duke@1 78 public byte[] getObjectId()
duke@1 79 {
duke@1 80 return objectId ;
duke@1 81 }
duke@1 82
duke@1 83 public boolean is_local(org.omg.CORBA.Object self)
duke@1 84 {
duke@1 85 return false;
duke@1 86 }
duke@1 87
duke@1 88 /*
duke@1 89 * Possible paths through
duke@1 90 * useLocalInvocation/servant_preinvoke/servant_postinvoke:
duke@1 91 *
duke@1 92 * A: call useLocalInvocation
duke@1 93 * If useLocalInvocation returns false, servant_preinvoke is not called.
duke@1 94 * If useLocalInvocation returns true,
duke@1 95 * call servant_preinvoke
duke@1 96 * If servant_preinvoke returns null,
duke@1 97 * goto A
duke@1 98 * else
duke@1 99 * (local invocation proceeds normally)
duke@1 100 * servant_postinvoke is called
duke@1 101 *
duke@1 102 */
duke@1 103 public boolean useLocalInvocation( org.omg.CORBA.Object self )
duke@1 104 {
duke@1 105 if (isNextCallValid.get() == Boolean.TRUE)
duke@1 106 return servantIsLocal ;
duke@1 107 else
duke@1 108 isNextCallValid.set( Boolean.TRUE ) ;
duke@1 109
duke@1 110 return false ;
duke@1 111 }
duke@1 112
duke@1 113 /** Check that the servant in info (which must not be null) is
duke@1 114 * an instance of the expectedType. If not, set the thread local flag
duke@1 115 * and return false.
duke@1 116 */
duke@1 117 protected boolean checkForCompatibleServant( ServantObject so,
duke@1 118 Class expectedType )
duke@1 119 {
duke@1 120 if (so == null)
duke@1 121 return false ;
duke@1 122
duke@1 123 // Normally, this test will never fail. However, if the servant
duke@1 124 // and the stub were loaded in different class loaders, this test
duke@1 125 // will fail.
duke@1 126 if (!expectedType.isInstance( so.servant )) {
duke@1 127 isNextCallValid.set( Boolean.FALSE ) ;
duke@1 128
duke@1 129 // When servant_preinvoke returns null, the stub will
duke@1 130 // recursively re-invoke itself. Thus, the next call made from
duke@1 131 // the stub is another useLocalInvocation call.
duke@1 132 return false ;
duke@1 133 }
duke@1 134
duke@1 135 return true ;
duke@1 136 }
duke@1 137
duke@1 138 }
duke@1 139
duke@1 140 // End of file.

mercurial