⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 corbaserverrequestdispatcherimpl.java

📁 JAVA 所有包
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * @(#)CorbaServerRequestDispatcherImpl.java	1.77 05/11/17 * * Copyright 2006 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.impl.protocol;import org.omg.PortableServer.Servant ;import org.omg.CORBA.SystemException;import org.omg.CORBA.INTERNAL;import org.omg.CORBA.UNKNOWN;import org.omg.CORBA.CompletionStatus;import org.omg.CORBA.Any;import org.omg.CORBA.portable.InvokeHandler;import org.omg.CORBA.portable.InputStream;import org.omg.CORBA.portable.OutputStream;import org.omg.CORBA.portable.UnknownException;import org.omg.CORBA.portable.ResponseHandler;import com.sun.org.omg.SendingContext.CodeBase;import com.sun.corba.se.pept.encoding.OutputObject;import com.sun.corba.se.pept.protocol.MessageMediator;import com.sun.corba.se.spi.orb.ORB;import com.sun.corba.se.spi.orb.ORBVersion;import com.sun.corba.se.spi.orb.ORBVersionFactory;import com.sun.corba.se.spi.ior.IOR ;import com.sun.corba.se.spi.ior.ObjectKey;import com.sun.corba.se.spi.ior.ObjectKeyTemplate;import com.sun.corba.se.spi.ior.ObjectAdapterId;import com.sun.corba.se.spi.oa.ObjectAdapterFactory;import com.sun.corba.se.spi.oa.ObjectAdapter;import com.sun.corba.se.spi.oa.OAInvocationInfo;import com.sun.corba.se.spi.oa.OADestroyed;import com.sun.corba.se.spi.oa.NullServant;import com.sun.corba.se.spi.protocol.CorbaMessageMediator;import com.sun.corba.se.spi.protocol.CorbaServerRequestDispatcher;import com.sun.corba.se.spi.protocol.ForwardException ;import com.sun.corba.se.spi.protocol.RequestDispatcherRegistry;import com.sun.corba.se.spi.transport.CorbaConnection;import com.sun.corba.se.spi.logging.CORBALogDomains;import com.sun.corba.se.spi.ior.iiop.GIOPVersion;import com.sun.corba.se.impl.protocol.SpecialMethod ;import com.sun.corba.se.spi.servicecontext.ServiceContext;import com.sun.corba.se.spi.servicecontext.ServiceContexts;import com.sun.corba.se.spi.servicecontext.UEInfoServiceContext;import com.sun.corba.se.spi.servicecontext.CodeSetServiceContext;import com.sun.corba.se.spi.servicecontext.SendingContextServiceContext;import com.sun.corba.se.spi.servicecontext.ORBVersionServiceContext;import com.sun.corba.se.impl.corba.ServerRequestImpl ;import com.sun.corba.se.impl.encoding.MarshalInputStream;import com.sun.corba.se.impl.encoding.MarshalOutputStream;import com.sun.corba.se.impl.encoding.CodeSetComponentInfo;import com.sun.corba.se.impl.encoding.OSFCodeSetRegistry;import com.sun.corba.se.impl.orbutil.ORBConstants;import com.sun.corba.se.impl.orbutil.ORBUtility;import com.sun.corba.se.impl.protocol.RequestCanceledException;import com.sun.corba.se.impl.logging.ORBUtilSystemException;import com.sun.corba.se.impl.logging.POASystemException;public class CorbaServerRequestDispatcherImpl    implements CorbaServerRequestDispatcher {    protected ORB orb; // my ORB instance    private ORBUtilSystemException wrapper ;    private POASystemException poaWrapper ;    // Added from last version because it broke the build - RTW    // XXX remove me and rebuild: probably no longer needed    // public static final int UNKNOWN_EXCEPTION_INFO_ID = 9;    public CorbaServerRequestDispatcherImpl(ORB orb)     {	this.orb = orb;	wrapper = ORBUtilSystemException.get( orb,	    CORBALogDomains.RPC_PROTOCOL ) ;	poaWrapper = POASystemException.get( orb,	    CORBALogDomains.RPC_PROTOCOL ) ;    }    /** XXX/REVISIT:      * We do not want to look for a servant in the POA/ServantManager case,     * but we could in most other cases.  The OA could have a method that     * returns true if the servant MAY exist, and false only if the servant     * definitely DOES NOT exist.     *     * XXX/REVISIT:     * We may wish to indicate OBJECT_HERE by some mechanism other than     * returning a null result.     *      * Called from ORB.locate when a LocateRequest arrives.     * Result is not always absolutely correct: may indicate OBJECT_HERE     * for non-existent objects, which is resolved on invocation.  This     * "bug" is unavoidable, since in general the object may be destroyed     * between a locate and a request.  Note that this only checks that     * the appropriate ObjectAdapter is available, not that the servant     * actually exists.     * Need to signal one of OBJECT_HERE, OBJECT_FORWARD, OBJECT_NOT_EXIST.     * @return Result is null if object is (possibly) implemented here, otherwise     * an IOR indicating objref to forward the request to.     * @exception OBJECT_NOT_EXIST is thrown if we know the object does not      * exist here, and we are not forwarding.     */    public IOR locate(ObjectKey okey)     {	try {	    if (orb.subcontractDebugFlag)		dprint(".locate->");	    ObjectKeyTemplate oktemp = okey.getTemplate() ;	    try {		checkServerId(okey);	    } catch (ForwardException fex) {		return fex.getIOR() ;	    }	    // Called only for its side-effect of throwing appropriate exceptions	    findObjectAdapter(oktemp);	    return null ;	} finally {	    if (orb.subcontractDebugFlag)		dprint(".locate<-");	}     }		    public void dispatch(MessageMediator messageMediator)    {	CorbaMessageMediator request = (CorbaMessageMediator) messageMediator;	try {	    if (orb.subcontractDebugFlag) {		dprint(".dispatch->: " + opAndId(request));	    }	    // to set the codebase information, if any transmitted; and also	    // appropriate ORB Version.	    consumeServiceContexts(request);	    // Now that we have the service contexts processed and the	    // correct ORBVersion set, we must finish initializing the	    // stream.	    ((MarshalInputStream)request.getInputObject())		.performORBVersionSpecificInit();	    ObjectKey okey = request.getObjectKey();	    // Check that this server is the right server	    try {		checkServerId(okey);	    } catch (ForwardException fex) {		if (orb.subcontractDebugFlag) {		    dprint(".dispatch: " + opAndId(request) 			   + ": bad server id");		}		request.getProtocolHandler()		    .createLocationForward(request, fex.getIOR(), null);		return;	    }	    String operation = request.getOperationName();	    ObjectAdapter objectAdapter = null ;	    try {		byte[] objectId = okey.getId().getId() ;		ObjectKeyTemplate oktemp = okey.getTemplate() ;		objectAdapter = findObjectAdapter(oktemp);		java.lang.Object servant = getServantWithPI(request, objectAdapter, 		    objectId, oktemp, operation);		dispatchToServant(servant, request, objectId, objectAdapter);	    } catch (ForwardException ex) {		if (orb.subcontractDebugFlag) {		    dprint(".dispatch: " + opAndId(request)			   + ": ForwardException caught");		}		// Thrown by Portable Interceptors from InterceptorInvoker,		// through Response constructor.		request.getProtocolHandler()		    .createLocationForward(request, ex.getIOR(), null);	    } catch (OADestroyed ex) {		if (orb.subcontractDebugFlag) {		    dprint(".dispatch: " + opAndId(request)			   + ": OADestroyed exception caught");		}		// DO NOT CALL THIS HERE:		// releaseServant(objectAdapter);		// The problem is that OADestroyed is only thrown by oa.enter, in		// which case oa.exit should NOT be called, and neither should		// the invocationInfo stack be popped.		// Destroyed POAs can be recreated by normal adapter activation.		// So just restart the dispatch.		dispatch(request);	    } catch (RequestCanceledException ex) {		if (orb.subcontractDebugFlag) {		    dprint(".dispatch: " + opAndId(request)			   + ": RequestCanceledException caught");		}		// IDLJ generated non-tie based skeletons do not catch the		// RequestCanceledException. Rethrow the exception, which will		// cause the worker thread to unwind the dispatch and wait for		// other requests.		throw ex;	    } catch (UnknownException ex) {		if (orb.subcontractDebugFlag) {		    dprint(".dispatch: " + opAndId(request)			   + ": UnknownException caught " + ex);		}		// RMIC generated tie skeletons convert all Throwable exception		// types (including RequestCanceledException, ThreadDeath)		// thrown during reading fragments into UnknownException.		// If RequestCanceledException was indeed raised,		// then rethrow it, which will eventually cause the worker		// thread to unstack the dispatch and wait for other requests.		if (ex.originalEx instanceof RequestCanceledException) {		    throw (RequestCanceledException) ex.originalEx;		}		ServiceContexts contexts = new ServiceContexts(orb);		UEInfoServiceContext usc = new UEInfoServiceContext(		    ex.originalEx);		contexts.put( usc ) ;		SystemException sysex = wrapper.unknownExceptionInDispatch( 			CompletionStatus.COMPLETED_MAYBE, ex ) ;		request.getProtocolHandler()		    .createSystemExceptionResponse(request, sysex, 			contexts);	    } catch (Throwable ex) {		if (orb.subcontractDebugFlag) {		    dprint(".dispatch: " + opAndId(request)			   + ": other exception " + ex);		}		request.getProtocolHandler()		    .handleThrowableDuringServerDispatch(                        request, ex, CompletionStatus.COMPLETED_MAYBE);	    }	    return;	} finally {	    if (orb.subcontractDebugFlag) {		dprint(".dispatch<-: " + opAndId(request));	    }	}    }    private void releaseServant(ObjectAdapter objectAdapter)     {	try {	    if (orb.subcontractDebugFlag) {		dprint(".releaseServant->");	    }	    if (objectAdapter == null) {		if (orb.subcontractDebugFlag) {		    dprint(".releaseServant: null object adapter");		}		return ;	    }	    try {		objectAdapter.returnServant();	    } finally {		objectAdapter.exit();		orb.popInvocationInfo() ;	    }	} finally {	    if (orb.subcontractDebugFlag) {		dprint(".releaseServant<-");	    }	}    }    // Note that objectAdapter.enter() must be called before getServant.    private java.lang.Object getServant(ObjectAdapter objectAdapter, byte[] objectId,	String operation) 	throws OADestroyed    {	try {	    if (orb.subcontractDebugFlag) {		dprint(".getServant->");	    }	    OAInvocationInfo info = objectAdapter.makeInvocationInfo(objectId);	    info.setOperation(operation);	    orb.pushInvocationInfo(info);	    objectAdapter.getInvocationServant(info);	    return info.getServantContainer() ;	} finally {	    if (orb.subcontractDebugFlag) {		dprint(".getServant<-");	    }	}    }    protected java.lang.Object getServantWithPI(CorbaMessageMediator request,						 ObjectAdapter objectAdapter,	byte[] objectId, ObjectKeyTemplate oktemp, String operation) 	throws OADestroyed     {	try {	    if (orb.subcontractDebugFlag) {		dprint(".getServantWithPI->");	    }	    // Prepare Portable Interceptors for a new server request	    // and invoke receive_request_service_contexts.  The starting	    // point may throw a SystemException or ForwardException.	    orb.getPIHandler().initializeServerPIInfo(request, objectAdapter,		objectId, oktemp);	    orb.getPIHandler().invokeServerPIStartingPoint();	    objectAdapter.enter() ;	    // This must be set just after the enter so that exceptions thrown by 	    // enter do not cause 	    // the exception reply to pop the thread stack and do an extra oa.exit.	    if (request != null)		request.setExecuteReturnServantInResponseConstructor(true);	    java.lang.Object servant = getServant(objectAdapter, objectId, 		operation);	    // Note: we do not know the MDI on a null servant.	    // We only end up in that situation if _non_existent called,	    // so that the following handleNullServant call does not throw an 	    // exception.	    String mdi = "unknown" ;	    if (servant instanceof NullServant) 		handleNullServant(operation, (NullServant)servant);	    else 		mdi = objectAdapter.getInterfaces(servant, objectId)[0] ;	    orb.getPIHandler().setServerPIInfo(servant, mdi);	    if (((servant != null) &&		!(servant instanceof org.omg.CORBA.DynamicImplementation) &&		!(servant instanceof org.omg.PortableServer.DynamicImplementation)) ||		(SpecialMethod.getSpecialMethod(operation) != null)) {		orb.getPIHandler().invokeServerPIIntermediatePoint();	    }	    return servant ;	} finally {	    if (orb.subcontractDebugFlag) {		dprint(".getServantWithPI<-");	    }	}    }    protected void checkServerId(ObjectKey okey)     {	try {	    if (orb.subcontractDebugFlag) {		dprint(".checkServerId->");	    }	    ObjectKeyTemplate oktemp = okey.getTemplate() ;	    int sId = oktemp.getServerId() ;	    int scid = oktemp.getSubcontractId() ;	    if (!orb.isLocalServerId(scid, sId)) {		if (orb.subcontractDebugFlag) {		    dprint(".checkServerId: bad server id");		}		orb.handleBadServerId(okey);	    }	} finally {	    if (orb.subcontractDebugFlag) {		dprint(".checkServerId<-");	    }	}    }    private ObjectAdapter findObjectAdapter(ObjectKeyTemplate oktemp)    {	try {	    if (orb.subcontractDebugFlag) {		dprint(".findObjectAdapter->");	    }	    RequestDispatcherRegistry scr = orb.getRequestDispatcherRegistry() ;	    int scid = oktemp.getSubcontractId() ;	    ObjectAdapterFactory oaf = scr.getObjectAdapterFactory(scid);	    if (oaf == null) {		if (orb.subcontractDebugFlag) {		    dprint(".findObjectAdapter: failed to find ObjectAdapterFactory");		}		throw wrapper.noObjectAdapterFactory() ;	    }	    ObjectAdapterId oaid = oktemp.getObjectAdapterId() ;	    ObjectAdapter oa = oaf.find(oaid);	    if (oa == null) {		if (orb.subcontractDebugFlag) {		    dprint(".findObjectAdapter: failed to find ObjectAdaptor");		}		throw wrapper.badAdapterId() ;	    }	    return oa ;	} finally {	    if (orb.subcontractDebugFlag) {		dprint(".findObjectAdapter<-");	    }	}    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -