Package com.mysql.cj.protocol
Class StandardSocketFactory
java.lang.Object
com.mysql.cj.protocol.StandardSocketFactory
- All Implemented Interfaces:
SocketFactory
,SocketMetadata
- Direct Known Subclasses:
SocketFactoryWrapper
,SocksProxySocketFactory
public class StandardSocketFactory extends java.lang.Object implements SocketFactory
Socket factory for vanilla TCP/IP sockets (the standard)
-
Field Summary
Fields Modifier and Type Field Description protected java.lang.String
host
The hostname to connect toprotected long
loginTimeoutCheckTimestamp
Time when last Login Timeout check occurredprotected int
loginTimeoutCountdown
The remaining login time in milliseconds.protected int
port
The port number to connect toprotected java.net.Socket
rawSocket
The underlying TCP/IP socket to useprotected int
socketTimeoutBackup
Backup original Socket timeout to be restored after handshakeprotected java.net.Socket
sslSocket
The wrapper for underlying TCP/IP socket -
Constructor Summary
Constructors Constructor Description StandardSocketFactory()
-
Method Summary
Modifier and Type Method Description void
afterHandshake()
Called by the driver after completing the MySQL protocol handshake and reading the results of the authentication.void
beforeHandshake()
Called by the driver before issuing the MySQL protocol handshake.<T extends java.io.Closeable>
Tconnect(java.lang.String hostname, int portNumber, PropertySet pset, int loginTimeout)
Creates a new socket or channel using the given properties.protected java.net.Socket
createSocket(PropertySet props)
Create the raw socket.protected int
getRealTimeout(int expectedTimeout)
Validates the connection/socket timeout that must really be used.<T extends java.io.Closeable>
TperformTlsHandshake(SocketConnection socketConnection, ServerSession serverSession)
If required, called by the driver during MySQL protocol handshake to transform original socket to SSL socket and perform TLS handshake.protected void
resetLoginTimeCountdown()
Decrements elapsed time since last reset from login timeout count down.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.mysql.cj.protocol.SocketMetadata
isLocallyConnected, isLocallyConnected
-
Field Details
-
host
protected java.lang.String hostThe hostname to connect to -
port
protected int portThe port number to connect to -
rawSocket
protected java.net.Socket rawSocketThe underlying TCP/IP socket to use -
sslSocket
protected java.net.Socket sslSocketThe wrapper for underlying TCP/IP socket -
loginTimeoutCountdown
protected int loginTimeoutCountdownThe remaining login time in milliseconds. Initial value set from defined DriverManager.setLoginTimeout() -
loginTimeoutCheckTimestamp
protected long loginTimeoutCheckTimestampTime when last Login Timeout check occurred -
socketTimeoutBackup
protected int socketTimeoutBackupBackup original Socket timeout to be restored after handshake
-
-
Constructor Details
-
StandardSocketFactory
public StandardSocketFactory()
-
-
Method Details
-
createSocket
Create the raw socket.- Parameters:
props
- properties available to affect behaviour during socket creation.- Returns:
- socket
-
connect
public <T extends java.io.Closeable> T connect(java.lang.String hostname, int portNumber, PropertySet pset, int loginTimeout) throws java.io.IOExceptionDescription copied from interface:SocketFactory
Creates a new socket or channel using the given properties. Properties are parsed by the driver from the URL. All properties other than sensitive ones (user and password) are passed to this method. The driver will instantiate the socket factory with the class name given in the property "socketFactory", where the standard iscom.mysql.cj.protocol.StandardSocketFactory
Implementing classes are responsible for handling synchronization of this method (if needed).- Specified by:
connect
in interfaceSocketFactory
- Type Parameters:
T
- result type- Parameters:
hostname
- the hostname passed in the URL. It will be a single hostname, as the driver parses multi-hosts (for failover) and calls this method for each host connection attempt.portNumber
- the port number to connect to (if required).pset
- properties passed to the driver via the URL and/or properties instance.loginTimeout
- login timeout in milliseconds- Returns:
- a socket connected to the given host
- Throws:
java.io.IOException
- if an I/O error occurs
-
beforeHandshake
public void beforeHandshake() throws java.io.IOExceptionDescription copied from interface:SocketFactory
Called by the driver before issuing the MySQL protocol handshake.- Specified by:
beforeHandshake
in interfaceSocketFactory
- Throws:
java.io.IOException
- if an I/O error occurs
-
performTlsHandshake
public <T extends java.io.Closeable> T performTlsHandshake(SocketConnection socketConnection, ServerSession serverSession) throws java.io.IOExceptionDescription copied from interface:SocketFactory
If required, called by the driver during MySQL protocol handshake to transform original socket to SSL socket and perform TLS handshake.- Specified by:
performTlsHandshake
in interfaceSocketFactory
- Type Parameters:
T
- result type- Parameters:
socketConnection
- current SocketConnectionserverSession
- current ServerSession- Returns:
- SSL socket
- Throws:
java.io.IOException
- if an I/O error occurs
-
afterHandshake
public void afterHandshake() throws java.io.IOExceptionDescription copied from interface:SocketFactory
Called by the driver after completing the MySQL protocol handshake and reading the results of the authentication.- Specified by:
afterHandshake
in interfaceSocketFactory
- Throws:
java.io.IOException
- if an I/O error occurs
-
resetLoginTimeCountdown
protected void resetLoginTimeCountdown() throws java.net.SocketExceptionDecrements elapsed time since last reset from login timeout count down.- Throws:
java.net.SocketException
- If the login timeout is reached or exceeded.
-
getRealTimeout
protected int getRealTimeout(int expectedTimeout)Validates the connection/socket timeout that must really be used.- Parameters:
expectedTimeout
- The timeout to validate.- Returns:
- The timeout to be used.
-