Package com.sun.corba.ee.impl.transport
Class ConnectionImpl
java.lang.Object
com.sun.corba.ee.impl.transport.EventHandlerBase
com.sun.corba.ee.impl.transport.ConnectionImpl
- All Implemented Interfaces:
Connection,Work,Connection,EventHandler
- Direct Known Subclasses:
NoConnectionCacheImpl.NCCConnectionImpl,SocketFactoryConnectionImpl
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Acceptorprivate NioBufferWriterprotected ByteBufferprotected CachedCodeBaseprotected MessageMediatorprotected IORprotected CodeSetComponentInfo.CodeSetContextprotected ConnectionCacheprotected ContactInfoprivate Throwableprotected ConnectionImpl.Dispatcher(package private) static final ConnectionImpl.Dispatcherprotected longprotected ConcurrentHashMap<RequestId, Queue<MessageMediator>> protected booleanprivate MessageParserprotected booleanprotected AtomicIntegerprotected ResponseWaitingRoomprotected MessageMediatorprotected int(package private) Map<Integer, MessageMediator> protected Socketprotected SocketChannelprivate SocketChannelReaderprivate intprotected final Objectprotected TcpTimeoutsprotected longprotected TemporarySelectorprotected final Objectprotected static final ORBUtilSystemExceptionprotected final Objectprotected booleanFields inherited from class com.sun.corba.ee.impl.transport.EventHandlerBase
orb, selectionKey, useSelectThreadToWait, useWorkerThreadForEvent, workFields inherited from interface com.sun.corba.ee.spi.transport.Connection
ABORT, CLOSE_RECVD, CLOSE_SENT, ESTABLISHED, OPENING -
Constructor Summary
ConstructorsModifierConstructorDescriptionConnectionImpl(ORB orb) protectedConnectionImpl(ORB orb, boolean useSelectThreadToWait, boolean useWorkerThread) ConnectionImpl(ORB orb, Acceptor acceptor, Socket socket) privateConnectionImpl(ORB orb, Acceptor acceptor, Socket socket, boolean useSelectThreadToWait, boolean useWorkerThread) privateConnectionImpl(ORB orb, ContactInfo contactInfo, boolean useSelectThreadToWait, boolean useWorkerThread, String socketType, String hostname, int port) ConnectionImpl(ORB orb, ContactInfo contactInfo, String socketType, String hostname, int port) -
Method Summary
Modifier and TypeMethodDescriptionprivate voidaddedEntryToFragmentMap(RequestId corbaRequestId) private voidaddMessageMediatorToWorkQueue(MessageMediator messageMediator) protected void(package private) voidClears the throwable, if any, that occurred during the latestdoWork()call.voidvoidclientRequestMapGet(int requestId) voidclose()Note:it is possible for this to be called more than oncevoidClean up all connection resources.protected voidprotected voidprivate voidclosingReadSelector(TemporarySelector tmpReadSelector) private voidprivate MessageMediatorprotected final voiddefineSocket(boolean useSelectThreadToWait, Socket socket) private voidprotected voidvoiddoWork()This method denotes the actual work that is done by the work item.private voidexceptionInfo(String string, Throwable t) private voidextractAndProcessMessages(ByteBuffer byteBuffer) final CodeBasefinal IOR(package private) ThrowableReturns the throwable, if any, that occurred during the latestdoWork()call.longThis methods gets the time in millis in the work item, when this work item was enqueued in the work queue.getFragmentList(RequestId corbaRequestId) intgetName()This method will return the name of the work item.intprotected intgetState()protected StringgetStateString(int state) protected TemporarySelectorlongTimestamps are used for connection management, in particular, for reclaiming idleConnections.booleanprivate voidbooleanisBusy()Indicates if theConnectionis in the process of sending or receiving a message.booleanisClosed()Indicates if theConnectionis closed.booleanbooleanisServer()Indicates whether a CorbaContactInfo or CorbaAcceptor created theConnection.private voidlocalStateInfo(int localState) protected intprivate voidvoidpurgeCalls(SystemException systemException, boolean die, boolean lockHeld) Wake up the outstanding requests on the connection, and hand them COMM_FAILURE exception with a given minor code.private voidqueuedMessageFragment(RequestId corbaRequestId) private voidqueueUpWork(MessageMediator messageMediator) booleanread()Called to read incoming messages.private ByteBufferread(int offset, int length) private MessageMediatorreadBits()private voidreadFully(InputStream is, byte[] buf, int offset, int length) Reads data from the input stream, adding it the end of the existing buffer.private voidreadFullySleeping(int time) voidregisterWaiter(MessageMediator messageMediator) Register an invocation's CorbaMessageMediator with theConnection.voidremoveFragmentList(RequestId corbaRequestId) private voidvoidsendCancelRequest(GIOPVersion giopVersion, int requestId) Send a CancelRequest message.voidsendCancelRequestWithLock(GIOPVersion giopVersion, int requestId) voidsendCloseConnection(GIOPVersion giopVersion) ********************************************************************** The following methods are for dealing with Connection cleaning for better scalability of servers in high network load conditions.protected voidsendHelper(GIOPVersion giopVersion, Message msg) voidsendMessageError(GIOPVersion giopVersion) voidsendWithoutLock(CDROutputObject outputObject) voidvoidserverRequestMapGet(int reqId) voidserverRequestMapPut(int reqId, MessageMediator messageMediator) voidserverRequestMapRemove(int reqId) voidIt is possible for a Close Connection to have been * sent here, but we will not check for this.voidfinal voidsetCodeBaseIOR(IOR ior) voidvoidsetConnectionCache(ConnectionCache connectionCache) voidsetEnqueueTime(long timeInMillis) This methods sets the time in millis in the work item, when this work item was enqueued in the work queue.voidprotected voidsetState(int state) voidThe "state" of theConnection.protected voidsetTcpTimeouts(TcpTimeouts tcpTimeouts) voidsetTimeStamp(long time) Timestamps are used for connection management, in particular, for reclaiming idleConnections.voidsetUseSelectThreadToWait(boolean x) booleanUsed to determine if theConnectionshould register with the CorbaTransportManager Selector to handle read events.booleanUsed to determine if theConnectionshould register with the CorbaTransportManager Selector to handle read events.toString()private voidtraceMessageBodyReceived(ORB orb, ByteBuffer buf) private voidvoidunregisterWaiter(MessageMediator messageMediator) Unregister an invocation's * CorbaMessageMediator with theConnection.waitForResponse(MessageMediator messageMediator) If a message expect's a response then this method is called.voidwrite(ByteBuffer byteBuffer) voidSets the writeLock for this connection.voidRelease a write lock on theConnection.private voidwriteUsingNio(ByteBuffer byteBuffer) Methods inherited from class com.sun.corba.ee.impl.transport.EventHandlerBase
getSelectionKey, getWork, handleEvent, setSelectionKey, setUseWorkerThreadForEvent, setWork, shouldUseSelectThreadToWait, shouldUseWorkerThreadForEvent
-
Field Details
-
wrapper
-
socketChannel
-
messageParser
-
socketChannelReader
-
discardedThrowable
-
byteBuffer
-
enqueueTime
protected long enqueueTime -
contactInfo
-
acceptor
-
connectionCache
-
socket
-
timeStamp
protected long timeStamp -
isServer
protected boolean isServer -
requestId
-
responseWaitingRoom
-
state
private int state -
stateEvent
-
writeEvent
-
writeLocked
protected boolean writeLocked -
serverRequestCount
protected int serverRequestCount -
serverRequestMap
Map<Integer,MessageMediator> serverRequestMap -
postInitialContexts
protected boolean postInitialContexts -
codeBaseServerIOR
-
cachedCodeBase
-
tcpTimeouts
-
tmpReadSelector
-
tmpReadSelectorLock
-
bufferWriter
-
dispatcher
-
DISPATCHER
-
fragmentMap
-
codeSetContext
-
clientReply_1_1
-
serverRequest_1_1
-
-
Constructor Details
-
ConnectionImpl
-
ConnectionImpl
-
ConnectionImpl
private ConnectionImpl(ORB orb, ContactInfo contactInfo, boolean useSelectThreadToWait, boolean useWorkerThread, String socketType, String hostname, int port) -
ConnectionImpl
public ConnectionImpl(ORB orb, ContactInfo contactInfo, String socketType, String hostname, int port) -
ConnectionImpl
-
ConnectionImpl
-
-
Method Details
-
getSocketChannel
- Specified by:
getSocketChannelin interfaceConnection
-
getDiscardedThrowable
Throwable getDiscardedThrowable()Returns the throwable, if any, that occurred during the latestdoWork()call. Currently used only by unit tests. -
clearDiscardedThrowable
void clearDiscardedThrowable()Clears the throwable, if any, that occurred during the latestdoWork()call. Currently used only by unit tests. -
defineSocket
- Throws:
IOException
-
shouldRegisterReadEvent
public boolean shouldRegisterReadEvent()Description copied from interface:ConnectionUsed to determine if theConnectionshould register with the CorbaTransportManager Selector to handle read events. For example, an HTTP transport would not register since the requesting thread would just block on read when waiting for the reply.- Specified by:
shouldRegisterReadEventin interfaceConnection- Returns:
trueif it should be registered.
-
shouldRegisterServerReadEvent
public boolean shouldRegisterServerReadEvent()Description copied from interface:ConnectionUsed to determine if theConnectionshould register with the CorbaTransportManager Selector to handle read events. For example, an HTTP transport would not register since the requesting thread would just block on read when waiting for the reply.- Specified by:
shouldRegisterServerReadEventin interfaceConnection- Returns:
trueif it should be registered.
-
read
public boolean read()Description copied from interface:ConnectionCalled to read incoming messages.- Specified by:
readin interfaceConnection- Returns:
trueif the thread calling read can be released.
-
readBits
-
unregisterForEventAndPurgeCalls
-
createMessageMediator
-
traceMessageBodyReceived
-
hasSocketChannel
public boolean hasSocketChannel()- Specified by:
hasSocketChannelin interfaceConnection
-
read
- Throws:
IOException
-
readFully
Reads data from the input stream, adding it the end of the existing buffer. At least one byte will always be read.- Parameters:
is- the input stream from which to readbuf- the buffer into which to readoffset- the first position in the buffer into which to readlength-- Throws:
IOException
-
write
- Specified by:
writein interfaceConnection- Throws:
IOException
-
writeUsingNio
- Throws:
IOException
-
close
public void close()Note:it is possible for this to be called more than once- Specified by:
closein interfaceConnection
-
closeConnectionResources
public void closeConnectionResources()Description copied from interface:ConnectionClean up all connection resources. Used when shutting down an ORB.- Specified by:
closeConnectionResourcesin interfaceConnection
-
closingSocketChannel
@InfoMethod private void closingSocketChannel() -
IOExceptionOnClose
-
closeSocketAndTemporarySelectors
protected void closeSocketAndTemporarySelectors() -
getAcceptor
- Specified by:
getAcceptorin interfaceConnection- Specified by:
getAcceptorin interfaceEventHandler
-
getContactInfo
- Specified by:
getContactInfoin interfaceConnection
-
getEventHandler
- Specified by:
getEventHandlerin interfaceConnection
-
isServer
public boolean isServer()Description copied from interface:ConnectionIndicates whether a CorbaContactInfo or CorbaAcceptor created theConnection.- Specified by:
isServerin interfaceConnection- Returns:
trueif a CorbaAcceptor created theConnection.
-
isClosed
public boolean isClosed()Description copied from interface:ConnectionIndicates if theConnectionis closed.- Specified by:
isClosedin interfaceConnection- Returns:
trueif theConnectionis closed.
-
isBusy
public boolean isBusy()Description copied from interface:ConnectionIndicates if theConnectionis in the process of sending or receiving a message.- Specified by:
isBusyin interfaceConnection- Returns:
trueif theConnectionis busy.
-
getTimeStamp
public long getTimeStamp()Description copied from interface:ConnectionTimestamps are used for connection management, in particular, for reclaiming idleConnections.- Specified by:
getTimeStampin interfaceConnection- Returns:
- the "time" the
Connectionwas last used.
-
setTimeStamp
public void setTimeStamp(long time) Description copied from interface:ConnectionTimestamps are used for connection management, in particular, for reclaiming idleConnections.- Specified by:
setTimeStampin interfaceConnection- Parameters:
time- - the "time" theConnectionwas last used.
-
getState
protected int getState() -
setState
protected void setState(int state) -
setState
Description copied from interface:ConnectionThe "state" of theConnection.- Specified by:
setStatein interfaceConnection- Parameters:
stateString- state to set
-
writeLock
public void writeLock()Sets the writeLock for this connection. If the writeLock is already set by someone else, block till the writeLock is released and can set by us. IMPORTANT: this connection's lock must be acquired before setting the writeLock and must be unlocked after setting the writeLock.- Specified by:
writeLockin interfaceConnection
-
writeUnlock
public void writeUnlock()Description copied from interface:ConnectionRelease a write lock on theConnection.- Specified by:
writeUnlockin interfaceConnection
-
sendWithoutLock
- Specified by:
sendWithoutLockin interfaceConnection
-
registerWaiter
Description copied from interface:ConnectionRegister an invocation's CorbaMessageMediator with theConnection. This is useful in protocols which support fragmentation.- Specified by:
registerWaiterin interfaceConnection- Parameters:
messageMediator- mediator to register
-
unregisterWaiter
Description copied from interface:ConnectionUnregister an invocation's * CorbaMessageMediator with theConnection.- Specified by:
unregisterWaiterin interfaceConnection- Parameters:
messageMediator- mediator to unregister
-
waitForResponse
Description copied from interface:ConnectionIf a message expect's a response then this method is called. This method might block on a read (e.g., HTTP), put the calling thread to sleep while another thread read's the response (e.g., GIOP), or it may use the calling thread to perform the server-side work (e.g., Solaris Doors).- Specified by:
waitForResponsein interfaceConnection- Parameters:
messageMediator- mediator to process- Returns:
- stream
-
setConnectionCache
- Specified by:
setConnectionCachein interfaceConnection
-
getConnectionCache
- Specified by:
getConnectionCachein interfaceConnection
-
setUseSelectThreadToWait
public void setUseSelectThreadToWait(boolean x) - Specified by:
setUseSelectThreadToWaitin interfaceEventHandler- Overrides:
setUseSelectThreadToWaitin classEventHandlerBase
-
getChannel
- Specified by:
getChannelin interfaceEventHandler
-
getInterestOps
public int getInterestOps()- Specified by:
getInterestOpsin interfaceEventHandler
-
getConnection
- Specified by:
getConnectionin interfaceEventHandler
-
getName
Description copied from interface:WorkThis method will return the name of the work item. -
doWork
public void doWork()Description copied from interface:WorkThis method denotes the actual work that is done by the work item. -
setEnqueueTime
public void setEnqueueTime(long timeInMillis) Description copied from interface:WorkThis methods sets the time in millis in the work item, when this work item was enqueued in the work queue.- Specified by:
setEnqueueTimein interfaceWork
-
getEnqueueTime
public long getEnqueueTime()Description copied from interface:WorkThis methods gets the time in millis in the work item, when this work item was enqueued in the work queue.- Specified by:
getEnqueueTimein interfaceWork
-
getResponseWaitingRoom
- Specified by:
getResponseWaitingRoomin interfaceConnection
-
serverRequestMapPut
- Specified by:
serverRequestMapPutin interfaceConnection
-
serverRequestMapGet
- Specified by:
serverRequestMapGetin interfaceConnection
-
serverRequestMapRemove
public void serverRequestMapRemove(int reqId) - Specified by:
serverRequestMapRemovein interfaceConnection
-
getFragmentList
- Specified by:
getFragmentListin interfaceConnection
-
removeFragmentList
- Specified by:
removeFragmentListin interfaceConnection
-
getSocket
- Specified by:
getSocketin interfaceConnection
-
serverRequestProcessingBegins
public void serverRequestProcessingBegins()It is possible for a Close Connection to have been * sent here, but we will not check for this. A "lazy" * Exception will be thrown in the Worker thread after the * incoming request has been processed even though the connection * is closed before the request is processed. This is o.k because * it is a boundary condition. To prevent it we would have to add * more locks which would reduce performance in the normal case.- Specified by:
serverRequestProcessingBeginsin interfaceConnection
-
serverRequestProcessingEnds
public void serverRequestProcessingEnds()- Specified by:
serverRequestProcessingEndsin interfaceConnection
-
getNextRequestId
public int getNextRequestId()- Specified by:
getNextRequestIdin interfaceConnection
-
getBroker
- Specified by:
getBrokerin interfaceConnection
-
getCodeSetContext
- Specified by:
getCodeSetContextin interfaceConnection
-
setCodeSetContext
- Specified by:
setCodeSetContextin interfaceConnection
-
clientRequestMapGet
- Specified by:
clientRequestMapGetin interfaceConnection
-
clientReply_1_1_Put
- Specified by:
clientReply_1_1_Putin interfaceConnection
-
clientReply_1_1_Get
- Specified by:
clientReply_1_1_Getin interfaceConnection
-
clientReply_1_1_Remove
public void clientReply_1_1_Remove()- Specified by:
clientReply_1_1_Removein interfaceConnection
-
serverRequest_1_1_Put
- Specified by:
serverRequest_1_1_Putin interfaceConnection
-
serverRequest_1_1_Get
- Specified by:
serverRequest_1_1_Getin interfaceConnection
-
serverRequest_1_1_Remove
public void serverRequest_1_1_Remove()- Specified by:
serverRequest_1_1_Removein interfaceConnection
-
getStateString
-
isPostInitialContexts
public boolean isPostInitialContexts()- Specified by:
isPostInitialContextsin interfaceConnection
-
setPostInitialContexts
public void setPostInitialContexts()- Specified by:
setPostInitialContextsin interfaceConnection
-
purgeCalls
Wake up the outstanding requests on the connection, and hand them COMM_FAILURE exception with a given minor code.Also, delete connection from connection table and stop the reader thread.
Note that this should only ever be called by the Reader thread for this connection.- Specified by:
purgeCallsin interfaceConnection- Parameters:
die- Kill the reader thread (this thread) before exiting.lockHeld- true if the calling thread holds the lock on the connection
-
sendCloseConnection
********************************************************************** The following methods are for dealing with Connection cleaning for better scalability of servers in high network load conditions. ************************************************************************- Specified by:
sendCloseConnectionin interfaceConnection- Throws:
IOException
-
sendMessageError
- Specified by:
sendMessageErrorin interfaceConnection- Throws:
IOException
-
sendCancelRequest
Send a CancelRequest message. This does not lock the connection, so the caller needs to ensure this method is called appropriately.- Specified by:
sendCancelRequestin interfaceConnection- Throws:
IOException- - could be due to abortive connection closure.
-
sendHelper
- Throws:
IOException
-
sendCancelRequestWithLock
- Specified by:
sendCancelRequestWithLockin interfaceConnection- Throws:
IOException
-
setCodeBaseIOR
- Specified by:
setCodeBaseIORin interfaceConnection
-
getCodeBaseIOR
- Specified by:
getCodeBaseIORin interfaceConnection
-
getCodeBase
- Specified by:
getCodeBasein interfaceConnection
-
setTcpTimeouts
-
doOptimizedReadStrategy
protected void doOptimizedReadStrategy() -
extractAndProcessMessages
-
parseBytesAndDispatchMessages
private void parseBytesAndDispatchMessages() -
blockingRead
protected void blockingRead() -
queueUpWork
-
nonBlockingRead
protected int nonBlockingRead() -
addMessageMediatorToWorkQueue
-
resumeSelectOnMainSelector
private void resumeSelectOnMainSelector() -
getTemporaryReadSelector
- Throws:
IOException
-
closeTemporarySelectors
- Throws:
IOException
-
toString
-
exceptionInfo
-
exceptionInfo
-
readFullySleeping
@InfoMethod private void readFullySleeping(int time) -
doNotCloseBusyConnection
@InfoMethod private void doNotCloseBusyConnection() -
localStateInfo
@InfoMethod private void localStateInfo(int localState) -
addedEntryToFragmentMap
-
queuedMessageFragment
-
closingReadSelector
-