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

📄 serverdelegate.java

📁 java jdk 1.4的源码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                // different than in the POA case (see GenericPOAServerSC),                // but OK since this case is not covered by the spec                // anyway.                ((com.sun.corba.se.internal.corba.ORB)orb).                    initializeServerPIInfo( request, null,                    oid.getId(), oktemp.getAdapterId( orb ) );		// Note: we do not know the MDI on a null servant.		// We only end up in that situation if _non_existent called.                ((com.sun.corba.se.internal.corba.ORB)orb).                    setServerPIInfo( servant,				     (servant == null ?				      "unknown" :				      ((ObjectImpl)servant)._ids()[0]) );                // Invoke server starting interception points:                ((com.sun.corba.se.internal.corba.ORB)orb).                    invokeServerPIStartingPoint();                // Note: org.omg.CORBA.DynamicImplementation is deprecated!                if( ((servant != null) &&		     !(servant instanceof DynamicImplementation) ) ||                    SpecialMethod.isSpecialMethod( operation ) )                {                    ((com.sun.corba.se.internal.corba.ORB)orb).                        invokeServerPIIntermediatePoint();                }                if (SpecialMethod.isSpecialMethod(operation)) {                    if (orb.subcontractDebugFlag)                        dprint( "Handling special method" ) ;                    response = SpecialMethod.getSpecialMethod(                        operation).invoke(servant, request);                } else if (servant instanceof InvokeHandler) {                    if (orb.subcontractDebugFlag)                        dprint( "Handling invoke handler type servant" ) ;                    response = (ServerResponse)((InvokeHandler)servant)._invoke(                        operation, (org.omg.CORBA.portable.InputStream) request,                        request);                } else {                    if (orb.subcontractDebugFlag)                        dprint( "Handling DSI type servant" ) ;                    // Invoke on servant using DSI                    ServerRequestImpl sreq = new ServerRequestImpl(request,                                                                   orb);                    DynamicImplementation dServant =                        (DynamicImplementation)servant;                    OutputStream os;                    InputStream is = (InputStream) request;                    dServant.invoke(sreq);                    // Check if ServerRequestImpl.result() has been called                    Any excany = sreq.checkResultCalled();                    if ( excany == null ) { // normal return                        if (orb.subcontractDebugFlag)                            dprint( "DSI type servant: normal response" ) ;                        response = request.createResponse(null);                        // Marshal out/inout/return parameters into the                        // ReplyMessage                        os = (OutputStream) response;                        sreq.marshalReplyParams(os);                    } else {                        if (orb.subcontractDebugFlag)                            dprint( "DSI type servant: error response" ) ;                        // Check if the servant set a SystemException or                        // UserException                        String repId = excany.type().id();                        if (ORBUtility.isSystemException(repId)) {                            if (orb.subcontractDebugFlag)                                dprint( "DSI type servant: system exception" ) ;                            // Get the exception object from the Any                            InputStream in = excany.create_input_stream();                            SystemException ex =                                ORBUtility.readSystemException(in);                            // Marshal the exception back                            response = request.createSystemExceptionResponse(                                ex, null);                        } else {                            if (orb.subcontractDebugFlag)                                dprint( "DSI type servant: user exception" ) ;                            response =                                request.createUserExceptionResponse(null);                            os = (OutputStream) response;                            excany.write_value(os);                        }                    }                }            } catch (InternalRuntimeForwardRequest ex ) {                // In case PI throws a ForwardRequest:                // Get the IOR from the ForwardRequest and send it back.                response = handleInternalRuntimeForwardRequest(                    request, (ObjectImpl)ex.forward );            } catch (UnknownException ex) {                if (orb.subcontractDebugFlag)                    dprint( "After dispatch: Unknown exception " + 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 ) ;                try {                    contexts.put( usc ) ;                } catch (DuplicateServiceContext dsc) {                    // Can't happen, since we are adding usc to an empty                    // contexts object                }                SystemException sys = new UNKNOWN( 0,                    CompletionStatus.COMPLETED_MAYBE);                response = request.createSystemExceptionResponse(sys,contexts);            } catch (RequestCanceledException ex) {                // 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 (Throwable ex) {                if (orb.subcontractDebugFlag)                    dprint( "After dispatch: other exception " + ex ) ;		response = 		    orb.handleThrowableDuringServerDispatch(                        request,			ex,			CompletionStatus.COMPLETED_MAYBE);            }        }        catch( InternalRuntimeForwardRequest re ) {            // In case PI throws a ForwardRequest:            // Get the IOR from the ForwardRequest and send it back.            response = handleInternalRuntimeForwardRequest(                request, (ObjectImpl)re.forward );        }        return response;    }    /**     * Private utility method to handle PI internal runtime forwardrequest     * and create the appropriate location forward response for it.     */    private ServerResponse handleInternalRuntimeForwardRequest(        ServerRequest request, ObjectImpl foi )    {        ClientSubcontract delegate =            (ClientSubcontract)foi._get_delegate();        IOR ior = delegate.marshal();        return request.createLocationForward( ior, null );    }    public void destroyObjref(Object objref) {        // Get the delegate, then ior, then transientKey, then delete servant        ObjectImpl oi = (ObjectImpl)objref;        ClientSubcontract del = (ClientSubcontract)oi._get_delegate();        IOR ior = del.marshal();        ObjectId id = ior.getProfile().getObjectId() ;        byte[] transientKey = id.getId() ;        servants.deleteServant(transientKey);        del.unexport();    }    public Object createObjref(IOR ior) {        throw new INTERNAL( MinorCodes.WRONG_CLIENTSC,            CompletionStatus.COMPLETED_MAYBE);    }    public Object createObjref(byte[] key, Object servant) {        // Note that the key parameter is never used here.        // First, make sure this is an ObjectImpl.        ObjectImpl objectImpl = (ObjectImpl) servant;        // Store it and get a userkey allocated by the transient        // object manager.        key = servants.storeServant(objectImpl, null);        ObjectId oid = new ObjectId( key ) ;        ObjectKeyTemplate oktemp = new JIDLObjectKeyTemplate( scid,            orb.getTransientServerId() ) ;        ObjectKey okey = new ObjectKey( oktemp, oid ) ;        // Find out the repository ID for this servant.        String id = getId(objectImpl);        // Find out the port number to put in the IOR.        EndPoint endpoint = orb.getServerGIOP().getDefaultEndpoint();        if (endpoint == null) {            orb.getServerGIOP().initEndpoints();            endpoint = orb.getServerGIOP().getDefaultEndpoint();        }        int port = endpoint.getPort();        String host = endpoint.getHostName();        IOR ior = new IOR( orb, id, host, port, okey, servant ) ;        // Create the delegate and set it in the tie        ClientDelegate delegate = new ClientDelegate( orb,            ior, this.scid, servant ) ;        objectImpl._set_delegate( delegate ) ;        return objectImpl ;    }    public static String getId(ObjectImpl theTie) {        return theTie._ids()[0];    }    /**     * Handles setting the connection's code sets if required.     * Returns true if the CodeSetContext was in the request, false     * otherwise.     */    private boolean processCodeSetContext(ServerRequest request,                                          ServiceContexts contexts) {        try {            ServiceContext sc = contexts.get(CodeSetServiceContext.SERVICE_CONTEXT_ID);            // Somehow a code set service context showed up in the local case.            if (request.getConnection() == null) {                return true;            }            // If it's GIOP 1.0, it shouldn't have this context at all.  Our legacy            // ORBs sent it and we need to know if it's here to make ORB versioning            // decisions, but we don't use the contents.            if (request.getGIOPVersion().equals(GIOPVersion.V1_0)) {                return true;            }            CodeSetServiceContext cssc = (CodeSetServiceContext)sc ;            CodeSetComponentInfo.CodeSetContext csctx = cssc.getCodeSetContext();            // Note on threading:            //            // getCodeSetContext and setCodeSetContext are synchronized            // on the Connection.  At worst, this will result in             // multiple threads entering this block and calling             // setCodeSetContext but not actually changing the            // values on the Connection.            //            // Alternative would be to lock the connection for the            // whole block, but it's fine either way.            //            // The connection's codeSetContext is null until we've received a            // request with a code set context with the negotiated code sets.            if (request.getConnection().getCodeSetContext() == null) {                // Use these code sets on this connection                if (orb.subcontractDebugFlag)                    dprint("Setting code sets to: " + csctx);                request.getConnection().setCodeSetContext(csctx);                // We had to read the method name using ISO 8859-1                // (which is the default in the CDRInputStream for                // char data), but now we may have a new char                // code set.  If it isn't ISO8859-1, we must tell                // the CDR stream to null any converter references                // it has created so that it will reacquire                // the code sets again using the new info.                //                // This should probably compare with the stream's                // char code set rather than assuming it's ISO8859-1.                // (However, the operation name is almost certainly                // ISO8859-1 or ASCII.)                if (csctx.getCharCodeSet()                    != OSFCodeSetRegistry.ISO_8859_1.getNumber()) {                    request.resetCodeSetConverters();                }            }            return true;        } catch (NoSuchServiceContext exc) {            // If no code set information is ever sent from the client,            // the server will use ISO8859-1 for char and throw an            // exception for any wchar transmissions.            //            // In the local case, we use ORB provided streams for            // marshaling and unmarshaling.  Currently, they use            // ISO8859-1 for char/string and UTF16 for wchar/wstring.            return false;        }    }}

⌨️ 快捷键说明

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