Class AprSocketContext


  • public class AprSocketContext
    extends java.lang.Object
    • Field Detail

      • log

        private static final java.util.logging.Logger log
      • USE_TICKETS

        boolean USE_TICKETS
      • contextNumber

        private static final java.util.concurrent.atomic.AtomicInteger contextNumber
      • contextId

        private int contextId
      • threadNumber

        private final java.util.concurrent.atomic.AtomicInteger threadNumber
      • threadSafe

        private boolean threadSafe
      • tcpNoDelay

        boolean tcpNoDelay
      • running

        protected boolean running
      • sslMode

        protected boolean sslMode
      • nonBlockingAccept

        private boolean nonBlockingAccept
      • acceptedQueue

        private final java.util.concurrent.BlockingQueue<AprSocket> acceptedQueue
      • rootPool

        private long rootPool
        Root APR memory pool.
      • sslCtx

        private long sslCtx
        SSL context.
      • open

        final java.util.concurrent.atomic.AtomicInteger open
      • pollTime

        private int pollTime
        Poll interval, in microseconds. If the platform doesn't support poll interrupt - it'll take this time to stop the poller.
      • hosts

        private final java.util.Map<java.lang.String,​HostInfo> hosts
      • certFile

        private java.lang.String certFile
      • keyFile

        private java.lang.String keyFile
      • spdyNPN

        private byte[] spdyNPN
      • ticketKey

        private byte[] ticketKey
      • threadPool

        private java.util.concurrent.ExecutorService threadPool
      • connectExecutor

        final java.util.concurrent.ExecutorService connectExecutor
      • debugPoll

        private boolean debugPoll
      • deferAccept

        private boolean deferAccept
      • backlog

        private int backlog
      • useSendfile

        private boolean useSendfile
      • sslProtocol

        private int sslProtocol
      • maxHandlerTime

        final java.util.concurrent.atomic.AtomicLong maxHandlerTime
        Max time spent in a callback ( will be longer for blocking )
      • totalHandlerTime

        final java.util.concurrent.atomic.AtomicLong totalHandlerTime
      • handlerCount

        final java.util.concurrent.atomic.AtomicLong handlerCount
      • connectionsCount

        private final java.util.concurrent.atomic.AtomicInteger connectionsCount
        Total connections handled ( accepted or connected ).
      • pollerThreadCount

        private int pollerThreadCount
        Poller thread count.
      • maxConnections

        private int maxConnections
      • SSLCipherSuite

        private java.lang.String SSLCipherSuite
        SSL cipher suite.
      • noApr

        private static java.io.IOException noApr
      • sizeLogged

        private static boolean sizeLogged
    • Constructor Detail

      • AprSocketContext

        public AprSocketContext()
    • Method Detail

      • setPollerThreadCount

        public void setPollerThreadCount​(int pollerThreadCount)
      • getPollerThreadCount

        public int getPollerThreadCount()
      • setMaxconnections

        public void setMaxconnections​(int maxCon)
      • setBacklog

        public void setBacklog​(int backlog)
      • getBacklog

        public int getBacklog()
      • setDeferAccept

        public void setDeferAccept​(boolean deferAccept)
        Defer accept.
      • getDeferAccept

        public boolean getDeferAccept()
      • setNpn

        public void setNpn​(java.lang.String npn)
        For client: - ClientHello will include the npn extension ( the ID == 0x3374) - if ServerHello includes a list of protocols - select one - send it after ChangeCipherSpec and before Finish For server: - if ClientHello includes the npn extension -- will send this string as list of supported protocols in ServerHello - read the selection before Finish.
        Parameters:
        npn -
      • setNpn

        public void setNpn​(byte[] data)
      • isServer

        public boolean isServer()
      • getExecutor

        protected java.util.concurrent.Executor getExecutor()
      • setTls

        public AprSocketContext setTls()
        All accepted/connected sockets will start handshake automatically.
      • setTcpNoDelay

        public void setTcpNoDelay​(boolean b)
      • setSslProtocol

        public void setSslProtocol​(java.lang.String protocol)
      • setTicketKey

        public void setTicketKey​(byte[] key48Bytes)
      • setKeys

        public AprSocketContext setKeys​(java.lang.String certPemFile,
                                        java.lang.String keyDerFile)
        Set certificate, will also enable TLS mode.
      • getSSLCipherSuite

        public java.lang.String getSSLCipherSuite()
      • setSSLCipherSuite

        public void setSSLCipherSuite​(java.lang.String SSLCipherSuite)
      • getHostInfo

        public HostInfo getHostInfo​(java.lang.String host,
                                    int port,
                                    boolean ssl)
        Override or use hostInfoLoader to implement persistent/memcache storage.
      • rawData

        protected void rawData​(AprSocket ch,
                               boolean inp,
                               byte[] data,
                               int pos,
                               int len,
                               int requested,
                               boolean closed)
      • listen

        public void listen​(int port)
                    throws java.io.IOException
        Throws:
        java.io.IOException
      • socket

        public AprSocket socket​(java.lang.String host,
                                int port,
                                boolean ssl)
        Get a socket for connectiong to host:port.
      • socket

        public AprSocket socket​(long socket)
      • destroySocket

        void destroySocket​(AprSocket socket)
      • connectBlocking

        protected void connectBlocking​(AprSocket apr)
                                throws java.io.IOException
        Throws:
        java.io.IOException
      • finalize

        protected void finalize()
        To clean the pools - we could track if all channels are closed, but this seems simpler and safer.
        Overrides:
        finalize in class java.lang.Object
      • stop

        public void stop()
      • destroy

        void destroy()
      • getRootPool

        private long getRootPool()
                          throws java.io.IOException
        Throws:
        java.io.IOException
      • getSslCtx

        long getSslCtx()
                throws java.lang.Exception
        Throws:
        java.lang.Exception
      • findPollerAndAdd

        void findPollerAndAdd​(AprSocket ch)
                       throws java.io.IOException
        Throws:
        java.io.IOException
      • assignPoller

        void assignPoller​(AprSocket ch)
                   throws java.io.IOException
        Throws:
        java.io.IOException
      • onSocket

        protected void onSocket​(AprSocket s)
        Called on each accepted socket (for servers) or after connection (client) after handshake.
      • allocatePoller

        AprSocketContext.AprPoller allocatePoller()
                                           throws java.io.IOException
        Create the poller. With some versions of APR, the maximum poller size will be 62 (recompiling APR is necessary to remove this limitation).
        Throws:
        java.io.IOException
      • allocatePoller

        protected long allocatePoller​(int size,
                                      long pool)