📄 genericpoaserversc.java
字号:
/* * @(#)GenericPOAServerSC.java 1.80 03/01/23 * * Copyright 2003 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */package com.sun.corba.se.internal.POA;import java.util.Iterator ;import org.omg.PortableServer.*;import org.omg.PortableServer.ServantLocatorPackage.*;import org.omg.CORBA.Any;import org.omg.CORBA.CompletionStatus;import org.omg.CORBA.SystemException;import org.omg.CORBA.OBJECT_NOT_EXIST;import org.omg.CORBA.OBJ_ADAPTER;import org.omg.CORBA.INTERNAL;import org.omg.CORBA.UNKNOWN;import org.omg.CORBA.portable.*;import org.omg.PortableServer.DynamicImplementation;import com.sun.corba.se.internal.core.*;import com.sun.corba.se.internal.corba.*;import com.sun.corba.se.internal.orbutil.ORBUtility; //d11638import com.sun.corba.se.internal.orbutil.ORBConstants;import com.sun.corba.se.internal.ior.ObjectKey ;import com.sun.corba.se.internal.ior.ObjectKeyFactory ;import com.sun.corba.se.internal.ior.ObjectId ;import com.sun.corba.se.internal.ior.ObjectKeyTemplate ;import com.sun.corba.se.internal.ior.POAObjectKeyTemplate ;import com.sun.corba.se.internal.ior.IIOPProfile ;import com.sun.corba.se.internal.ior.POAId ;import com.sun.corba.se.internal.iiop.RequestCanceledException;import javax.rmi.CORBA.Tie;/** The general-purpose server-side subcontract for the POA ORB. * It handles ORB processing for transient, persistent, non-transactional * and transactional server objects. * Its main functionality is: * 1. on each incoming request, find a POA and deliver the request to it. * 2. create delegates (to be embedded in object references) for a server * object in a POA with a given quality of service. The subcontract * thus controls the layout of fields in the objectKey in the IOR. * The quality of service of the server object is known from the subcontract-id * variable ("scid"). */public class GenericPOAServerSC extends ServerDelegate{ public GenericPOAServerSC() { super(); } public GenericPOAServerSC(POAORB o) { super(o); } public static boolean isTransient(int subcontractId) { // 2nd bit in subcontract id is 0 for transient case. return ((subcontractId & 2)==0); } /** dispatch() is the start of the upcall for remote invocations. * The IIOPInputStream cursor is at the end of the RequestHeader * and the request's arguments can be read directly. On return * the IIOPOutputStream should contain the entire reply message * (ReplyHeader + return arguments). */ public ServerResponse dispatch(ServerRequest req) { if (orb.subcontractDebugFlag) dprint( "dispatch entered" ) ; POAORB poaorb = (POAORB)orb; ObjectKey okey = req.getObjectKey(); ObjectKeyTemplate oktemp = okey.getTemplate() ; int sId = oktemp.getServerId() ; if (orb.subcontractDebugFlag) dprint( "dispatch: sId = " + sId ) ; // to set the codebase information, if any transmitted; and also // appropriate ORB Version. consumeServiceContexts(req); // Now that we have the service contexts processed and the // correct ORBVersion set, we must finish initializing the // stream. req.performORBVersionSpecificInit(); // If this is a transient SC, then check if the serverid matches // this server's transientServerId. Else check if the serverid // matches this server's persistentServerId. if ( (isTransient(scid) && sId == poaorb.getTransientServerId()) || (!isTransient(scid) && poaorb.persistentServerIdInitialized && sId == poaorb.getPersistentServerId()) ) { return internalDispatch(req, okey); } else if ( poaorb.getBadServerIdHandler() != null ) { // e.g. in ORBD try { if (orb.subcontractDebugFlag) dprint( "dispatch: handling Bad server id (may be ORBD)" ) ; // will throw an exception: ForwardException poaorb.getBadServerIdHandler().handle(okey); } catch ( ForwardException fex ) { IOR ior = fex.getIOR(); return req.createLocationForward(ior, null); } } else { throw new OBJECT_NOT_EXIST( com.sun.corba.se.internal.orbutil.MinorCodes.BAD_SERVER_ID, CompletionStatus.COMPLETED_NO); } return null; // to keep javac happy } private ServerResponse internalDispatch(ServerRequest req, ObjectKey okey ) { if (orb.subcontractDebugFlag) dprint( "internalDispatch entered" ) ; byte[] objectId = okey.getId().getId() ; ObjectKeyTemplate oktemp = okey.getTemplate() ; POAId poaid = null ; if (oktemp instanceof POAObjectKeyTemplate) { POAObjectKeyTemplate poktemp = (POAObjectKeyTemplate)oktemp ; poaid = poktemp.getPOAId() ; } int targetScid = oktemp.getSubcontractId() ; if (orb.subcontractDebugFlag) dprint( "internalDispatch: targetScid = " + targetScid ) ; String operation = req.getOperationName(); CookieHolder cookieHolder = new CookieHolder(); POAImpl poaimpl=null; Servant servant=null; //The following is and INTERNAL minor code. //Use it only with INTERNAL exceptions. int mc = MinorCodes.SERVANT_LOOKUP ; ServerResponse resp = null ; try { poaimpl = (POAImpl)getPOA(poaid); // Prepare Portable Interceptors for a new server request // and invoke receive_request_service_contexts. The starting // point may throw a SystemException or ForwardRequest. byte[] adapterId = oktemp.getAdapterId( orb ); ((POAORB)orb).initializeServerPIInfo( req, poaimpl, objectId, adapterId ); ((POAORB)orb).invokeServerPIStartingPoint(); servant = poaimpl.getServant(objectId, cookieHolder, operation, req); if (servant == null) { boolean raiseObjectAdapterException = true; if (SpecialMethod.isSpecialMethod(operation)) { SpecialMethod specialMethod = SpecialMethod.getSpecialMethod(operation); if (specialMethod instanceof NonExistent || specialMethod instanceof NotExistent) { raiseObjectAdapterException = false; } } if (raiseObjectAdapterException) { throw new OBJ_ADAPTER(MinorCodes.NULL_SERVANT, CompletionStatus.COMPLETED_NO); } } // Store server request interceptor information and invoke // receive_request if this is not DSI. // Note: we do not know the MDI on a null servant. // We only end up in that situation if _non_existent called. ((POAORB)orb).setServerPIInfo( servant, (servant == null ? "unknown" : servant._all_interfaces( poaimpl, objectId )[0]) ); if( ((servant != null) && !(servant instanceof DynamicImplementation) ) || SpecialMethod.isSpecialMethod( operation ) ) { ((POAORB)orb).invokeServerPIIntermediatePoint(); } mc = MinorCodes.SERVANT_DISPATCH ; resp = dispatchToServant(servant, req, objectId, poaimpl, targetScid); } catch ( POADestroyed ex ) { if (orb.subcontractDebugFlag) dprint( "internalDispatch: POADestroyed exception caught" ) ; // REVISIT: does this need to be called explicitly? if (poaimpl != null) { poaimpl.returnServantAndRemoveThreadInfo(); } // Destroyed POAs can be recreated by normal adapter activation. // So just restart the dispatch. return internalDispatch(req, okey); } catch ( ForwardRequest ex ) { if (orb.subcontractDebugFlag) dprint( "internalDispatch: ForwardRequest exception caught" ) ; return handleInternalDispatchForwardRequest( (ObjectImpl)ex.forward_reference, req ); } catch ( InternalRuntimeForwardRequest ex ) { if (orb.subcontractDebugFlag) dprint( "internalDispatch: InternalRuntimeForwardRequest caught" ) ; // Thrown by Portable Interceptors from InterceptorInvoker, // through iiop.ServerResponseImpl constructor. return handleInternalDispatchForwardRequest( (ObjectImpl)ex.forward, req ); } catch (RequestCanceledException ex) { if (orb.subcontractDebugFlag) { dprint("internalDispatch: RequestCanceledException caught"); } // No need to do anything specific. This is handled // out in RequestProcessor. throw ex; } catch ( Throwable t ) { if (orb.subcontractDebugFlag) { dprint( "internalDispatch: Throwable caught: " + t ) ; t.printStackTrace( System.out) ; } resp = orb.handleThrowableDuringServerDispatch( req, t, CompletionStatus.COMPLETED_MAYBE); } return resp ; } // Internal utility method to handle a ForwardRequest from within // internalDispatch. private ServerResponse handleInternalDispatchForwardRequest( ObjectImpl foi, com.sun.corba.se.internal.core.ServerRequest req) { // Get the IOR from the ForwardRequest and send it back. ClientSubcontract delegate = (ClientSubcontract)foi._get_delegate(); IOR ior = delegate.marshal(); ServerResponse resp = req.createLocationForward(ior, null); return resp; } // Allow access from ServantCachePOAClientSC POA getPOA(POAId poaid) { if (poaid == null) throw new INTERNAL() ; POAORB poaorb = (POAORB)orb; POA poa=null; try { Iterator iter = poaid.iterator() ; poa = poaorb.getRootPOA(); while (iter.hasNext()) { String name = (String)(iter.next()) ; poa = poa.find_POA( name, true ) ; } } catch ( org.omg.PortableServer.POAPackage.AdapterNonExistent ex ){ throw new OBJ_ADAPTER(MinorCodes.POA_NOT_FOUND, CompletionStatus.COMPLETED_NO); } catch ( OBJECT_NOT_EXIST ex ) { throw ex; } catch ( Exception ex ) { throw new OBJ_ADAPTER(MinorCodes.POA_LOOKUP_ERROR, CompletionStatus.COMPLETED_NO); } if ( poa == null ) throw new OBJ_ADAPTER(MinorCodes.POA_LOOKUP_ERROR, CompletionStatus.COMPLETED_NO); return poa; } // This is used by the Util.isLocal case in rmi-iiop stubs. // Called from local stub thru GenericPOAClientSC. public ServantObject preinvoke(IOR targetIor, String method, Class expectedType) { byte[] objectId = targetIor.getObjectId() ; POAId poaid = targetIor.getPOAId() ; // Get servant CookieHolder cookieHolder = new CookieHolder(); POAImpl poaimpl=null; Servant servant=null; try { poaimpl = (POAImpl)getPOA(poaid); servant = poaimpl.getServant(objectId, cookieHolder, method, null); } catch ( POADestroyed ex ) { if (poaimpl != null) { poaimpl.returnServantAndRemoveThreadInfo(); } // Destroyed POAs can be recreated by normal adapter activation. // So just reinvoke this method. return preinvoke(targetIor, method, expectedType); } catch ( ForwardRequest ex ) { if (poaimpl != null) { poaimpl.returnServantAndRemoveThreadInfo(); } // REVISIT: java2idl rtf: // The isLocal branch does not have a remarshal loop to // handle ForwardRequest. Therefore, just return null. return null; } catch ( ThreadDeath ex ) { // Balancing happenings in ORB.process. throw ex; } catch ( Throwable t ) { if (poaimpl != null) { poaimpl.returnServantAndRemoveThreadInfo(); } SystemException ex; if ( t instanceof SystemException ) ex = (SystemException)t; else ex = new OBJ_ADAPTER(MinorCodes.LOCAL_SERVANT_LOOKUP, CompletionStatus.COMPLETED_NO); throw ex; } // No exceptions. So handle servant. if ( servant == null || ( ! (servant instanceof Tie) && !expectedType.isInstance(servant) ) ) { if (poaimpl != null) { poaimpl.returnServantAndRemoveThreadInfo(); } return null; } boolean alternateServant = false; if (servant != null && servant instanceof Tie ) { if(!expectedType.isInstance(((Tie)servant).getTarget())){ if (poaimpl != null) { poaimpl.returnServantAndRemoveThreadInfo(); } return null; } else alternateServant = true; } ServantObject servantObject = new ServantObject(); if (alternateServant) { //servant is Tie if alternate servant is set servantObject.servant = ((Tie)servant).getTarget();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -