📄 serverdelegate.java
字号:
/* * @(#)ServerDelegate.java 1.72 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 javax.rmi.CORBA.Tie;import org.omg.CORBA.portable.ApplicationException;import org.omg.CORBA.SystemException;import org.omg.CORBA.INTERNAL;import org.omg.CORBA.UNKNOWN;import org.omg.CORBA.OBJECT_NOT_EXIST;import org.omg.CORBA.DATA_CONVERSION;import org.omg.CORBA.CompletionStatus;import org.omg.CORBA.Any;import org.omg.CORBA.portable.ObjectImpl;import org.omg.CORBA.portable.InvokeHandler;import org.omg.CORBA.DynamicImplementation;import org.omg.CORBA.portable.InputStream;import org.omg.CORBA.portable.OutputStream;import org.omg.CORBA.portable.UnknownException;import org.omg.CORBA.CompletionStatus;import java.rmi.Remote;import com.sun.corba.se.internal.iiop.ORB;import com.sun.corba.se.internal.core.InternalRuntimeForwardRequest;import com.sun.corba.se.internal.core.ServerSubcontract;import com.sun.corba.se.internal.core.IOR;import com.sun.corba.se.internal.core.ServerRequest;import com.sun.corba.se.internal.core.ServerResponse;import com.sun.corba.se.internal.core.ServiceContext;import com.sun.corba.se.internal.core.DuplicateServiceContext;import com.sun.corba.se.internal.core.NoSuchServiceContext;import com.sun.corba.se.internal.core.ServiceContexts;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.ORBVersion;import com.sun.corba.se.internal.core.ORBVersionFactory;import com.sun.corba.se.internal.core.ORBVersionImpl;import com.sun.corba.se.internal.core.EndPoint;import com.sun.corba.se.internal.core.ClientSubcontract;import com.sun.corba.se.internal.core.ServiceContext;import com.sun.corba.se.internal.core.MarshalInputStream;import com.sun.corba.se.internal.core.MarshalOutputStream;import com.sun.corba.se.internal.core.CodeSetComponentInfo;import com.sun.corba.se.internal.core.GIOPVersion;import com.sun.corba.se.internal.core.OSFCodeSetRegistry;import com.sun.corba.se.internal.orbutil.MinorCodes;import com.sun.corba.se.internal.orbutil.ORBUtility;import com.sun.org.omg.SendingContext.CodeBase;import com.sun.corba.se.internal.orbutil.TransientObjectManager;import com.sun.corba.se.internal.orbutil.ORBConstants;import com.sun.corba.se.internal.iiop.Connection;import com.sun.corba.se.internal.iiop.RequestCanceledException;import com.sun.corba.se.internal.ior.ObjectId;import com.sun.corba.se.internal.ior.ObjectKeyFactory;import com.sun.corba.se.internal.ior.ObjectKey;import com.sun.corba.se.internal.ior.ObjectKeyTemplate;import com.sun.corba.se.internal.ior.JIDLObjectKeyTemplate;public class ServerDelegate implements ServerSubcontract { protected void dprint( String msg ) { ORBUtility.dprint( this, msg ) ; } protected ORB orb; // my ORB instance protected int scid; // my subcontract id protected TransientObjectManager servants; // Added from last version because it broke the build - RTW public static final int UNKNOWN_EXCEPTION_INFO_ID = 9; // These offsets are for the object key. Assume the first 8 bytes // contain the magic and the sc-id. public static final int SERVERID_OFFSET = 8; public static final int USERKEYLEN_OFFSET = 12; public static final int USERKEY_OFFSET = 16; public ServerDelegate() { servants = new TransientObjectManager(); } public ServerDelegate(ORB orb) { this(); setOrb( orb ) ; } 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.iiop.ORB) orb; servants.setOrb( (com.sun.corba.se.internal.corba.ORB)orb ) ; } public Class getClientSubcontractClass() { return ClientDelegate.class; } // Need to signal one of OBJECT_HERE, OBJECT_FORWARD, OBJECT_NOT_EXIST. public IOR locate(ObjectKey okey) { ObjectId id = okey.getId() ; ObjectKeyTemplate oktemp = okey.getTemplate() ; // Check if the serverid matches this server's transientServerId. int sid = oktemp.getServerId() ; if ( sid != orb.getTransientServerId() ) throw new OBJECT_NOT_EXIST(MinorCodes.BAD_SERVER_ID, CompletionStatus.COMPLETED_NO); // Get the servant java.lang.Object servant = getServant(id); if (servant == null) throw new OBJECT_NOT_EXIST(MinorCodes.SERVANT_NOT_FOUND, CompletionStatus.COMPLETED_NO); // If we reached here, it means we got the servant, // so just return null to signal OBJECT_HERE. return null; } private Object getServant( ObjectId id ) { byte[] userKey = id.getId() ; return servants.lookupServant(userKey); } public Object getServant(IOR ior) { if (!ior.isLocal()) return null; ObjectId id = ior.getProfile().getObjectId() ; return getServant( id ) ; } public boolean isServantSupported() { return true; } public void consumeServiceContexts(ServerRequest request) { ServiceContexts ctxts = request.getServiceContexts(); ServiceContext sc ; GIOPVersion giopVersion = request.getGIOPVersion(); // we cannot depend on this since for our local case, we do not send // in this service context. Can we rely on just the CodeSetServiceContext? // boolean rtSC = false; // Runtime ServiceContext boolean hasCodeSetContext = processCodeSetContext(request, ctxts); if (orb.subcontractDebugFlag) { dprint("Consuming service contexts, GIOP version: " + giopVersion); dprint("Has code set context? " + hasCodeSetContext); } try { sc = ctxts.get( SendingContextServiceContext.SERVICE_CONTEXT_ID ) ; SendingContextServiceContext scsc = (SendingContextServiceContext)sc ; IOR ior = scsc.getIOR() ; try { request.getConnection().setCodeBaseIOR(ior); } catch (ThreadDeath td) { throw td ; } catch (Throwable t) { throw new DATA_CONVERSION( MinorCodes.BAD_STRINGIFIED_IOR, CompletionStatus.COMPLETED_NO); } } catch (NoSuchServiceContext exc) { // ignore: this type not present } // the RTSC is sent only once during session establishment. We // need to find out if the CodeBaseRef is already set. If yes, // then also the rtSC flag needs to be set to true // this is not possible for the LocalCase since there is no // IIOPConnection for the LocalCase // used for a case where we have JDK 1.3 supporting 1.0 protocol, // but sending 2 service contexts, that is not normal as per // GIOP rules, based on above information, we figure out that we // are talking to the legacy ORB and set the ORB Version Accordingly. // this special case tell us that it is legacy SUN orb // and not a foreign one // rtSC is not available for localcase due to which this generic // path would fail if relying on rtSC //if (giopVersion.equals(GIOPVersion.V1_0) && hasCodeSetContext && rtSC) boolean isForeignORB = false; if (giopVersion.equals(GIOPVersion.V1_0) && hasCodeSetContext) { if (orb.subcontractDebugFlag) dprint("Determined to be an old Sun ORB"); orb.setORBVersion(ORBVersionImpl.OLD) ; // System.out.println("setting legacy ORB version"); } else { // If it didn't include our ORB version service context (below), // then it must be a foreign ORB. isForeignORB = true; } // try to get the ORBVersion sent as part of the ServiceContext // if any try { sc = ctxts.get( ORBVersionServiceContext.SERVICE_CONTEXT_ID ) ; ORBVersionServiceContext ovsc = (ORBVersionServiceContext) sc; ORBVersion version = ovsc.getVersion(); orb.setORBVersion( version ) ; isForeignORB = false; } catch (NoSuchServiceContext exc) { // ignore: this type not present } if (isForeignORB) { if (orb.subcontractDebugFlag) dprint("Determined to be a foreign ORB"); orb.setORBVersion(ORBVersionImpl.FOREIGN); } } public ServerResponse dispatch(ServerRequest request) { if (orb.subcontractDebugFlag) dprint( "Entering dispatch method" ) ; ObjectKey okey = request.getObjectKey(); ObjectKeyTemplate oktemp = okey.getTemplate() ; ObjectId oid = okey.getId() ; String operation = request.getOperationName(); Object servant = getServant(oid); if (servant == null) { boolean raiseObjectNotExist = true; if (SpecialMethod.isSpecialMethod(operation)) { SpecialMethod specialMethod = SpecialMethod.getSpecialMethod(operation); if (specialMethod instanceof NonExistent || specialMethod instanceof NotExistent) { raiseObjectNotExist = false; } } if (raiseObjectNotExist) { throw new OBJECT_NOT_EXIST(MinorCodes.SERVANT_NOT_FOUND, CompletionStatus.COMPLETED_NO); } } ServerResponse response = null; int sId = oktemp.getServerId() ; if (sId != orb.getTransientServerId()) throw new OBJECT_NOT_EXIST(MinorCodes.BAD_SERVER_ID, CompletionStatus.COMPLETED_NO); consumeServiceContexts(request); // Now that we have the service contexts processed and the // correct ORBVersion set, we must finish initializing the // stream. request.performORBVersionSpecificInit(); if (orb.subcontractDebugFlag) dprint( "Dispatching to servant" ) ; // This outer try is required for PI so that if an interceptor // throws InternalRuntimeForwardRequest in a send_* point, // we can still handle it. try { try { // Notify PI of serverRequest, Servant. // Note that we call receive_request_service_contexts after // setting the servant in the info object. This is
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -