FileDocCategorySizeDatePackage
ServerRequestInfoImpl.javaAPI DocJava SE 5 API28822Fri Aug 26 14:54:22 BST 2005com.sun.corba.se.impl.interceptors

ServerRequestInfoImpl

public final class ServerRequestInfoImpl extends RequestInfoImpl implements ServerRequestInfo
Implementation of the ServerRequestInfo interface as specified in orbos/99-12-02 section 5.4.3.

Fields Summary
static final int
CALL_RECEIVE_REQUEST_SERVICE_CONTEXT
static final int
CALL_RECEIVE_REQUEST
static final int
CALL_INTERMEDIATE_NONE
static final int
CALL_SEND_REPLY
static final int
CALL_SEND_EXCEPTION
static final int
CALL_SEND_OTHER
private boolean
forwardRequestRaisedInEnding
private CorbaMessageMediator
request
private Object
servant
private byte[]
objectId
private ObjectKeyTemplate
oktemp
private byte[]
adapterId
private String[]
adapterName
private ArrayList
addReplyServiceContextQueue
private ReplyMessage
replyMessage
private String
targetMostDerivedInterface
private NVList
dsiArguments
private Any
dsiResult
private Any
dsiException
private boolean
isDynamic
private ObjectAdapter
objectAdapter
private int
serverRequestId
private Parameter[]
cachedArguments
private Any
cachedSendingException
private HashMap
cachedRequestServiceContexts
private HashMap
cachedReplyServiceContexts
protected static final int
MID_SENDING_EXCEPTION
protected static final int
MID_OBJECT_ID
protected static final int
MID_ADAPTER_ID
protected static final int
MID_TARGET_MOST_DERIVED_INTERFACE
protected static final int
MID_GET_SERVER_POLICY
protected static final int
MID_SET_SLOT
protected static final int
MID_TARGET_IS_A
protected static final int
MID_ADD_REPLY_SERVICE_CONTEXT
protected static final int
MID_SERVER_ID
protected static final int
MID_ORB_ID
protected static final int
MID_ADAPTER_NAME
protected static final boolean[]
validCall
Constructors Summary
ServerRequestInfoImpl(ORB myORB)
Creates a new ServerRequestInfo implementation. The constructor is package scope since no other package need create an instance of this class.

    
    /*
     **********************************************************************
     * Public interfaces
     **********************************************************************/
    
                              
         
        super( myORB ); 
        startingPointCall = CALL_RECEIVE_REQUEST_SERVICE_CONTEXT;
        intermediatePointCall = CALL_RECEIVE_REQUEST;
        endingPointCall = CALL_SEND_REPLY;
	serverRequestId = myORB.getPIHandler().allocateServerRequestId();
    
Methods Summary
public synchronized byte[]adapter_id()
The opaque identifier for the object adapter.

        checkAccess( MID_ADAPTER_ID );

	if( adapterId == null ) {
	    checkForNullTemplate() ;
	    adapterId = oktemp.getAdapterId() ;
	}

	return adapterId;
    
public synchronized java.lang.String[]adapter_name()

	checkAccess( MID_ADAPTER_NAME ) ;

	if (adapterName == null) {
	    checkForNullTemplate() ;

	    ObjectAdapterId oaid = oktemp.getObjectAdapterId() ;
	    adapterName = oaid.getAdapterName() ;
	}

	return adapterName ;
    
public voidadd_reply_service_context(org.omg.IOP.ServiceContext service_context, boolean replace)
Allows Interceptors to add service contexts to the request.

	// access is currently valid for all states:
        //checkAccess( MID_ADD_REPLY_SERVICE_CONTEXT );

        if( currentExecutionPoint == EXECUTION_POINT_ENDING ) {
	    ServiceContexts scs = replyMessage.getServiceContexts();

	    // May be null.  If this is null, create a new one in its place.
	    if( scs == null ) {
		scs = new ServiceContexts( myORB );
		replyMessage.setServiceContexts( scs );
	    }

	    if( cachedReplyServiceContexts == null ) {
		cachedReplyServiceContexts = new HashMap();
	    }

	    // This is during and ending point, so we now have enough
	    // information to add the reply service context.
	    addServiceContext( cachedReplyServiceContexts, scs, 
			       service_context, replace );
	}

	// We enqueue all adds for the following reasons:
	//
	// If we are not in the ending point then we do not yet have a
	// pointer to the ServiceContexts object so we cannot access the
	// service contexts until we get to the ending point. 
	// So we enqueue this add reply service context request.
	// It is added when we do have a handle on the service contexts object.
	//
	// If we are in the ending point and we just add directly to the
	// SC container but then an interceptor raises a SystemException
	// then that add will be lost since a new container is created
	// for the SystemException response.
	//
	// Therefore we always enqueue and never dequeue (per request) so
	// that all adds will be completed.

	AddReplyServiceContextCommand addReply = 
	    new AddReplyServiceContextCommand();
	addReply.service_context = service_context;
	addReply.replace = replace;

	if( addReplyServiceContextQueue == null ) {
	    addReplyServiceContextQueue = new ArrayList();
	}

	// REVISIT: this does not add to the cache.
	enqueue( addReply );
    
public org.omg.Dynamic.Parameter[]arguments()
See ServerRequestInfo for javadocs.

        checkAccess( MID_ARGUMENTS );

	if( cachedArguments == null ) {
	    if( !isDynamic ) {
		throw stdWrapper.piOperationNotSupported1() ;
	    }

	    if( dsiArguments == null ) {
		throw stdWrapper.piOperationNotSupported8() ;
	    }

	    // If it is a DSI request then get the arguments from the DSI req
	    // and convert that into parameters.
	    cachedArguments = nvListToParameterArray( dsiArguments );
	}

        // Good citizen: In the interest of efficiency, we assume 
	// interceptors will be "good citizens" in that they will not 
	// modify the contents of the Parameter[] array.  We also assume 
	// they will not change the values of the containing Anys.

	return cachedArguments;
    
protected voidcheckAccess(int methodID)
See description for RequestInfoImpl.checkAccess

        // Make sure currentPoint matches the appropriate index in the
        // validCall table:
        int validCallIndex = 0;
        switch( currentExecutionPoint ) {
        case EXECUTION_POINT_STARTING:
            validCallIndex = 0;
            break;
        case EXECUTION_POINT_INTERMEDIATE:
            validCallIndex = 1;
            break;
        case EXECUTION_POINT_ENDING:
            switch( endingPointCall ) {
            case CALL_SEND_REPLY:
                validCallIndex = 2;
                break;
            case CALL_SEND_EXCEPTION:
                validCallIndex = 3;
                break;
            case CALL_SEND_OTHER:
                validCallIndex = 4;
                break;
            }
            break;
        }
        
        // Check the validCall table:
        if( !validCall[methodID][validCallIndex] ) {
	    throw stdWrapper.invalidPiCall2() ;
        }
    
private voidcheckForNullTemplate()

	if (oktemp == null) {
	    // For some reason, we never set the ObjectKeyTemplate
	    // because a servant locator caused a location forward or
	    // raised an exception.  As per ptc/00-08-06, section 21.3.14,
	    // we throw NO_RESOURCES
	    throw stdWrapper.piOperationNotSupported7() ;
	}
    
public java.lang.String[]contexts()
See ServerRequestInfo for javadocs.

        checkAccess( MID_CONTEXTS );

	// We do not support this because our ORB does not send contexts.

	throw stdWrapper.piOperationNotSupported3() ;
    
private voidenqueue(com.sun.corba.se.impl.interceptors.ServerRequestInfoImpl$AddReplyServiceContextCommand addReply)

	int size = addReplyServiceContextQueue.size();
	boolean found = false;

	for( int i = 0; i < size; i++ ) {
	    AddReplyServiceContextCommand cmd = 
		(AddReplyServiceContextCommand)
		addReplyServiceContextQueue.get( i );

	    if( cmd.service_context.context_id == 
		addReply.service_context.context_id ) 
	    {
		found = true;
		if( addReply.replace ) {
		    addReplyServiceContextQueue.set( i, addReply );
		} else {
		    throw stdWrapper.serviceContextAddFailed( 
			new Integer( cmd.service_context.context_id ) ) ;
		}
		break;
	    }
	}

	if( !found ) {
	    addReplyServiceContextQueue.add( addReply );
	}
    
public org.omg.CORBA.TypeCode[]exceptions()
See ServerRequestInfo for javadocs.

        checkAccess( MID_EXCEPTIONS );

	// _REVISIT_ PI RTF Issue: No exception list on server side.

	throw stdWrapper.piOperationNotSupported2() ;
    
public org.omg.CORBA.Objectforward_reference()
See ServerRequestInfo for javadocs.

        checkAccess( MID_FORWARD_REFERENCE );
        // Check to make sure we are in LOCATION_FORWARD
        // state as per ptc/00-08-06, table 21-2
        // footnote 2.
        if( replyStatus != LOCATION_FORWARD.value ) {
	    throw stdWrapper.invalidPiCall1() ;
        }

	return getForwardRequestException().forward;
    
public org.omg.IOP.ServiceContextget_reply_service_context(int id)
See ServerRequestInfo for javadocs.

        checkAccess( MID_GET_REPLY_SERVICE_CONTEXT );       

	if( cachedReplyServiceContexts == null ) {
	    cachedReplyServiceContexts = new HashMap();
	}

        return getServiceContext( cachedReplyServiceContexts,
				  replyMessage.getServiceContexts(), id );
    
public org.omg.IOP.ServiceContextget_request_service_context(int id)
See ServerRequestInfo for javadocs.

        checkAccess( MID_GET_REQUEST_SERVICE_CONTEXT );

	if( cachedRequestServiceContexts == null ) {
	    cachedRequestServiceContexts = new HashMap();
	}

	return getServiceContext( cachedRequestServiceContexts, 
				  request.getRequestServiceContexts(), id );
    
public org.omg.CORBA.Policyget_server_policy(int type)
Returns the policy in effect for this operation for the given policy type.

	// access is currently valid for all states:
        //checkAccess( MID_GET_SERVER_POLICY );

	Policy result = null;

	if( objectAdapter != null ) {
	    result = objectAdapter.getEffectivePolicy( type );
	}

	// _REVISIT_ RTF Issue: get_server_policy spec not in sync with
	// get_effective_policy spec.

	return result;
    
booleanisDynamic()
Returns true if this is a dynamic invocation, or false if not

      return this.isDynamic;
    
booleanisForwardRequestRaisedInEnding()
Returns true if ForwardRequest was raised by a server ending point or false otherwise.

	return this.forwardRequestRaisedInEnding;
    
public byte[]object_id()
The opaque object_id describing the target of the operation invocation.

        checkAccess( MID_OBJECT_ID );

	if( objectId == null ) {
	    // For some reason, we never set object id.  This could be 
	    // because a servant locator caused a location forward or
	    // raised an exception.  As per ptc/00-08-06, section 21.3.14,
	    // we throw NO_RESOURCES
	    throw stdWrapper.piOperationNotSupported6() ;
	}

	// Good citizen: In the interest of efficiency, we will assume
	// interceptors will not change the resulting byte[] array.
	// Otherwise, we would need to make a clone of this array.

	return objectId;
    
public java.lang.Stringoperation()
See ServerRequestInfo for javadocs.

        // access is currently valid for all states:
        //checkAccess( MID_OPERATION );
        return request.getOperationName();
    
public java.lang.String[]operation_context()
See ServerRequestInfo for javadocs.

        checkAccess( MID_OPERATION_CONTEXT );

	// We do not support this because our ORB does not send 
	// operation_context.

	throw stdWrapper.piOperationNotSupported4() ;
    
public java.lang.Stringorb_id()

	checkAccess( MID_ORB_ID ) ;

	return myORB.getORBData().getORBId() ;
    
voidreleaseServant()
Release the servant object so the user has control over its lifetime. Called after receive_request is finished executing.

        this.servant = null;
    
public intrequest_id()
See ServerRequestInfo for javadocs.

        // access is currently valid for all states:
        //checkAccess( MID_REQUEST_ID );
	/*
	 * NOTE: The request id in server interceptors is NOT the
	 * same as the GIOP request id.  The ORB may be servicing several
	 * connections, each with possibly overlapping sets of request ids.
	 * Therefore we create a request id specific to interceptors.
	 */
        return serverRequestId;
    
voidreset()
Reset the info object so that it can be reused for a retry, for example.

 
    
    //////////////////////////////////////////////////////////////////////
    //
    // NOTE: IF AN ATTRIBUTE IS ADDED, PLEASE UPDATE RESET();
    //
    //////////////////////////////////////////////////////////////////////
    

                        
      
        super.reset();

        // Please keep these in the same order as declared above.
        
        forwardRequestRaisedInEnding = false;

        request = null;
	servant = null;
	objectId = null;
	oktemp = null;

	adapterId = null;
	adapterName = null;

	addReplyServiceContextQueue = null;
	replyMessage = null;
	targetMostDerivedInterface = null;
	dsiArguments = null;
	dsiResult = null;
	dsiException = null;
	isDynamic = false;
	objectAdapter = null;
	serverRequestId = myORB.getPIHandler().allocateServerRequestId();

	// reset cached attributes:
	cachedArguments = null;
	cachedSendingException = null;
	cachedRequestServiceContexts = null;
	cachedReplyServiceContexts = null;

        startingPointCall = CALL_RECEIVE_REQUEST_SERVICE_CONTEXT;
        intermediatePointCall = CALL_RECEIVE_REQUEST;
        endingPointCall = CALL_SEND_REPLY;
    
public booleanresponse_expected()
See ServerRequestInfo for javadocs.

        // access is currently valid for all states:
        //checkAccess( MID_RESPONSE_EXPECTED );
        return !request.isOneWay();
    
public org.omg.CORBA.Anyresult()
See ServerRequestInfo for javadocs.

        checkAccess( MID_RESULT );

	if( !isDynamic ) {
	    throw stdWrapper.piOperationNotSupported5() ;
	}

	if( dsiResult == null ) {
	    throw wrapper.piDsiResultIsNull() ;
	}

	// Good citizen: In the interest of efficiency, we assume that
	// interceptors will not modify the contents of the result Any.
	// Otherwise, we would need to create a deep copy of the Any.

	return dsiResult;
    
public org.omg.CORBA.Anysending_exception()
Any containing the exception to be returned to the client.

        checkAccess( MID_SENDING_EXCEPTION );

	if( cachedSendingException == null ) {
	    Any result = null ;

	    if( dsiException != null ) {
		result = dsiException;
	    } else if( exception != null ) {
		result = exceptionToAny( exception );
	    } else {
		// sending_exception should not be callable if both dsiException
		// and exception are null.
		throw wrapper.exceptionUnavailable() ;
	    }

	    cachedSendingException = result;
	}

	return cachedSendingException;
    
public java.lang.Stringserver_id()

	checkAccess( MID_SERVER_ID ) ;
	checkForNullTemplate() ;

	// Good citizen: In the interest of efficiency, we will assume
	// interceptors will not change the resulting byte[] array.
	// Otherwise, we would need to make a clone of this array.

	return Integer.toString( oktemp.getServerId() ) ;
    
protected voidsetCurrentExecutionPoint(int executionPoint)
Overridden from RequestInfoImpl. This version calls the super and then, if we are changing to ending points, executes all enqueued AddReplyServiceContextCommands.

	super.setCurrentExecutionPoint( executionPoint );

	// If we are transitioning to ending point, we will now have a pointer
	// to the reply service contexts, so we can execute all queued
	// add reply service context requests.
	if( (executionPoint == EXECUTION_POINT_ENDING) &&
	    (addReplyServiceContextQueue != null) ) 
	{
	    int size = addReplyServiceContextQueue.size();
	    for( int i = 0; i < size; i++ ) {
		AddReplyServiceContextCommand addReply = 
		    (AddReplyServiceContextCommand)
		    addReplyServiceContextQueue.get( i );
		try {
		    add_reply_service_context( addReply.service_context, 
					       addReply.replace );
	        }
		catch( BAD_INV_ORDER e ) {
		    // _REVISIT_  The only way this can happen is if during 
		    // rrsc or rr, the interceptor tried to add with 
		    // replace=false to a service context that is present in 
		    // the reply message.  At that time there was no way for 
		    // us to check for this, so the best we can do is ignore 
		    // the original request.
		}
	    }

	    // We specifically do not empty the SC queue so that if
	    // the interceptor raises an exception the queued service contexts
	    // will be put in the exception response.
	}
    
protected voidsetDSIArguments(org.omg.CORBA.NVList arguments)
Stores the various sources of information used for this info object.

	this.dsiArguments = arguments;
    
protected voidsetDSIException(org.omg.CORBA.Any exception)
Stores the various sources of information used for this info object.

	this.dsiException = exception;

	// Clear cached exception value:
	cachedSendingException = null;
    
protected voidsetDSIResult(org.omg.CORBA.Any result)
Stores the various sources of information used for this info object.

	this.dsiResult = result;
    
protected voidsetException(java.lang.Exception exception)
Sets the exception to be returned by received_exception and received_exception_id.

	super.setException( exception );

	// Make sure DSIException is null because this is the more recent one.
	this.dsiException = null;

	// Clear cached exception value:
	cachedSendingException = null;
    
voidsetForwardRequestRaisedInEnding()
Sets the forwardRequestRaisedInEnding flag to true, indicating that a server ending point has raised location forward at some point.

	this.forwardRequestRaisedInEnding = true;
    
protected voidsetInfo(com.sun.corba.se.spi.protocol.CorbaMessageMediator request, com.sun.corba.se.spi.oa.ObjectAdapter oa, byte[] objectId, com.sun.corba.se.spi.ior.ObjectKeyTemplate oktemp)
Stores the various sources of information used for this info object.

        this.request = request;
        this.objectId = objectId;
	this.oktemp = oktemp;
	this.objectAdapter = oa ;
	this.connection = (com.sun.corba.se.spi.legacy.connection.Connection)
	    request.getConnection();
    
protected voidsetInfo(java.lang.Object servant, java.lang.String targetMostDerivedInterface)
Stores the various sources of information used for this info object.

        this.servant = servant;
	this.targetMostDerivedInterface = targetMostDerivedInterface;
	this.isDynamic = 
	    (servant instanceof 
	    org.omg.PortableServer.DynamicImplementation) ||
	    (servant instanceof org.omg.CORBA.DynamicImplementation);
    
voidsetReplyMessage(com.sun.corba.se.impl.protocol.giopmsgheaders.ReplyMessage replyMessage)
Set reply message

	this.replyMessage = replyMessage;
    
protected voidsetReplyStatus(short replyStatus)
Overridden from RequestInfoImpl. Calls the super class, then sets the ending point call depending on the reply status.

        super.setReplyStatus( replyStatus );
        switch( replyStatus ) {
        case SUCCESSFUL.value:
            endingPointCall = CALL_SEND_REPLY;
            break;
        case SYSTEM_EXCEPTION.value:
        case USER_EXCEPTION.value:
            endingPointCall = CALL_SEND_EXCEPTION;
            break;
        case LOCATION_FORWARD.value:
        case TRANSPORT_RETRY.value:
            endingPointCall = CALL_SEND_OTHER;
            break;
        }
    
public voidset_slot(int id, org.omg.CORBA.Any data)
Allows an Interceptor to set a slot in the Current that is in the scope of the request. If data already exists in that slot, it will be overwritten. If the ID does not define an allocated slot, InvalidSlot is raised.

	// access is currently valid for all states:
        //checkAccess( MID_SET_SLOT );
   
        slotTable.set_slot( id, data );
    
public booleantarget_is_a(java.lang.String id)
Returns true if the servant is the given RepositoryId, false if it is not.

        checkAccess( MID_TARGET_IS_A );

	boolean result = false ;
	if( servant instanceof Servant ) {
	    result = ((Servant)servant)._is_a( id );
	} else if (StubAdapter.isStub( servant )) {
	    result = ((org.omg.CORBA.Object)servant)._is_a( id );
	} else {
	    throw wrapper.servantInvalid() ;
	}

	return result;
    
public java.lang.Stringtarget_most_derived_interface()
The RepositoryID for the most derived interface of the servant.

        checkAccess( MID_TARGET_MOST_DERIVED_INTERFACE );
	return targetMostDerivedInterface;