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 Acceptor
private NioBufferWriter
protected ByteBuffer
protected CachedCodeBase
protected MessageMediator
protected IOR
protected CodeSetComponentInfo.CodeSetContext
protected ConnectionCache
protected ContactInfo
private Throwable
protected ConnectionImpl.Dispatcher
(package private) static final ConnectionImpl.Dispatcher
protected long
protected ConcurrentHashMap
<RequestId, Queue<MessageMediator>> protected boolean
private MessageParser
protected boolean
protected AtomicInteger
protected ResponseWaitingRoom
protected MessageMediator
protected int
(package private) Map
<Integer, MessageMediator> protected Socket
protected SocketChannel
private SocketChannelReader
private int
protected final Object
protected TcpTimeouts
protected long
protected TemporarySelector
protected final Object
protected static final ORBUtilSystemException
protected final Object
protected boolean
Fields inherited from class com.sun.corba.ee.impl.transport.EventHandlerBase
orb, selectionKey, useSelectThreadToWait, useWorkerThreadForEvent, work
Fields inherited from interface com.sun.corba.ee.spi.transport.Connection
ABORT, CLOSE_RECVD, CLOSE_SENT, ESTABLISHED, OPENING
-
Constructor Summary
ConstructorsModifierConstructorDescriptionConnectionImpl
(ORB orb) protected
ConnectionImpl
(ORB orb, boolean useSelectThreadToWait, boolean useWorkerThread) ConnectionImpl
(ORB orb, Acceptor acceptor, Socket socket) private
ConnectionImpl
(ORB orb, Acceptor acceptor, Socket socket, boolean useSelectThreadToWait, boolean useWorkerThread) private
ConnectionImpl
(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 void
addedEntryToFragmentMap
(RequestId corbaRequestId) private void
addMessageMediatorToWorkQueue
(MessageMediator messageMediator) protected void
(package private) void
Clears the throwable, if any, that occurred during the latestdoWork()
call.void
void
clientRequestMapGet
(int requestId) void
close()
Note:it is possible for this to be called more than oncevoid
Clean up all connection resources.protected void
protected void
private void
closingReadSelector
(TemporarySelector tmpReadSelector) private void
private MessageMediator
protected final void
defineSocket
(boolean useSelectThreadToWait, Socket socket) private void
protected void
void
doWork()
This method denotes the actual work that is done by the work item.private void
exceptionInfo
(String string, Throwable t) private void
extractAndProcessMessages
(ByteBuffer byteBuffer) final CodeBase
final IOR
(package private) Throwable
Returns the throwable, if any, that occurred during the latestdoWork()
call.long
This methods gets the time in millis in the work item, when this work item was enqueued in the work queue.getFragmentList
(RequestId corbaRequestId) int
getName()
This method will return the name of the work item.int
protected int
getState()
protected String
getStateString
(int state) protected TemporarySelector
long
Timestamps are used for connection management, in particular, for reclaiming idleConnection
s.boolean
private void
boolean
isBusy()
Indicates if theConnection
is in the process of sending or receiving a message.boolean
isClosed()
Indicates if theConnection
is closed.boolean
boolean
isServer()
Indicates whether a CorbaContactInfo or CorbaAcceptor created theConnection
.private void
localStateInfo
(int localState) protected int
private void
void
purgeCalls
(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 void
queuedMessageFragment
(RequestId corbaRequestId) private void
queueUpWork
(MessageMediator messageMediator) boolean
read()
Called to read incoming messages.private ByteBuffer
read
(int offset, int length) private MessageMediator
readBits()
private void
readFully
(InputStream is, byte[] buf, int offset, int length) Reads data from the input stream, adding it the end of the existing buffer.private void
readFullySleeping
(int time) void
registerWaiter
(MessageMediator messageMediator) Register an invocation's CorbaMessageMediator with theConnection
.void
removeFragmentList
(RequestId corbaRequestId) private void
void
sendCancelRequest
(GIOPVersion giopVersion, int requestId) Send a CancelRequest message.void
sendCancelRequestWithLock
(GIOPVersion giopVersion, int requestId) void
sendCloseConnection
(GIOPVersion giopVersion) ********************************************************************** The following methods are for dealing with Connection cleaning for better scalability of servers in high network load conditions.protected void
sendHelper
(GIOPVersion giopVersion, Message msg) void
sendMessageError
(GIOPVersion giopVersion) void
sendWithoutLock
(CDROutputObject outputObject) void
void
serverRequestMapGet
(int reqId) void
serverRequestMapPut
(int reqId, MessageMediator messageMediator) void
serverRequestMapRemove
(int reqId) void
It is possible for a Close Connection to have been * sent here, but we will not check for this.void
final void
setCodeBaseIOR
(IOR ior) void
void
setConnectionCache
(ConnectionCache connectionCache) void
setEnqueueTime
(long timeInMillis) This methods sets the time in millis in the work item, when this work item was enqueued in the work queue.void
protected void
setState
(int state) void
The "state" of theConnection
.protected void
setTcpTimeouts
(TcpTimeouts tcpTimeouts) void
setTimeStamp
(long time) Timestamps are used for connection management, in particular, for reclaiming idleConnection
s.void
setUseSelectThreadToWait
(boolean x) boolean
Used to determine if theConnection
should register with the CorbaTransportManager Selector to handle read events.boolean
Used to determine if theConnection
should register with the CorbaTransportManager Selector to handle read events.toString()
private void
traceMessageBodyReceived
(ORB orb, ByteBuffer buf) private void
void
unregisterWaiter
(MessageMediator messageMediator) Unregister an invocation's * CorbaMessageMediator with theConnection
.waitForResponse
(MessageMediator messageMediator) If a message expect's a response then this method is called.void
write
(ByteBuffer byteBuffer) void
Sets the writeLock for this connection.void
Release a write lock on theConnection
.private void
writeUsingNio
(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:
getSocketChannel
in 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:Connection
Used to determine if theConnection
should 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:
shouldRegisterReadEvent
in interfaceConnection
- Returns:
true
if it should be registered.
-
shouldRegisterServerReadEvent
public boolean shouldRegisterServerReadEvent()Description copied from interface:Connection
Used to determine if theConnection
should 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:
shouldRegisterServerReadEvent
in interfaceConnection
- Returns:
true
if it should be registered.
-
read
public boolean read()Description copied from interface:Connection
Called to read incoming messages.- Specified by:
read
in interfaceConnection
- Returns:
true
if the thread calling read can be released.
-
readBits
-
unregisterForEventAndPurgeCalls
-
createMessageMediator
-
traceMessageBodyReceived
-
hasSocketChannel
public boolean hasSocketChannel()- Specified by:
hasSocketChannel
in 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:
write
in interfaceConnection
- Throws:
IOException
-
writeUsingNio
- Throws:
IOException
-
close
public void close()Note:it is possible for this to be called more than once- Specified by:
close
in interfaceConnection
-
closeConnectionResources
public void closeConnectionResources()Description copied from interface:Connection
Clean up all connection resources. Used when shutting down an ORB.- Specified by:
closeConnectionResources
in interfaceConnection
-
closingSocketChannel
@InfoMethod private void closingSocketChannel() -
IOExceptionOnClose
-
closeSocketAndTemporarySelectors
protected void closeSocketAndTemporarySelectors() -
getAcceptor
- Specified by:
getAcceptor
in interfaceConnection
- Specified by:
getAcceptor
in interfaceEventHandler
-
getContactInfo
- Specified by:
getContactInfo
in interfaceConnection
-
getEventHandler
- Specified by:
getEventHandler
in interfaceConnection
-
isServer
public boolean isServer()Description copied from interface:Connection
Indicates whether a CorbaContactInfo or CorbaAcceptor created theConnection
.- Specified by:
isServer
in interfaceConnection
- Returns:
true
if a CorbaAcceptor created theConnection
.
-
isClosed
public boolean isClosed()Description copied from interface:Connection
Indicates if theConnection
is closed.- Specified by:
isClosed
in interfaceConnection
- Returns:
true
if theConnection
is closed.
-
isBusy
public boolean isBusy()Description copied from interface:Connection
Indicates if theConnection
is in the process of sending or receiving a message.- Specified by:
isBusy
in interfaceConnection
- Returns:
true
if theConnection
is busy.
-
getTimeStamp
public long getTimeStamp()Description copied from interface:Connection
Timestamps are used for connection management, in particular, for reclaiming idleConnection
s.- Specified by:
getTimeStamp
in interfaceConnection
- Returns:
- the "time" the
Connection
was last used.
-
setTimeStamp
public void setTimeStamp(long time) Description copied from interface:Connection
Timestamps are used for connection management, in particular, for reclaiming idleConnection
s.- Specified by:
setTimeStamp
in interfaceConnection
- Parameters:
time
- - the "time" theConnection
was last used.
-
getState
protected int getState() -
setState
protected void setState(int state) -
setState
Description copied from interface:Connection
The "state" of theConnection
.- Specified by:
setState
in 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:
writeLock
in interfaceConnection
-
writeUnlock
public void writeUnlock()Description copied from interface:Connection
Release a write lock on theConnection
.- Specified by:
writeUnlock
in interfaceConnection
-
sendWithoutLock
- Specified by:
sendWithoutLock
in interfaceConnection
-
registerWaiter
Description copied from interface:Connection
Register an invocation's CorbaMessageMediator with theConnection
. This is useful in protocols which support fragmentation.- Specified by:
registerWaiter
in interfaceConnection
- Parameters:
messageMediator
- mediator to register
-
unregisterWaiter
Description copied from interface:Connection
Unregister an invocation's * CorbaMessageMediator with theConnection
.- Specified by:
unregisterWaiter
in interfaceConnection
- Parameters:
messageMediator
- mediator to unregister
-
waitForResponse
Description copied from interface:Connection
If 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:
waitForResponse
in interfaceConnection
- Parameters:
messageMediator
- mediator to process- Returns:
- stream
-
setConnectionCache
- Specified by:
setConnectionCache
in interfaceConnection
-
getConnectionCache
- Specified by:
getConnectionCache
in interfaceConnection
-
setUseSelectThreadToWait
public void setUseSelectThreadToWait(boolean x) - Specified by:
setUseSelectThreadToWait
in interfaceEventHandler
- Overrides:
setUseSelectThreadToWait
in classEventHandlerBase
-
getChannel
- Specified by:
getChannel
in interfaceEventHandler
-
getInterestOps
public int getInterestOps()- Specified by:
getInterestOps
in interfaceEventHandler
-
getConnection
- Specified by:
getConnection
in interfaceEventHandler
-
getName
Description copied from interface:Work
This method will return the name of the work item. -
doWork
public void doWork()Description copied from interface:Work
This method denotes the actual work that is done by the work item. -
setEnqueueTime
public void setEnqueueTime(long timeInMillis) Description copied from interface:Work
This methods sets the time in millis in the work item, when this work item was enqueued in the work queue.- Specified by:
setEnqueueTime
in interfaceWork
-
getEnqueueTime
public long getEnqueueTime()Description copied from interface:Work
This methods gets the time in millis in the work item, when this work item was enqueued in the work queue.- Specified by:
getEnqueueTime
in interfaceWork
-
getResponseWaitingRoom
- Specified by:
getResponseWaitingRoom
in interfaceConnection
-
serverRequestMapPut
- Specified by:
serverRequestMapPut
in interfaceConnection
-
serverRequestMapGet
- Specified by:
serverRequestMapGet
in interfaceConnection
-
serverRequestMapRemove
public void serverRequestMapRemove(int reqId) - Specified by:
serverRequestMapRemove
in interfaceConnection
-
getFragmentList
- Specified by:
getFragmentList
in interfaceConnection
-
removeFragmentList
- Specified by:
removeFragmentList
in interfaceConnection
-
getSocket
- Specified by:
getSocket
in 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:
serverRequestProcessingBegins
in interfaceConnection
-
serverRequestProcessingEnds
public void serverRequestProcessingEnds()- Specified by:
serverRequestProcessingEnds
in interfaceConnection
-
getNextRequestId
public int getNextRequestId()- Specified by:
getNextRequestId
in interfaceConnection
-
getBroker
- Specified by:
getBroker
in interfaceConnection
-
getCodeSetContext
- Specified by:
getCodeSetContext
in interfaceConnection
-
setCodeSetContext
- Specified by:
setCodeSetContext
in interfaceConnection
-
clientRequestMapGet
- Specified by:
clientRequestMapGet
in interfaceConnection
-
clientReply_1_1_Put
- Specified by:
clientReply_1_1_Put
in interfaceConnection
-
clientReply_1_1_Get
- Specified by:
clientReply_1_1_Get
in interfaceConnection
-
clientReply_1_1_Remove
public void clientReply_1_1_Remove()- Specified by:
clientReply_1_1_Remove
in interfaceConnection
-
serverRequest_1_1_Put
- Specified by:
serverRequest_1_1_Put
in interfaceConnection
-
serverRequest_1_1_Get
- Specified by:
serverRequest_1_1_Get
in interfaceConnection
-
serverRequest_1_1_Remove
public void serverRequest_1_1_Remove()- Specified by:
serverRequest_1_1_Remove
in interfaceConnection
-
getStateString
-
isPostInitialContexts
public boolean isPostInitialContexts()- Specified by:
isPostInitialContexts
in interfaceConnection
-
setPostInitialContexts
public void setPostInitialContexts()- Specified by:
setPostInitialContexts
in 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:
purgeCalls
in 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:
sendCloseConnection
in interfaceConnection
- Throws:
IOException
-
sendMessageError
- Specified by:
sendMessageError
in 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:
sendCancelRequest
in interfaceConnection
- Throws:
IOException
- - could be due to abortive connection closure.
-
sendHelper
- Throws:
IOException
-
sendCancelRequestWithLock
- Specified by:
sendCancelRequestWithLock
in interfaceConnection
- Throws:
IOException
-
setCodeBaseIOR
- Specified by:
setCodeBaseIOR
in interfaceConnection
-
getCodeBaseIOR
- Specified by:
getCodeBaseIOR
in interfaceConnection
-
getCodeBase
- Specified by:
getCodeBase
in 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
-