📄 pihandlerimpl.java
字号:
RequestInfoStack infoStack = (RequestInfoStack)threadLocalClientRequestInfoStack.get(); infoStack.disableCount--; } public void invokeClientPIStartingPoint() throws RemarshalException { if( !hasClientInterceptors ) return; if( !isClientPIEnabledForThisThread() ) return; // Invoke the starting interception points and record exception // and reply status info in the info object: ClientRequestInfoImpl info = peekClientRequestInfoImplStack(); interceptorInvoker.invokeClientInterceptorStartingPoint( info ); // Check reply status. If we will not have another chance later // to invoke the client ending points, do it now. short replyStatus = info.getReplyStatus(); if( (replyStatus == SYSTEM_EXCEPTION.value) || (replyStatus == LOCATION_FORWARD.value) ) { // Note: Transport retry cannot happen here since this happens // before the request hits the wire. Exception exception = invokeClientPIEndingPoint( convertPIReplyStatusToReplyMessage( replyStatus ), info.getException() ); if( exception == null ) { // Do not throw anything. Otherwise, it must be a // SystemException, UserException or RemarshalException. } if( exception instanceof SystemException ) { throw (SystemException)exception; } else if( exception instanceof RemarshalException ) { throw (RemarshalException)exception; } else if( (exception instanceof UserException) || (exception instanceof ApplicationException) ) { // It should not be possible for an interceptor to throw // a UserException. By asserting instead of throwing the // UserException, we need not declare anything but // RemarshalException in the throws clause. throw wrapper.exceptionInvalid() ; } } else if( replyStatus != ClientRequestInfoImpl.UNINITIALIZED ) { throw wrapper.replyStatusNotInit() ; } } public Exception invokeClientPIEndingPoint( int replyStatus, Exception exception ) { if( !hasClientInterceptors ) return exception; if( !isClientPIEnabledForThisThread() ) return exception; // Translate ReplyMessage.replyStatus into PI replyStatus: // Note: this is also an assertion to make sure a valid replyStatus // is passed in (IndexOutOfBoundsException will be thrown otherwise) short piReplyStatus = REPLY_MESSAGE_TO_PI_REPLY_STATUS[replyStatus]; // Invoke the ending interception points and record exception // and reply status info in the info object: ClientRequestInfoImpl info = peekClientRequestInfoImplStack(); info.setReplyStatus( piReplyStatus ); info.setException( exception ); interceptorInvoker.invokeClientInterceptorEndingPoint( info ); piReplyStatus = info.getReplyStatus(); // Check reply status: if( (piReplyStatus == LOCATION_FORWARD.value) || (piReplyStatus == TRANSPORT_RETRY.value) ) { // If this is a forward or a retry, reset and reuse // info object: info.reset(); info.setRetryRequest( true ); // ... and return a RemarshalException so the orb internals know exception = new RemarshalException(); } else if( (piReplyStatus == SYSTEM_EXCEPTION.value) || (piReplyStatus == USER_EXCEPTION.value) ) { exception = info.getException(); } return exception; } public void initiateClientPIRequest( boolean diiRequest ) { if( !hasClientInterceptors ) return; if( !isClientPIEnabledForThisThread() ) return; // Get the most recent info object from the thread local // ClientRequestInfoImpl stack: RequestInfoStack infoStack = (RequestInfoStack)threadLocalClientRequestInfoStack.get(); ClientRequestInfoImpl info = null; if( !infoStack.empty() ) info = (ClientRequestInfoImpl)infoStack.peek(); if( !diiRequest && (info != null) && info.isDIIInitiate() ) { // In RequestImpl.doInvocation we already called // initiateClientPIRequest( true ), so ignore this initiate. info.setDIIInitiate( false ); } else { // If there is no info object or if we are not retrying a request, // push a new ClientRequestInfoImpl on the stack: if( (info == null) || !info.getRetryRequest() ) { info = new ClientRequestInfoImpl( orb ); infoStack.push( info ); printPush(); // Note: the entry count is automatically initialized to 0. } // Reset the retry request flag so that recursive calls will // push a new info object, and bump up entry count so we know // when to pop this info object: info.setRetryRequest( false ); info.incrementEntryCount(); // If this is a DII request, make sure we ignore the next initiate. if( diiRequest ) { info.setDIIInitiate( true ); } } } public void cleanupClientPIRequest() { if( !hasClientInterceptors ) return; if( !isClientPIEnabledForThisThread() ) return; ClientRequestInfoImpl info = peekClientRequestInfoImplStack(); // If the replyStatus has not yet been set, this is an indication // that the ORB threw an exception before we had a chance to // invoke the client interceptor ending points. // // _REVISIT_ We cannot handle any exceptions or ForwardRequests // flagged by the ending points here because there is no way // to gracefully handle this in any of the calling code. // This is a rare corner case, so we will ignore this for now. short replyStatus = info.getReplyStatus(); if( replyStatus == info.UNINITIALIZED ) { invokeClientPIEndingPoint( ReplyMessage.SYSTEM_EXCEPTION, wrapper.unknownRequestInvoke( CompletionStatus.COMPLETED_MAYBE ) ) ; } // Decrement entry count, and if it is zero, pop it from the stack. info.decrementEntryCount(); if( info.getEntryCount() == 0 ) { RequestInfoStack infoStack = (RequestInfoStack)threadLocalClientRequestInfoStack.get(); infoStack.pop(); printPop(); } } public void setClientPIInfo(CorbaMessageMediator messageMediator) { if( !hasClientInterceptors ) return; if( !isClientPIEnabledForThisThread() ) return; peekClientRequestInfoImplStack().setInfo(messageMediator); } public void setClientPIInfo( RequestImpl requestImpl ) { if( !hasClientInterceptors ) return; if( !isClientPIEnabledForThisThread() ) return; peekClientRequestInfoImplStack().setDIIRequest( requestImpl ); } /* ***************** * Server PI hooks *****************/ public void invokeServerPIStartingPoint() { if( !hasServerInterceptors ) return; ServerRequestInfoImpl info = peekServerRequestInfoImplStack(); interceptorInvoker.invokeServerInterceptorStartingPoint( info ); // Handle SystemException or ForwardRequest: serverPIHandleExceptions( info ); } public void invokeServerPIIntermediatePoint() { if( !hasServerInterceptors ) return; ServerRequestInfoImpl info = peekServerRequestInfoImplStack(); interceptorInvoker.invokeServerInterceptorIntermediatePoint( info ); // Clear servant from info object so that the user has control over // its lifetime: info.releaseServant(); // Handle SystemException or ForwardRequest: serverPIHandleExceptions( info ); } public void invokeServerPIEndingPoint( ReplyMessage replyMessage ) { if( !hasServerInterceptors ) return; ServerRequestInfoImpl info = peekServerRequestInfoImplStack(); // REVISIT: This needs to be done "early" for the following workaround. info.setReplyMessage( replyMessage ); // REVISIT: This was done inside of invokeServerInterceptorEndingPoint // but needs to be here for now. See comment in that method for why. info.setCurrentExecutionPoint( info.EXECUTION_POINT_ENDING ); // It is possible we might have entered this method more than // once (e.g. if an ending point threw a SystemException, then // a new ServerResponseImpl is created). if( !info.getAlreadyExecuted() ) { int replyStatus = replyMessage.getReplyStatus(); // Translate ReplyMessage.replyStatus into PI replyStatus: // Note: this is also an assertion to make sure a valid // replyStatus is passed in (IndexOutOfBoundsException will be // thrown otherwise) short piReplyStatus = REPLY_MESSAGE_TO_PI_REPLY_STATUS[replyStatus]; // Make forwarded IOR available to interceptors, if applicable: if( ( piReplyStatus == LOCATION_FORWARD.value ) || ( piReplyStatus == TRANSPORT_RETRY.value ) ) { info.setForwardRequest( replyMessage.getIOR() ); } // REVISIT: Do early above for now. // Make reply message available to interceptors: //info.setReplyMessage( replyMessage ); // Remember exception so we can tell if an interceptor changed it. Exception prevException = info.getException(); // _REVISIT_ We do not have access to the User Exception at // this point, so treat it as an UNKNOWN for now. // Note that if this is a DSI call, we do have the user exception. if( !info.isDynamic() && (piReplyStatus == USER_EXCEPTION.value) ) { info.setException( omgWrapper.unknownUserException( CompletionStatus.COMPLETED_MAYBE ) ) ; } // Invoke the ending interception points: info.setReplyStatus( piReplyStatus ); interceptorInvoker.invokeServerInterceptorEndingPoint( info ); short newPIReplyStatus = info.getReplyStatus(); Exception newException = info.getException(); // Check reply status. If an interceptor threw a SystemException // and it is different than the one that we came in with, // rethrow it so the proper response can be constructed: if( ( newPIReplyStatus == SYSTEM_EXCEPTION.value ) && ( newException != prevException ) ) { throw (SystemException)newException; } // If we are to forward the location: if( newPIReplyStatus == LOCATION_FORWARD.value ) { if( piReplyStatus != LOCATION_FORWARD.value ) { // Treat a ForwardRequest as a ForwardException. IOR ior = info.getForwardRequestIOR(); throw new ForwardException( orb, ior ) ; } else if( info.isForwardRequestRaisedInEnding() ) { // Treat a ForwardRequest by changing the IOR. replyMessage.setIOR( info.getForwardRequestIOR() ); } } } } public void setServerPIInfo( Exception exception ) { if( !hasServerInterceptors ) return; ServerRequestInfoImpl info = peekServerRequestInfoImplStack(); info.setException( exception ); } public void setServerPIInfo( NVList arguments ) { if( !hasServerInterceptors ) return; ServerRequestInfoImpl info = peekServerRequestInfoImplStack(); info.setDSIArguments( arguments ); } public void setServerPIExceptionInfo( Any exception ) { if( !hasServerInterceptors ) return; ServerRequestInfoImpl info = peekServerRequestInfoImplStack(); info.setDSIException( exception ); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -