📄 clientdelegate.java
字号:
/* * @(#)ClientDelegate.java 1.87 03/01/23 * * Copyright 2003 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. *//* * Licensed Materials - Property of IBM * RMI-IIOP v1.0 * Copyright IBM Corp. 1998 1999 All Rights Reserved * * US Government Users Restricted Rights - Use, duplication or * disclosure restricted by GSA ADP Schedule Contract with IBM Corp. */package com.sun.corba.se.internal.corba;import java.util.Iterator;import org.omg.CORBA.INTERNAL;import org.omg.CORBA.ORB;import org.omg.CORBA.portable.RemarshalException;import org.omg.CORBA.SystemException;import org.omg.CORBA.CompletionStatus;import org.omg.CORBA.WrongTransaction;import org.omg.CORBA.Request;import org.omg.CORBA.NamedValue;import org.omg.CORBA.NVList;import org.omg.CORBA.Context;import org.omg.CORBA.ContextList;import org.omg.CORBA.ExceptionList;import org.omg.CORBA.TypeCode;import org.omg.CORBA.DATA_CONVERSION;import org.omg.CORBA.UNKNOWN;import org.omg.CORBA.portable.ObjectImpl;import org.omg.CORBA.portable.InputStream;import org.omg.CORBA.portable.OutputStream;import org.omg.CORBA.portable.Delegate;import org.omg.CORBA.portable.ServantObject;import org.omg.CORBA.portable.ApplicationException;import org.omg.CORBA.portable.UnknownException;import org.omg.IOP.TAG_CODE_SETS;import javax.rmi.CORBA.Util;import javax.rmi.CORBA.Tie;import java.rmi.RemoteException;import com.sun.org.omg.SendingContext.CodeBase;import com.sun.corba.se.internal.ior.IIOPProfile;import com.sun.corba.se.internal.ior.IIOPProfileTemplate;import com.sun.corba.se.internal.ior.ObjectKey;import com.sun.corba.se.internal.core.IOR;import com.sun.corba.se.internal.core.ClientGIOP;import com.sun.corba.se.internal.core.ClientSubcontract;import com.sun.corba.se.internal.core.ClientRequest;import com.sun.corba.se.internal.core.ClientResponse;import com.sun.corba.se.internal.core.ServiceContext;import com.sun.corba.se.internal.core.ServiceContexts;import com.sun.corba.se.internal.core.MarshalOutputStream;import com.sun.corba.se.internal.core.MarshalInputStream;import com.sun.corba.se.internal.core.CodeSetComponentInfo;import com.sun.corba.se.internal.core.CodeSetConversion;import com.sun.corba.se.internal.core.UEInfoServiceContext;import com.sun.corba.se.internal.core.CodeSetServiceContext;import com.sun.corba.se.internal.core.SendingContextServiceContext;import com.sun.corba.se.internal.core.ORBVersionServiceContext;import com.sun.corba.se.internal.core.NoSuchServiceContext;import com.sun.corba.se.internal.core.DuplicateServiceContext;import com.sun.corba.se.internal.core.GIOPVersion;import com.sun.corba.se.internal.core.ORBVersion;import com.sun.corba.se.internal.orbutil.MinorCodes;import com.sun.corba.se.internal.util.JDKBridge;import com.sun.corba.se.internal.orbutil.ORBUtility;import com.sun.corba.se.internal.iiop.messages.ReplyMessage;import com.sun.corba.se.internal.iiop.Connection;import com.sun.corba.se.internal.iiop.ClientRequestImpl;import com.sun.corba.se.internal.iiop.LocalClientRequestImpl;import com.sun.corba.se.internal.iiop.messages.KeyAddr;import com.sun.corba.se.internal.core.ORBVersionFactory;import com.sun.corba.se.internal.ior.CodeSetsComponent;import com.sun.corba.se.internal.ior.TaggedComponent;import com.sun.corba.se.internal.orbutil.ORBConstants;import com.sun.corba.se.internal.iiop.messages.KeyAddr;import com.sun.corba.se.internal.iiop.messages.ProfileAddr;import com.sun.corba.se.internal.iiop.messages.ReferenceAddr;/** * ClientDelegate is the RMI client-side subcontract or representation * It implements RMI delegate as well as our internal ClientSubcontract * interface. */public class ClientDelegate extends org.omg.CORBA_2_3.portable.Delegate implements ClientSubcontract{ protected void dprint( String msg ) { ORBUtility.dprint( this, msg ) ; } protected com.sun.corba.se.internal.corba.ORB orb; protected IOR ior; protected IOR locatedIOR; protected boolean isCachedHashValue = false; protected int cachedHashValue; protected int scid; // my subcontract id protected ServantObject servant; protected ClassLoader servantClassLoader ; protected short addressingDisposition = KeyAddr.value; protected ThreadLocal isNextIsLocalValid = new ThreadLocal( ) { protected Object initialValue( ) { return Boolean.TRUE; } }; // the connection with which to store the codebase returned by the // server // orb version to be stored into thread local public ClientDelegate() { super(); servant = null; } public ClientDelegate(com.sun.corba.se.internal.corba.ORB orb, IOR ior, int id) { this(orb,ior,id,null); } public ClientDelegate(com.sun.corba.se.internal.corba.ORB orb, IOR ior, int id, java.lang.Object servant) { this(); setOrb(orb); this.ior = ior; this.locatedIOR = ior; this.scid = id; if (servant != null && servant instanceof Tie) { servantClassLoader = servant.getClass().getClassLoader() ; this.servant = new ServantObject(); this.servant.servant = ((Tie)servant).getTarget(); } else { this.servant = null; servantClassLoader = null ; } } public void unexport() { // DO NOT set the IOR to null. (Un)exporting is only concerns // the servant not the IOR. If the ior is set to null then // null pointer exceptions happen during an colocated invocation. // It is better to let the invocation proceed and get OBJECT_NOT_EXIST // from the server side. //ior = null; servant = null; } public IOR marshal() { return ior; } public IOR getIOR() { return ior; } public IOR getLocatedIOR() { return locatedIOR; } public void unmarshal(IOR ior) { this.ior = ior; this.locatedIOR = ior; } public void setAddressingDisposition(short value){ this.addressingDisposition = value; } public short getAddressingDisposition() { return this.addressingDisposition; } public void setLocatedIOR( IOR locatedIOR ) { this.locatedIOR = locatedIOR; } public void setId(int id) { this.scid = id; } public int getId() { return scid ; } public void setOrb(com.sun.corba.se.internal.core.ORB orb) { this.orb = (com.sun.corba.se.internal.corba.ORB) orb; this.addressingDisposition = this.orb.getGIOPAddressDisposition(); } /* * NOTE: This version of invoke should ONLY be used externally * by a DII call (it is used internally by the streams invoke). * Otherwise the PortableInterceptor internal stack will become * unbalanced. * * It is invoked from the DII implementation: RequestImpl.doInvocation(). * * invoke(org.omg.CORBA.Object, OutputStream) calls this one, so * do any service context processing here. * * This is also called from GenericPOAClientSC's * invoke(org.omg.CORBA.Object, OutputStream). */ public ClientResponse invoke(ClientRequest request) { if (orb.subcontractDebugFlag) dprint( "invoke(ClientRequest) called" ) ; ClientResponse resp = request.invoke(); // We know for sure now that we've sent a message. // So OK to not send initial again. if (request.getConnection() != null) { request.getConnection().setPostInitialContexts(); } // Notify Portable Interceptors of client response. // This must happen here so that both stream-based and DII // calls have their hands on the response. orb.setClientPIInfo( resp ); if (request.isOneWay()) { return null; } consumeServiceContexts(resp); // Now that we have the service contexts processed and the // correct ORBVersion set, we must finish initializing the // stream. resp.performORBVersionSpecificInit(); // FIX(Ram J) (04/28/2000) The location forwarded behaviour and the // system exception(COMM_FAILURE) behaviour (i.e retry from root ior) // is handled in this.invoke(Object, OutputStream) which called this // method. The client stubs should not directly call this method. // However, there are a few methods in the ClientDelegate : is_a(), // get_interface_def() and non_existent() which directly call // this method. Such methods should handle the location forwarded // responses by building new requests and system exception(COMM_FAILURE) // responses by retrying from root ior. return resp; } /* * This version of invoke should be used by everthing but a DII call. */ public InputStream invoke(org.omg.CORBA.Object self, OutputStream out) throws ApplicationException, org.omg.CORBA.portable.RemarshalException { ClientRequest request = (ClientRequest) out; ClientResponse response = this.invoke(request); // For PI code: Exception exception = null; if (request.isOneWay()) { //oneway calls // Invoke Portable Interceptors with receive_other exception = orb.invokeClientPIEndingPoint( ReplyMessage.NO_EXCEPTION, exception ); continueOrThrowSystemOrRemarshal( exception ); return null; } // COMMENT(Ram J) 10/01/2000 There is no need to set the response // stream's connection to that of the request stream. The response // stream will have a connection associated if the response had been // built out of the server response; else if the response was built out // of SystemException arising out of response handling, then there // will be no connection or service context available with the response // stream. In such a case, the consumeServiceContexts has to return // gracefully. /* // consume service contexts that were returned to the client Connection c = request.getConnection(); if (response != null) response.setConnection(c); */ // Processing of service contexts is done in invoke(ClientRequest) if (response.isSystemException()) { SystemException se = response.getSystemException(); boolean doRemarshal = false; // FIX(Ram J) (04/28/2000) added locatedIOR = ior // and throw RemarshallException to force retrying // from root ior, if system exception is COMM_FAILURE. // WARNING: There is a risk of infinite loopback if the requests on // location forwarded ior result in system exception (COMM_FAILURE) if (se instanceof org.omg.CORBA.COMM_FAILURE && se.completed == CompletionStatus.COMPLETED_NO) { if (locatedIOR != ior) { locatedIOR = ior; // retry from root ior doRemarshal = true; } } /* This used to live in a loop in IIOPOutputStream.invoke. That loop had a retry count to bound the number of tries. However that loop did not work once fragmentation was put in. So it was moved here. However, there is no place to hang the count since this throws out to the Stub. We need invocation level (i.e., thread local) date like in PI to put this count. That is scheduled for Taggart. For now, just turn this off. if (se.minor == MinorCodes.CONN_CLOSE_REBIND && (se instanceof org.omg.CORBA.COMM_FAILURE)) { doRemarshal = true; } */ if (doRemarshal) { // Invoke Portable Interceptors with receive_exception: exception = orb.invokeClientPIEndingPoint( ReplyMessage.SYSTEM_EXCEPTION, se ); // If PI did not change the exception, throw a // Remarshal. Otherwise, throw the exception PI // wants thrown. if( se == exception ) { // exception = null is to maintain symmetry with // GenericPOAClientSC. //exception = null; throw new RemarshalException(); } else { continueOrThrowSystemOrRemarshal( exception ); throw new INTERNAL("Assertion failed. " + "exception should not be null." );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -