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

public class ConnectionImpl extends EventHandlerBase implements Connection, Work
  • Field Details

  • Constructor Details

    • ConnectionImpl

      public ConnectionImpl(ORB orb)
    • ConnectionImpl

      protected ConnectionImpl(ORB orb, boolean useSelectThreadToWait, boolean useWorkerThread)
    • 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

      private ConnectionImpl(ORB orb, Acceptor acceptor, Socket socket, boolean useSelectThreadToWait, boolean useWorkerThread)
    • ConnectionImpl

      public ConnectionImpl(ORB orb, Acceptor acceptor, Socket socket)
  • Method Details

    • getSocketChannel

      public SocketChannel getSocketChannel()
      Specified by:
      getSocketChannel in interface Connection
    • getDiscardedThrowable

      Throwable getDiscardedThrowable()
      Returns the throwable, if any, that occurred during the latest doWork() call. Currently used only by unit tests.
    • clearDiscardedThrowable

      void clearDiscardedThrowable()
      Clears the throwable, if any, that occurred during the latest doWork() call. Currently used only by unit tests.
    • defineSocket

      protected final void defineSocket(boolean useSelectThreadToWait, Socket socket) throws IOException
      Throws:
      IOException
    • shouldRegisterReadEvent

      public boolean shouldRegisterReadEvent()
      Description copied from interface: Connection
      Used to determine if the Connection 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 interface Connection
      Returns:
      true if it should be registered.
    • shouldRegisterServerReadEvent

      public boolean shouldRegisterServerReadEvent()
      Description copied from interface: Connection
      Used to determine if the Connection 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 interface Connection
      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 interface Connection
      Returns:
      true if the thread calling read can be released.
    • readBits

      private MessageMediator readBits()
    • unregisterForEventAndPurgeCalls

      private void unregisterForEventAndPurgeCalls(SystemException ex)
    • createMessageMediator

      private MessageMediator createMessageMediator()
    • traceMessageBodyReceived

      private void traceMessageBodyReceived(ORB orb, ByteBuffer buf)
    • hasSocketChannel

      public boolean hasSocketChannel()
      Specified by:
      hasSocketChannel in interface Connection
    • read

      private ByteBuffer read(int offset, int length) throws IOException
      Throws:
      IOException
    • readFully

      private void readFully(InputStream is, byte[] buf, int offset, int length) throws IOException
      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 read
      buf - the buffer into which to read
      offset - the first position in the buffer into which to read
      length -
      Throws:
      IOException
    • write

      public void write(ByteBuffer byteBuffer) throws IOException
      Specified by:
      write in interface Connection
      Throws:
      IOException
    • writeUsingNio

      private void writeUsingNio(ByteBuffer byteBuffer) throws IOException
      Throws:
      IOException
    • close

      public void close()
      Note:it is possible for this to be called more than once
      Specified by:
      close in interface Connection
    • closeConnectionResources

      public void closeConnectionResources()
      Description copied from interface: Connection
      Clean up all connection resources. Used when shutting down an ORB.
      Specified by:
      closeConnectionResources in interface Connection
    • closingSocketChannel

      @InfoMethod private void closingSocketChannel()
    • IOExceptionOnClose

      @InfoMethod private void IOExceptionOnClose(Exception e)
    • closeSocketAndTemporarySelectors

      protected void closeSocketAndTemporarySelectors()
    • getAcceptor

      public Acceptor getAcceptor()
      Specified by:
      getAcceptor in interface Connection
      Specified by:
      getAcceptor in interface EventHandler
    • getContactInfo

      public ContactInfo getContactInfo()
      Specified by:
      getContactInfo in interface Connection
    • getEventHandler

      public EventHandler getEventHandler()
      Specified by:
      getEventHandler in interface Connection
    • isServer

      public boolean isServer()
      Description copied from interface: Connection
      Indicates whether a CorbaContactInfo or CorbaAcceptor created the Connection.
      Specified by:
      isServer in interface Connection
      Returns:
      true if a CorbaAcceptor created the Connection.
    • isClosed

      public boolean isClosed()
      Description copied from interface: Connection
      Indicates if the Connection is closed.
      Specified by:
      isClosed in interface Connection
      Returns:
      true if the Connection is closed.
    • isBusy

      public boolean isBusy()
      Description copied from interface: Connection
      Indicates if the Connection is in the process of sending or receiving a message.
      Specified by:
      isBusy in interface Connection
      Returns:
      true if the Connection is busy.
    • getTimeStamp

      public long getTimeStamp()
      Description copied from interface: Connection
      Timestamps are used for connection management, in particular, for reclaiming idle Connections.
      Specified by:
      getTimeStamp in interface Connection
      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 idle Connections.
      Specified by:
      setTimeStamp in interface Connection
      Parameters:
      time - - the "time" the Connection was last used.
    • getState

      protected int getState()
    • setState

      protected void setState(int state)
    • setState

      public void setState(String stateString)
      Description copied from interface: Connection
      The "state" of the Connection.
      Specified by:
      setState in interface Connection
      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 interface Connection
    • writeUnlock

      public void writeUnlock()
      Description copied from interface: Connection
      Release a write lock on the Connection.
      Specified by:
      writeUnlock in interface Connection
    • sendWithoutLock

      public void sendWithoutLock(CDROutputObject outputObject)
      Specified by:
      sendWithoutLock in interface Connection
    • registerWaiter

      public void registerWaiter(MessageMediator messageMediator)
      Description copied from interface: Connection
      Register an invocation's CorbaMessageMediator with the Connection. This is useful in protocols which support fragmentation.
      Specified by:
      registerWaiter in interface Connection
      Parameters:
      messageMediator - mediator to register
    • unregisterWaiter

      public void unregisterWaiter(MessageMediator messageMediator)
      Description copied from interface: Connection
      Unregister an invocation's * CorbaMessageMediator with the Connection.
      Specified by:
      unregisterWaiter in interface Connection
      Parameters:
      messageMediator - mediator to unregister
    • waitForResponse

      public CDRInputObject waitForResponse(MessageMediator messageMediator)
      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 interface Connection
      Parameters:
      messageMediator - mediator to process
      Returns:
      stream
    • setConnectionCache

      public void setConnectionCache(ConnectionCache connectionCache)
      Specified by:
      setConnectionCache in interface Connection
    • getConnectionCache

      public ConnectionCache getConnectionCache()
      Specified by:
      getConnectionCache in interface Connection
    • setUseSelectThreadToWait

      public void setUseSelectThreadToWait(boolean x)
      Specified by:
      setUseSelectThreadToWait in interface EventHandler
      Overrides:
      setUseSelectThreadToWait in class EventHandlerBase
    • getChannel

      public SelectableChannel getChannel()
      Specified by:
      getChannel in interface EventHandler
    • getInterestOps

      public int getInterestOps()
      Specified by:
      getInterestOps in interface EventHandler
    • getConnection

      public Connection getConnection()
      Specified by:
      getConnection in interface EventHandler
    • getName

      public String getName()
      Description copied from interface: Work
      This method will return the name of the work item.
      Specified by:
      getName in interface Work
    • doWork

      public void doWork()
      Description copied from interface: Work
      This method denotes the actual work that is done by the work item.
      Specified by:
      doWork in interface Work
    • 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 interface Work
    • 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 interface Work
    • getResponseWaitingRoom

      public ResponseWaitingRoom getResponseWaitingRoom()
      Specified by:
      getResponseWaitingRoom in interface Connection
    • serverRequestMapPut

      public void serverRequestMapPut(int reqId, MessageMediator messageMediator)
      Specified by:
      serverRequestMapPut in interface Connection
    • serverRequestMapGet

      public MessageMediator serverRequestMapGet(int reqId)
      Specified by:
      serverRequestMapGet in interface Connection
    • serverRequestMapRemove

      public void serverRequestMapRemove(int reqId)
      Specified by:
      serverRequestMapRemove in interface Connection
    • getFragmentList

      public Queue<MessageMediator> getFragmentList(RequestId corbaRequestId)
      Specified by:
      getFragmentList in interface Connection
    • removeFragmentList

      public void removeFragmentList(RequestId corbaRequestId)
      Specified by:
      removeFragmentList in interface Connection
    • getSocket

      public Socket getSocket()
      Specified by:
      getSocket in interface Connection
    • 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 interface Connection
    • serverRequestProcessingEnds

      public void serverRequestProcessingEnds()
      Specified by:
      serverRequestProcessingEnds in interface Connection
    • getNextRequestId

      public int getNextRequestId()
      Specified by:
      getNextRequestId in interface Connection
    • getBroker

      public ORB getBroker()
      Specified by:
      getBroker in interface Connection
    • getCodeSetContext

      public CodeSetComponentInfo.CodeSetContext getCodeSetContext()
      Specified by:
      getCodeSetContext in interface Connection
    • setCodeSetContext

      public void setCodeSetContext(CodeSetComponentInfo.CodeSetContext csc)
      Specified by:
      setCodeSetContext in interface Connection
    • clientRequestMapGet

      public MessageMediator clientRequestMapGet(int requestId)
      Specified by:
      clientRequestMapGet in interface Connection
    • clientReply_1_1_Put

      public void clientReply_1_1_Put(MessageMediator x)
      Specified by:
      clientReply_1_1_Put in interface Connection
    • clientReply_1_1_Get

      public MessageMediator clientReply_1_1_Get()
      Specified by:
      clientReply_1_1_Get in interface Connection
    • clientReply_1_1_Remove

      public void clientReply_1_1_Remove()
      Specified by:
      clientReply_1_1_Remove in interface Connection
    • serverRequest_1_1_Put

      public void serverRequest_1_1_Put(MessageMediator x)
      Specified by:
      serverRequest_1_1_Put in interface Connection
    • serverRequest_1_1_Get

      public MessageMediator serverRequest_1_1_Get()
      Specified by:
      serverRequest_1_1_Get in interface Connection
    • serverRequest_1_1_Remove

      public void serverRequest_1_1_Remove()
      Specified by:
      serverRequest_1_1_Remove in interface Connection
    • getStateString

      protected String getStateString(int state)
    • isPostInitialContexts

      public boolean isPostInitialContexts()
      Specified by:
      isPostInitialContexts in interface Connection
    • setPostInitialContexts

      public void setPostInitialContexts()
      Specified by:
      setPostInitialContexts in interface Connection
    • purgeCalls

      public 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.

      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 interface Connection
      Parameters:
      die - Kill the reader thread (this thread) before exiting.
      lockHeld - true if the calling thread holds the lock on the connection
    • sendCloseConnection

      public void sendCloseConnection(GIOPVersion giopVersion) throws IOException
      ********************************************************************** The following methods are for dealing with Connection cleaning for better scalability of servers in high network load conditions. ************************************************************************
      Specified by:
      sendCloseConnection in interface Connection
      Throws:
      IOException
    • sendMessageError

      public void sendMessageError(GIOPVersion giopVersion) throws IOException
      Specified by:
      sendMessageError in interface Connection
      Throws:
      IOException
    • sendCancelRequest

      public void sendCancelRequest(GIOPVersion giopVersion, int requestId) throws IOException
      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 interface Connection
      Throws:
      IOException - - could be due to abortive connection closure.
    • sendHelper

      protected void sendHelper(GIOPVersion giopVersion, Message msg) throws IOException
      Throws:
      IOException
    • sendCancelRequestWithLock

      public void sendCancelRequestWithLock(GIOPVersion giopVersion, int requestId) throws IOException
      Specified by:
      sendCancelRequestWithLock in interface Connection
      Throws:
      IOException
    • setCodeBaseIOR

      public final void setCodeBaseIOR(IOR ior)
      Specified by:
      setCodeBaseIOR in interface Connection
    • getCodeBaseIOR

      public final IOR getCodeBaseIOR()
      Specified by:
      getCodeBaseIOR in interface Connection
    • getCodeBase

      public final CodeBase getCodeBase()
      Specified by:
      getCodeBase in interface Connection
    • setTcpTimeouts

      protected void setTcpTimeouts(TcpTimeouts tcpTimeouts)
    • doOptimizedReadStrategy

      protected void doOptimizedReadStrategy()
    • extractAndProcessMessages

      public ByteBuffer extractAndProcessMessages(ByteBuffer byteBuffer)
    • parseBytesAndDispatchMessages

      private void parseBytesAndDispatchMessages()
    • blockingRead

      protected void blockingRead()
    • queueUpWork

      private void queueUpWork(MessageMediator messageMediator)
    • nonBlockingRead

      protected int nonBlockingRead()
    • addMessageMediatorToWorkQueue

      private void addMessageMediatorToWorkQueue(MessageMediator messageMediator)
    • resumeSelectOnMainSelector

      private void resumeSelectOnMainSelector()
    • getTemporaryReadSelector

      protected TemporarySelector getTemporaryReadSelector() throws IOException
      Throws:
      IOException
    • closeTemporarySelectors

      protected void closeTemporarySelectors() throws IOException
      Throws:
      IOException
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • exceptionInfo

      @InfoMethod private void exceptionInfo(Throwable t)
    • exceptionInfo

      @InfoMethod private void exceptionInfo(String string, Throwable t)
    • readFullySleeping

      @InfoMethod private void readFullySleeping(int time)
    • doNotCloseBusyConnection

      @InfoMethod private void doNotCloseBusyConnection()
    • localStateInfo

      @InfoMethod private void localStateInfo(int localState)
    • addedEntryToFragmentMap

      @InfoMethod private void addedEntryToFragmentMap(RequestId corbaRequestId)
    • queuedMessageFragment

      @InfoMethod private void queuedMessageFragment(RequestId corbaRequestId)
    • closingReadSelector

      @InfoMethod private void closingReadSelector(TemporarySelector tmpReadSelector)