Class ConnectionImpl

    • Field Detail

      • socketChannel

        protected java.nio.channels.SocketChannel socketChannel
      • discardedThrowable

        private java.lang.Throwable discardedThrowable
      • byteBuffer

        protected java.nio.ByteBuffer byteBuffer
      • enqueueTime

        protected long enqueueTime
      • socket

        protected java.net.Socket socket
      • timeStamp

        protected long timeStamp
      • isServer

        protected boolean isServer
      • requestId

        protected java.util.concurrent.atomic.AtomicInteger requestId
      • state

        private int state
      • stateEvent

        protected final java.lang.Object stateEvent
      • writeEvent

        protected final java.lang.Object writeEvent
      • writeLocked

        protected boolean writeLocked
      • serverRequestCount

        protected int serverRequestCount
      • serverRequestMap

        java.util.Map<java.lang.Integer,​MessageMediator> serverRequestMap
      • postInitialContexts

        protected boolean postInitialContexts
      • codeBaseServerIOR

        protected IOR codeBaseServerIOR
      • tmpReadSelectorLock

        protected final java.lang.Object tmpReadSelectorLock
      • fragmentMap

        protected java.util.concurrent.ConcurrentHashMap<RequestId,​java.util.Queue<MessageMediator>> fragmentMap
    • Constructor Detail

      • 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,
                               java.lang.String socketType,
                               java.lang.String hostname,
                               int port)
      • ConnectionImpl

        public ConnectionImpl​(ORB orb,
                              ContactInfo contactInfo,
                              java.lang.String socketType,
                              java.lang.String hostname,
                              int port)
      • ConnectionImpl

        private ConnectionImpl​(ORB orb,
                               Acceptor acceptor,
                               java.net.Socket socket,
                               boolean useSelectThreadToWait,
                               boolean useWorkerThread)
      • ConnectionImpl

        public ConnectionImpl​(ORB orb,
                              Acceptor acceptor,
                              java.net.Socket socket)
    • Method Detail

      • getSocketChannel

        public java.nio.channels.SocketChannel getSocketChannel()
        Specified by:
        getSocketChannel in interface Connection
      • getDiscardedThrowable

        java.lang.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,
                                          java.net.Socket socket)
                                   throws java.io.IOException
        Throws:
        java.io.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.
      • unregisterForEventAndPurgeCalls

        private void unregisterForEventAndPurgeCalls​(SystemException ex)
      • traceMessageBodyReceived

        private void traceMessageBodyReceived​(ORB orb,
                                              java.nio.ByteBuffer buf)
      • read

        private java.nio.ByteBuffer read​(int offset,
                                         int length)
                                  throws java.io.IOException
        Throws:
        java.io.IOException
      • readFully

        private void readFully​(java.io.InputStream is,
                               byte[] buf,
                               int offset,
                               int length)
                        throws java.io.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:
        java.io.IOException
      • write

        public void write​(java.nio.ByteBuffer byteBuffer)
                   throws java.io.IOException
        Specified by:
        write in interface Connection
        Throws:
        java.io.IOException
      • writeUsingNio

        private void writeUsingNio​(java.nio.ByteBuffer byteBuffer)
                            throws java.io.IOException
        Throws:
        java.io.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​(java.lang.Exception e)
      • closeSocketAndTemporarySelectors

        protected void closeSocketAndTemporarySelectors()
      • 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​(java.lang.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
      • 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
      • getChannel

        public java.nio.channels.SelectableChannel getChannel()
        Specified by:
        getChannel in interface EventHandler
      • getName

        public java.lang.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
      • getSocket

        public java.net.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
      • getStateString

        protected java.lang.String getStateString​(int state)
      • 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 java.io.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:
        java.io.IOException
      • sendMessageError

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

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

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

        public void sendCancelRequestWithLock​(GIOPVersion giopVersion,
                                              int requestId)
                                       throws java.io.IOException
        Specified by:
        sendCancelRequestWithLock in interface Connection
        Throws:
        java.io.IOException
      • setTcpTimeouts

        protected void setTcpTimeouts​(TcpTimeouts tcpTimeouts)
      • doOptimizedReadStrategy

        protected void doOptimizedReadStrategy()
      • extractAndProcessMessages

        public java.nio.ByteBuffer extractAndProcessMessages​(java.nio.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 java.io.IOException
        Throws:
        java.io.IOException
      • closeTemporarySelectors

        protected void closeTemporarySelectors()
                                        throws java.io.IOException
        Throws:
        java.io.IOException
      • toString

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

        @InfoMethod
        private void exceptionInfo​(java.lang.Throwable t)
      • exceptionInfo

        @InfoMethod
        private void exceptionInfo​(java.lang.String string,
                                   java.lang.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)