Package org.apache.tomcat.jni.socket
Class AprSocketContext
- java.lang.Object
-
- org.apache.tomcat.jni.socket.AprSocketContext
-
public class AprSocketContext extends java.lang.Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private class
AprSocketContext.AcceptorDispatchThread
private class
AprSocketContext.AcceptorThread
(package private) class
AprSocketContext.AprPoller
static interface
AprSocketContext.BlockingPollHandler
Callback for poll events, will be invoked in a thread pool.static interface
AprSocketContext.HostInfoLoader
Delegates loading of persistent info about a host - public certs, tickets, config, persistent info etc.static interface
AprSocketContext.NonBlockingPollHandler
Additional callbacks for non-blocking.static interface
AprSocketContext.RawDataHandler
Called when a chunk of data is sent or received.static interface
AprSocketContext.TlsCertVerifier
Called in SSL mode after the handshake is completed.
-
Field Summary
Fields Modifier and Type Field Description private java.util.concurrent.BlockingQueue<AprSocket>
acceptedQueue
private AprSocketContext.AcceptorThread
acceptor
For now - single acceptor thread per connector.private AprSocketContext.AcceptorDispatchThread
acceptorDispatch
private int
backlog
private java.lang.String
certFile
(package private) java.util.concurrent.ExecutorService
connectExecutor
private java.util.concurrent.atomic.AtomicInteger
connectionsCount
Total connections handled ( accepted or connected ).(package private) int
connectTimeout
private int
contextId
private static java.util.concurrent.atomic.AtomicInteger
contextNumber
private boolean
debugPoll
(package private) boolean
debugSSL
(package private) int
defaultTimeout
private boolean
deferAccept
private AprSocket
END
private static int
FALLBACK_POLL_TIME
(package private) java.util.concurrent.atomic.AtomicLong
handlerCount
private AprSocketContext.HostInfoLoader
hostInfoLoader
private java.util.Map<java.lang.String,HostInfo>
hosts
(package private) int
keepAliveTimeout
private java.lang.String
keyFile
private static java.util.logging.Logger
log
private int
maxConnections
(package private) java.util.concurrent.atomic.AtomicLong
maxHandlerTime
Max time spent in a callback ( will be longer for blocking )private static java.io.IOException
noApr
private boolean
nonBlockingAccept
(package private) java.util.concurrent.atomic.AtomicInteger
open
private java.util.List<AprSocketContext.AprPoller>
pollers
Pollers.private int
pollerThreadCount
Poller thread count.private int
pollTime
Poll interval, in microseconds.(package private) AprSocketContext.RawDataHandler
rawDataHandler
private long
rootPool
Root APR memory pool.protected boolean
running
private static boolean
sizeLogged
private byte[]
spdyNPN
private java.lang.String
SSLCipherSuite
SSL cipher suite.private long
sslCtx
SSL context.protected boolean
sslMode
private int
sslProtocol
(package private) boolean
tcpNoDelay
private java.util.concurrent.atomic.AtomicInteger
threadNumber
private java.util.concurrent.ExecutorService
threadPool
private boolean
threadSafe
private byte[]
ticketKey
(package private) AprSocketContext.TlsCertVerifier
tlsCertVerifier
(package private) java.util.concurrent.atomic.AtomicLong
totalHandlerTime
(package private) boolean
USE_TICKETS
private boolean
useSendfile
-
Constructor Summary
Constructors Constructor Description AprSocketContext()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) AprSocketContext.AprPoller
allocatePoller()
Create the poller.protected long
allocatePoller(int size, long pool)
(package private) void
assignPoller(AprSocket ch)
protected void
connectBlocking(AprSocket apr)
void
customVerification(AprSocketContext.TlsCertVerifier verifier)
(package private) void
destroy()
(package private) void
destroySocket(AprSocket socket)
protected void
finalize()
To clean the pools - we could track if all channels are closed, but this seems simpler and safer.(package private) void
findPollerAndAdd(AprSocket ch)
int
getBacklog()
boolean
getDeferAccept()
protected java.util.concurrent.Executor
getExecutor()
HostInfo
getHostInfo(java.lang.String host, int port, boolean ssl)
Override or use hostInfoLoader to implement persistent/memcache storage.int
getPollerThreadCount()
private long
getRootPool()
java.lang.String
getSSLCipherSuite()
(package private) long
getSslCtx()
boolean
isServer()
void
listen(int port)
(package private) AprSocket
newSocket(AprSocketContext context)
protected void
onSocket(AprSocket s)
Called on each accepted socket (for servers) or after connection (client) after handshake.protected void
rawData(AprSocket ch, boolean inp, byte[] data, int pos, int len, int requested, boolean closed)
void
setBacklog(int backlog)
void
setDeferAccept(boolean deferAccept)
Defer accept.void
setHostLoader(AprSocketContext.HostInfoLoader handler)
AprSocketContext
setKeys(java.lang.String certPemFile, java.lang.String keyDerFile)
Set certificate, will also enable TLS mode.void
setMaxconnections(int maxCon)
void
setNpn(byte[] data)
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.void
setPollerThreadCount(int pollerThreadCount)
void
setSSLCipherSuite(java.lang.String SSLCipherSuite)
void
setSslProtocol(java.lang.String protocol)
void
setTcpNoDelay(boolean b)
void
setTicketKey(byte[] key48Bytes)
AprSocketContext
setTls()
All accepted/connected sockets will start handshake automatically.AprSocket
socket(long socket)
AprSocket
socket(java.lang.String host, int port, boolean ssl)
Get a socket for connectiong to host:port.AprSocket
socket(HostInfo hi)
void
stop()
-
-
-
Field Detail
-
log
private static final java.util.logging.Logger log
-
FALLBACK_POLL_TIME
private static final int FALLBACK_POLL_TIME
- See Also:
- Constant Field Values
-
USE_TICKETS
boolean USE_TICKETS
-
END
private final AprSocket END
-
contextNumber
private static final java.util.concurrent.atomic.AtomicInteger contextNumber
-
contextId
private int contextId
-
threadNumber
private final java.util.concurrent.atomic.AtomicInteger threadNumber
-
acceptor
private AprSocketContext.AcceptorThread acceptor
For now - single acceptor thread per connector.
-
acceptorDispatch
private AprSocketContext.AcceptorDispatchThread acceptorDispatch
-
threadSafe
private boolean threadSafe
-
pollers
private final java.util.List<AprSocketContext.AprPoller> pollers
Pollers.
-
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.
-
tlsCertVerifier
AprSocketContext.TlsCertVerifier tlsCertVerifier
-
connectTimeout
final int connectTimeout
- See Also:
- Constant Field Values
-
defaultTimeout
final int defaultTimeout
- See Also:
- Constant Field Values
-
keepAliveTimeout
final int keepAliveTimeout
- See Also:
- Constant Field Values
-
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.
-
hostInfoLoader
private AprSocketContext.HostInfoLoader hostInfoLoader
-
rawDataHandler
final AprSocketContext.RawDataHandler rawDataHandler
-
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
-
debugSSL
final boolean debugSSL
- See Also:
- Constant Field Values
-
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
-
-
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)
-
setHostLoader
public void setHostLoader(AprSocketContext.HostInfoLoader handler)
-
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)
-
customVerification
public void customVerification(AprSocketContext.TlsCertVerifier verifier)
-
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
-
newSocket
AprSocket newSocket(AprSocketContext context)
-
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 classjava.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)
-
-