uka.karmi.rmi
Class ServerConnection

java.lang.Object
  extended byuka.transport.JdkMarshalContext
      extended byuka.karmi.rmi.Connection
          extended byuka.karmi.rmi.ServerConnection
All Implemented Interfaces:
CallHandler.BlockingOperation, CallHandler.CallbackOperation, Constants, RMACallback
Direct Known Subclasses:
StreamServerConnection

public abstract class ServerConnection
extends Connection
implements CallHandler.CallbackOperation, CallHandler.BlockingOperation, RMACallback, Constants

Connection objects represent the context of a remote method invocation. Stub and skeleton objects use connections to marshal and unmarshal method arguments and results.

Author:
Bernhard Haumacher
See Also:
StreamServerConnection

Field Summary
(package private)  java.lang.Throwable dispatchProblem
          Temporarily stores an exception that is thrown in doCallback(boolean).
protected  ExportPoint ep
          The export point this connection belongs to.
protected static CallHandler handlers
           
private  java.lang.Throwable receivingProblem
           
protected  Technology technology
          The technology this connection belongs to.
protected  boolean useTID
          The status of this invocation.
 
Fields inherited from class uka.karmi.rmi.Connection
cid, mid, oid, RETURN_EXCEPTION, RETURN_INTERNAL, RETURN_INTERRUPT, RETURN_OK, tid
 
Fields inherited from class uka.transport.JdkMarshalContext
 
Fields inherited from interface uka.karmi.rmi.server.Constants
APP_CALL, COLLECTIVE_OPERATION, DGC_ACK, DGC_CALL, DGC_CALL_ASYNC, MID_BARRIER, MID_COLLECTIVE_EXCHANGE, MID_COLLECTIVE_UPDATE, MID_EXCLUSIVE_LOCK, MID_EXCLUSIVE_UPDATE, MID_REQUEST_TICKET, MID_REQUEST_WAIT, MID_RMA, MID_SERVICE_CREATE_REPLICA, MID_SERVICE_GET_STUB, MID_SERVICE_INTERRUPT, MID_SERVICE_MIGRATE, MID_SERVICE_UPDATE_REFERENCES, MID_WAKEUP, SERVICE_CALL, SKELETON_EXTENSION, STUB_EXTENSION
 
Constructor Summary
ServerConnection(MarshalOutput snd, MarshalInput rcv, ExportPoint ep, Technology technology)
           
 
Method Summary
abstract  void closeReceiveCall()
          Indicates that the call was received successfully.
abstract  void closeReceiveDgcCall()
           
 void closeSendDgcResult()
           
 void closeSendResult()
          Connection cleanup.
 void dispatch(boolean useTID)
          The dispatch() method is the main entry point for incoming calls.
 boolean dispatchInterrupt()
          If a thread that waits for this blocking operation to complete is interrupted, this method is called to anounce the interrupt.
protected  void doAsyncDGCCall(int methodId, java.lang.Object argument)
           
 void doBlocking()
          Receives the monitor release code from this connection.
 void doCallback(boolean isCallback)
          Represents the callback.
protected  java.lang.Object doDGCCall(int methodId, java.lang.Object argument)
           
 void doSynchronized()
          Callback executed while a remote server thread has acquired a monitor on a remote object in a remote monitor acquisition operation.
 java.lang.Throwable getBlockingProblem()
           
 java.lang.Throwable getCallbackProblem()
          Returns an exception thrown during the execution of doCallback(boolean), or null is no excetion was thrown.
static CallHandler getHandler()
           
 RemoteServerRef getRemoteServerRef()
           
 long getThreadID()
           
abstract  void openReceiveCall()
          Receive connection parameters Connection.cid, Connection.oid, Connection.mid, and Connection.tid.
 void openSendResult(boolean normalReturn)
          Called from the skeleton to indicate the type of a remote method return.
protected abstract  void openSendResult(byte code)
           
static void releaseHandler(CallHandler handler)
           
 java.lang.String toStringMembers()
           
 
Methods inherited from class uka.karmi.rmi.Connection
closeAsynchronousCall, toString
 
Methods inherited from class uka.transport.JdkMarshalContext
areObjectsReceived, areObjectsSent, close, closeReceivePrimitive, closeSendPrimitive, flush, getMarshalStream, getUnmarshalStream, openReceivePrimitive, openSendPrimitive, receiveBoolean, receiveByte, receiveChar, receiveDouble, receiveFloat, receiveInt, receiveLong, receiveObject, receiveSingleBoolean, receiveSingleByte, receiveSingleChar, receiveSingleDouble, receiveSingleFloat, receiveSingleInt, receiveSingleLong, resetReceive, resetSend, sendBoolean, sendByte, sendChar, sendDouble, sendFloat, sendInt, sendLong, sendObject, sendSingleBoolean, sendSingleByte, sendSingleChar, sendSingleDouble, sendSingleFloat, sendSingleInt, sendSingleLong
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

ep

protected ExportPoint ep
The export point this connection belongs to.


technology

protected Technology technology
The technology this connection belongs to.


useTID

protected boolean useTID
The status of this invocation. The variable is set from the dispatch(boolean) method to true, if this server connection is dispatched in an application thread that is currently waiting for a former method to return. If this is the case, setting and resetting the thread ID can be avoided, because the thread executing the dispatch already has set the correct thread ID.

See Also:
dispatch(boolean)

receivingProblem

private java.lang.Throwable receivingProblem
See Also:
getBlockingProblem()

handlers

protected static CallHandler handlers
See Also:
getHandler()

dispatchProblem

java.lang.Throwable dispatchProblem
Temporarily stores an exception that is thrown in doCallback(boolean).

See Also:
getCallbackProblem(), doCallback(boolean), CallHandler
Constructor Detail

ServerConnection

public ServerConnection(MarshalOutput snd,
                        MarshalInput rcv,
                        ExportPoint ep,
                        Technology technology)
Method Detail

getRemoteServerRef

public RemoteServerRef getRemoteServerRef()
                                   throws NoSuchObjectException
Throws:
NoSuchObjectException

openReceiveCall

public abstract void openReceiveCall()
                              throws java.io.IOException
Receive connection parameters Connection.cid, Connection.oid, Connection.mid, and Connection.tid.

Throws:
java.io.IOException

closeReceiveCall

public abstract void closeReceiveCall()
                               throws java.io.IOException

Indicates that the call was received successfully. This method is called by the skeleton just before invoking the server method.

At the time, this method is called the following has happened: The skeleton has already unmarshaled the arguments form this connection in its doApplicationCall() method.

This method belongs to the server-side skeleton interface of the connection.

Throws:
java.io.IOException
See Also:
RemoteSkeleton.doApplicationCall(ServerConnection)

closeReceiveDgcCall

public abstract void closeReceiveDgcCall()
                                  throws java.io.IOException
Throws:
java.io.IOException
See Also:
closeReceiveCall()

openSendResult

protected abstract void openSendResult(byte code)
                                throws java.io.IOException
Parameters:
code - Legal values are: RETURN_OK, RETURN_EXCEPTION, RETURN_OK | RETURN_INTERRUPT, RETURN_EXCEPTION | RETURN_INTERRUPT, RETURN_INTERNAL
Throws:
java.io.IOException
See Also:
Connection.RETURN_OK, Connection.RETURN_EXCEPTION, Connection.RETURN_INTERRUPT, Connection.RETURN_INTERNAL

openSendResult

public final void openSendResult(boolean normalReturn)
                          throws java.io.IOException

Called from the skeleton to indicate the type of a remote method return. Either the result value , or the exception that is thrown from the server is marshaled back to the caller.

This method is called after the server implementation method returns.

This method belongs to the server-side skeleton interface of the connection.

Parameters:
normalReturn - true, if the server method returned normally, false, if the server implementation method threw an exception.
Throws:
java.io.IOException

closeSendResult

public void closeSendResult()
                     throws java.io.IOException

Connection cleanup. After this method completes, the next remote call can be unmarshaled from this connection object. This method is invoked after a remote method invocation has been completed and the result is marshaled back to the caller.

This method belongs to the server-side skeleton interface of the connection.

Throws:
java.io.IOException
See Also:
dispatch(boolean)

closeSendDgcResult

public void closeSendDgcResult()
                        throws java.io.IOException
Throws:
java.io.IOException
See Also:
closeSendResult()

doSynchronized

public void doSynchronized()
                    throws java.lang.Throwable
Callback executed while a remote server thread has acquired a monitor on a remote object in a remote monitor acquisition operation. This method waits for the signal that the remotely acquired monitor should be released and makes sure that the executing server thread stays attentive for further remote calls that could possibly arrive at the local node in the meantime. The acquired monitor is signaled to be released by sending a single byte value over this connection. The reception of this release code is done in the doBlocking() method that is specified in the CallHandler.BlockingOperation interface.

Specified by:
doSynchronized in interface RMACallback
Throws:
java.lang.Throwable
See Also:
RMACallback, doBlocking()

doBlocking

public void doBlocking()
Receives the monitor release code from this connection. This method is called during a remote monitor acquisition operation. When this method returns, the remotely acquired monitor is released.

Specified by:
doBlocking in interface CallHandler.BlockingOperation
See Also:
CallHandler.BlockingOperation

getBlockingProblem

public java.lang.Throwable getBlockingProblem()
Specified by:
getBlockingProblem in interface CallHandler.BlockingOperation
See Also:
CallHandler.BlockingOperation

dispatchInterrupt

public boolean dispatchInterrupt()
Description copied from interface: CallHandler.BlockingOperation
If a thread that waits for this blocking operation to complete is interrupted, this method is called to anounce the interrupt. It returns whether the interrupt was delivered successfully. If the method returns false, the interrupt will be signaled to the waiting thread when it resumes operation.

Specified by:
dispatchInterrupt in interface CallHandler.BlockingOperation
See Also:
CallHandler.BlockingOperation

getHandler

public static final CallHandler getHandler()

releaseHandler

public static final void releaseHandler(CallHandler handler)

getThreadID

public long getThreadID()
Specified by:
getThreadID in interface CallHandler.CallbackOperation
See Also:
CallHandler.CallbackOperation

doCallback

public void doCallback(boolean isCallback)
Description copied from interface: CallHandler.CallbackOperation
Represents the callback. The callback gets information whether it is executed as callback to a CallHandler.BlockingOperation or wheter it is dispatched directly.

Specified by:
doCallback in interface CallHandler.CallbackOperation
Parameters:
isCallback - is true if this is executed as callback to a CallHandler.BlockingOperation.
See Also:
CallHandler.CallbackOperation

getCallbackProblem

public java.lang.Throwable getCallbackProblem()
Description copied from interface: CallHandler.CallbackOperation
Returns an exception thrown during the execution of CallHandler.CallbackOperation.doCallback(boolean), or null is no excetion was thrown. Since CallHandler.CallbackOperation.doCallback(boolean) does not declare any exceptions to be thrown, it is expected to always return silently and store any exception for later processing.

Specified by:
getCallbackProblem in interface CallHandler.CallbackOperation
See Also:
CallHandler.CallbackOperation

dispatch

public void dispatch(boolean useTID)
              throws java.lang.Throwable

The dispatch() method is the main entry point for incoming calls. This method is called after unmarshaling the call header from the connection. It dispatches application calls to the corresponding server reference object. After looking up the server reference according to the object ID, the connection is forwarded to the doApplicationCall() method of the reference. After doApplicationCall() returns, the connection is cleaned up through closeSendResult().

Throws:
java.lang.Throwable
See Also:
RemoteServerRef.doApplicationCall(ServerConnection), closeSendResult()

doDGCCall

protected java.lang.Object doDGCCall(int methodId,
                                     java.lang.Object argument)
                              throws java.lang.Throwable
Throws:
java.lang.Throwable

doAsyncDGCCall

protected void doAsyncDGCCall(int methodId,
                              java.lang.Object argument)
                       throws java.lang.Throwable
Throws:
java.lang.Throwable

toStringMembers

public java.lang.String toStringMembers()
Overrides:
toStringMembers in class Connection