Package com.sun.corba.se.impl.transport
Class SocketOrChannelConnectionImpl
java.lang.Object
com.sun.corba.se.impl.transport.EventHandlerBase
com.sun.corba.se.impl.transport.SocketOrChannelConnectionImpl
- All Implemented Interfaces:
Connection,EventHandler,Connection,Work,CorbaConnection
- Direct Known Subclasses:
SocketFactoryConnectionImpl
public class SocketOrChannelConnectionImpl
extends EventHandlerBase
implements CorbaConnection, Work
- Author:
- Harold Carr
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Acceptorprotected CachedCodeBaseprotected MessageMediatorprotected IORprotected CodeSetComponentInfo.CodeSetContextprotected ConnectionCacheprotected CorbaContactInfostatic booleanprotected longprotected booleanprotected CorbaMessageMediatorprotected booleanprotected ReadTimeoutsprotected intprotected CorbaResponseWaitingRoomprotected MessageMediatorprotected intprotected booleanprotected Socketprotected SocketChannelprotected intprotected Objectprotected longprotected ORBUtilSystemExceptionprotected Objectprotected booleanFields inherited from class com.sun.corba.se.impl.transport.EventHandlerBase
orb, selectionKey, useSelectThreadToWait, useWorkerThreadForEvent, workFields inherited from interface com.sun.corba.se.spi.transport.CorbaConnection
ABORT, CLOSE_RECVD, CLOSE_SENT, ESTABLISHED, OPENING -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedprotectedSocketOrChannelConnectionImpl(ORB orb, boolean useSelectThreadToWait, boolean useWorkerThread) SocketOrChannelConnectionImpl(ORB orb, Acceptor acceptor, Socket socket) SocketOrChannelConnectionImpl(ORB orb, Acceptor acceptor, Socket socket, boolean useSelectThreadToWait, boolean useWorkerThread) SocketOrChannelConnectionImpl(ORB orb, CorbaContactInfo contactInfo, boolean useSelectThreadToWait, boolean useWorkerThread, String socketType, String hostname, int port) SocketOrChannelConnectionImpl(ORB orb, CorbaContactInfo contactInfo, String socketType, String hostname, int port) -
Method Summary
Modifier and TypeMethodDescriptionvoidvoidclientRequestMapGet(int requestId) voidclose()Note:it is possible for this to be called more than oncevoidClean up all connection resources.createOutputObject(MessageMediator messageMediator) protected booleandispatch(CorbaMessageMediator messageMediator) voiddoWork()This method denotes the actual work that is done by the work item.voidprotected voidprotected CorbaMessageMediatorfinishReadingBits(MessageMediator messageMediator) Get theAcceptorthat created thisConnection.final CodeBasefinal IORGet theContactInfothat created thisConnection.longThis methods gets the time in millis in the work item, when this work item was enqueued in the work queue.Get theEventHandlerassociated with thisAcceptor.intgetName()This method will return the name of the work item.intprotected CorbaMessageMediatorprotected StringgetStateString(int state) longTimestamps are used for connection management, in particular, for reclaiming idleConnections.voidbooleanisBusy()Indicates if theConnectionis in the process of sending or receiving a message.booleanbooleanisServer()voidpurgeCalls(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.booleanread()Called to read incoming messages.read(int size, int offset, int length, long max_wait_time) read(ByteBuffer byteBuffer, int offset, int length, long max_wait_time) protected CorbaMessageMediatorreadBits()voidreadFully(InputStream is, byte[] buf, int offset, int size, long max_wait_time) voidreadFully(ByteBuffer byteBuffer, int size, long max_wait_time) voidregisterWaiter(MessageMediator messageMediator) Register an invocation'sMessageMediatorwith theConnection.voidsendCancelRequest(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(OutputObject outputObject) voidvoidserverRequestMapGet(int requestId) voidserverRequestMapPut(int requestId, CorbaMessageMediator messageMediator) voidserverRequestMapRemove(int requestId) 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.protected voidsetPartialMessageMediator(CorbaMessageMediator messageMediator) voidprotected voidsetReadGiopHeaderOnly(boolean shouldReadHeaderOnly) protected voidsetReadTimeouts(ReadTimeouts readTimeouts) voidThe "state" of theConnection.voidsetTimeStamp(long time) Timestamps are used for connection management, in particular, for reclaiming idleConnections.voidsetUseSelectThreadToWait(boolean x) booleanbooleanUsed to determine if theConnectionshould register with theTransportManagerSelectorto handle read events.booleanUsed to determine if theConnectionshould register with theTransportManagerSelectorto handle read events.booleantoString()voidunregisterWaiter(MessageMediator messageMediator) Unregister an invocation'sMessageMediatorwith 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.Methods inherited from class com.sun.corba.se.impl.transport.EventHandlerBase
getSelectionKey, getWork, setSelectionKey, setUseWorkerThreadForEvent, setWork, shouldUseSelectThreadToWait, shouldUseWorkerThreadForEvent
-
Field Details
-
dprintWriteLocks
public static boolean dprintWriteLocks -
enqueueTime
protected long enqueueTime -
socketChannel
-
contactInfo
-
acceptor
-
connectionCache
-
socket
-
timeStamp
protected long timeStamp -
isServer
protected boolean isServer -
requestId
protected int requestId -
responseWaitingRoom
-
state
protected int state -
stateEvent
-
writeEvent
-
writeLocked
protected boolean writeLocked -
serverRequestCount
protected int serverRequestCount -
postInitialContexts
protected boolean postInitialContexts -
codeBaseServerIOR
-
cachedCodeBase
-
wrapper
-
readTimeouts
-
shouldReadGiopHeaderOnly
protected boolean shouldReadGiopHeaderOnly -
partialMessageMediator
-
codeSetContext
-
clientReply_1_1
-
serverRequest_1_1
-
-
Constructor Details
-
SocketOrChannelConnectionImpl
-
SocketOrChannelConnectionImpl
protected SocketOrChannelConnectionImpl(ORB orb, boolean useSelectThreadToWait, boolean useWorkerThread) -
SocketOrChannelConnectionImpl
public SocketOrChannelConnectionImpl(ORB orb, CorbaContactInfo contactInfo, boolean useSelectThreadToWait, boolean useWorkerThread, String socketType, String hostname, int port) -
SocketOrChannelConnectionImpl
public SocketOrChannelConnectionImpl(ORB orb, CorbaContactInfo contactInfo, String socketType, String hostname, int port) -
SocketOrChannelConnectionImpl
-
SocketOrChannelConnectionImpl
-
-
Method Details
-
getSocketChannel
- Specified by:
getSocketChannelin interfaceCorbaConnection
-
shouldRegisterReadEvent
public boolean shouldRegisterReadEvent()Description copied from interface:ConnectionUsed to determine if theConnectionshould register with theTransportManagerSelectorto 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 theTransportManagerSelectorto 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
-
finishReadingBits
-
dispatch
-
shouldUseDirectByteBuffers
public boolean shouldUseDirectByteBuffers()- Specified by:
shouldUseDirectByteBuffersin interfaceCorbaConnection
-
read
- Specified by:
readin interfaceCorbaConnection- Throws:
IOException
-
read
public ByteBuffer read(ByteBuffer byteBuffer, int offset, int length, long max_wait_time) throws IOException - Specified by:
readin interfaceCorbaConnection- Throws:
IOException
-
readFully
- Throws:
IOException
-
readFully
public void readFully(InputStream is, byte[] buf, int offset, int size, long max_wait_time) throws IOException - Throws:
IOException
-
write
- Specified by:
writein interfaceCorbaConnection- 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:CorbaConnectionClean up all connection resources. Used when shutting down an ORB.- Specified by:
closeConnectionResourcesin interfaceCorbaConnection
-
getAcceptor
Description copied from interface:ConnectionGet theAcceptorthat created thisConnection.- Specified by:
getAcceptorin interfaceConnection- Specified by:
getAcceptorin interfaceEventHandler- Returns:
Acceptor
-
getContactInfo
Description copied from interface:ConnectionGet theContactInfothat created thisConnection.- Specified by:
getContactInfoin interfaceConnection- Returns:
ContactInfo
-
getEventHandler
Description copied from interface:ConnectionGet theEventHandlerassociated with thisAcceptor.- Specified by:
getEventHandlerin interfaceConnection- Returns:
EventHandler
-
createOutputObject
-
isServer
public boolean isServer()Description copied from interface:Connection- Specified by:
isServerin interfaceConnection- Returns:
trueifConnectionanAcceptorcreated theConnection.
-
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.
-
setState
Description copied from interface:ConnectionThe "state" of theConnection. param state- Specified by:
setStatein interfaceConnection
-
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'sMessageMediatorwith theConnection. This is useful in protocols which support fragmentation.- Specified by:
registerWaiterin interfaceConnection
-
unregisterWaiter
Description copied from interface:ConnectionUnregister an invocation'sMessageMediatorwith theConnection.- Specified by:
unregisterWaiterin interfaceConnection
-
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
-
setConnectionCache
- Specified by:
setConnectionCachein interfaceConnection
-
getConnectionCache
- Specified by:
getConnectionCachein interfaceConnection
-
setUseSelectThreadToWait
public void setUseSelectThreadToWait(boolean x) - Specified by:
setUseSelectThreadToWaitin interfaceEventHandler- Overrides:
setUseSelectThreadToWaitin classEventHandlerBase
-
handleEvent
public void handleEvent()- Specified by:
handleEventin interfaceEventHandler- Overrides:
handleEventin 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
-
shouldReadGiopHeaderOnly
public boolean shouldReadGiopHeaderOnly()- Specified by:
shouldReadGiopHeaderOnlyin interfaceCorbaConnection
-
setReadGiopHeaderOnly
protected void setReadGiopHeaderOnly(boolean shouldReadHeaderOnly) -
getResponseWaitingRoom
- Specified by:
getResponseWaitingRoomin interfaceCorbaConnection
-
serverRequestMapPut
- Specified by:
serverRequestMapPutin interfaceCorbaConnection
-
serverRequestMapGet
- Specified by:
serverRequestMapGetin interfaceCorbaConnection
-
serverRequestMapRemove
public void serverRequestMapRemove(int requestId) - Specified by:
serverRequestMapRemovein interfaceCorbaConnection
-
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 interfaceCorbaConnection
-
serverRequestProcessingEnds
public void serverRequestProcessingEnds()- Specified by:
serverRequestProcessingEndsin interfaceCorbaConnection
-
getNextRequestId
public int getNextRequestId()- Specified by:
getNextRequestIdin interfaceCorbaConnection
-
getBroker
- Specified by:
getBrokerin interfaceCorbaConnection
-
getCodeSetContext
- Specified by:
getCodeSetContextin interfaceCorbaConnection
-
setCodeSetContext
- Specified by:
setCodeSetContextin interfaceCorbaConnection
-
clientRequestMapGet
- Specified by:
clientRequestMapGetin interfaceCorbaConnection
-
clientReply_1_1_Put
- Specified by:
clientReply_1_1_Putin interfaceCorbaConnection
-
clientReply_1_1_Get
- Specified by:
clientReply_1_1_Getin interfaceCorbaConnection
-
clientReply_1_1_Remove
public void clientReply_1_1_Remove()- Specified by:
clientReply_1_1_Removein interfaceCorbaConnection
-
serverRequest_1_1_Put
- Specified by:
serverRequest_1_1_Putin interfaceCorbaConnection
-
serverRequest_1_1_Get
- Specified by:
serverRequest_1_1_Getin interfaceCorbaConnection
-
serverRequest_1_1_Remove
public void serverRequest_1_1_Remove()- Specified by:
serverRequest_1_1_Removein interfaceCorbaConnection
-
getStateString
-
isPostInitialContexts
public boolean isPostInitialContexts()- Specified by:
isPostInitialContextsin interfaceCorbaConnection
-
setPostInitialContexts
public void setPostInitialContexts()- Specified by:
setPostInitialContextsin interfaceCorbaConnection
-
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 interfaceCorbaConnection- Parameters:
minor_code- The minor code for the COMM_FAILURE major code.die- Kill the reader thread (this thread) before exiting.
-
sendCloseConnection
The following methods are for dealing with Connection cleaning for better scalability of servers in high network load conditions.- Specified by:
sendCloseConnectionin interfaceCorbaConnection- Throws:
IOException
-
sendMessageError
- Specified by:
sendMessageErrorin interfaceCorbaConnection- 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 interfaceCorbaConnection- Throws:
IOException- - could be due to abortive connection closure.
-
sendHelper
- Throws:
IOException
-
sendCancelRequestWithLock
- Specified by:
sendCancelRequestWithLockin interfaceCorbaConnection- Throws:
IOException
-
setCodeBaseIOR
- Specified by:
setCodeBaseIORin interfaceCorbaConnection
-
getCodeBaseIOR
- Specified by:
getCodeBaseIORin interfaceCorbaConnection
-
getCodeBase
- Specified by:
getCodeBasein interfaceCorbaConnection
-
setReadTimeouts
-
setPartialMessageMediator
-
getPartialMessageMediator
-
toString
-
dprint
- Specified by:
dprintin interfaceCorbaConnection
-
dprint
-