Module org.firebirdsql.jaybird
Package org.firebirdsql.gds.ng.wire
Class WireConnection<T extends IAttachProperties<T>,C extends FbWireAttachment>
java.lang.Object
org.firebirdsql.gds.ng.AbstractConnection<T,C>
org.firebirdsql.gds.ng.wire.WireConnection<T,C>
- Type Parameters:
T
- Type of attach propertiesC
- Type of connection handle
- All Implemented Interfaces:
Closeable
,AutoCloseable
- Direct Known Subclasses:
WireDatabaseConnection
,WireServiceConnection
public abstract class WireConnection<T extends IAttachProperties<T>,C extends FbWireAttachment>
extends AbstractConnection<T,C>
implements Closeable
Class managing the TCP/IP connection and initial handshaking with the Firebird server.
- Since:
- 3.0
- Author:
- Mark Rotteveel
-
Field Summary
Fields inherited from class org.firebirdsql.gds.ng.AbstractConnection
attachProperties
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
WireConnection
(T attachProperties) Creates a WireConnection (without establishing a connection to the server) with the default protocol collection.protected
WireConnection
(T attachProperties, IEncodingFactory encodingFactory, ProtocolCollection protocols) Creates a WireConnection (without establishing a connection to the server). -
Method Summary
Modifier and TypeMethodDescriptionfinal void
Clear authentication data.final void
close()
Closes the TCP/IP connection.protected abstract C
createConnectionHandle
(ProtocolDescriptor protocolDescriptor) Creates the connection handle for this type of connection.final String
final ClientAuthBlock
protected String
final int
final int
final int
final int
final String
final XdrStreamAccess
final C
identify()
Performs the connection identification phase of the Wire protocol and returns the FbWireDatabase implementation for the agreed protocol.final boolean
final int
Reads the next operation code.final void
Resets the socket timeout to the configured socketTimeout.final void
setSoTimeout
(int socketTimeout) Sets the socket blocking timeout (SO_TIMEOUT) of the socket.final void
Establishes the TCP/IP connection to serverName and portNumber of this connection.protected abstract DbAttachInfo
toDbAttachInfo
(T attachProperties) final void
writeDirect
(byte[] data) Writes directly to theOutputStream
of the underlying socket.Methods inherited from class org.firebirdsql.gds.ng.AbstractConnection
createDbCryptCallback, getAttachProperties, getEncoding, getEncodingDefinition, getEncodingFactory, isLockedByCurrentThread, withLock
-
Constructor Details
-
WireConnection
Creates a WireConnection (without establishing a connection to the server) with the default protocol collection.- Parameters:
attachProperties
- Attach properties- Throws:
SQLException
-
WireConnection
protected WireConnection(T attachProperties, IEncodingFactory encodingFactory, ProtocolCollection protocols) throws SQLException Creates a WireConnection (without establishing a connection to the server).- Parameters:
attachProperties
- Attach propertiesencodingFactory
- Factory for encoding definitionsprotocols
- The collection of protocols to use for this connection.- Throws:
SQLException
-
-
Method Details
-
getServerName
-
getPortNumber
public final int getPortNumber() -
getCnctFile
- Returns:
- The file name to use in the p_cnct_file of the op_connect request
-
getAttachObjectName
-
toDbAttachInfo
- Throws:
SQLException
-
isConnected
public final boolean isConnected() -
getProtocolVersion
public final int getProtocolVersion() -
getProtocolArchitecture
public final int getProtocolArchitecture() -
getProtocolMinimumType
public final int getProtocolMinimumType() -
getClientAuthBlock
-
setSoTimeout
Sets the socket blocking timeout (SO_TIMEOUT) of the socket.This method can also be called if a connection is established
- Parameters:
socketTimeout
- Value of the socket timeout (in milliseconds)- Throws:
SQLException
- If the timeout value cannot be changed
-
resetSocketTimeout
Resets the socket timeout to the configured socketTimeout. Does nothing if currently not connected.- Throws:
SQLException
- If the timeout value cannot be changed
-
socketConnect
Establishes the TCP/IP connection to serverName and portNumber of this connection.- Throws:
SQLTimeoutException
- if the connection cannot be established within the connect timeout (either explicitly set or implied by the OS timeout of the socket)SQLException
- if the connection cannot be established.
-
getXdrStreamAccess
-
identify
Performs the connection identification phase of the Wire protocol and returns the FbWireDatabase implementation for the agreed protocol.- Specified by:
identify
in classAbstractConnection<T extends IAttachProperties<T>,
C extends FbWireAttachment> - Returns:
- FbWireDatabase
- Throws:
SQLException
- For exceptions connecting
-
clearAuthData
public final void clearAuthData()Clear authentication data. -
createConnectionHandle
Creates the connection handle for this type of connection.- Parameters:
protocolDescriptor
- The protocol descriptor selected by the identify phase- Returns:
- Connection handle
-
readNextOperation
Reads the next operation code. Skips allWireProtocolConstants.op_dummy
codes received.- Returns:
- Operation code
- Throws:
IOException
- if an error occurs while reading from the underlying InputStream
-
close
Closes the TCP/IP connection. This is not a normal detach operation.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
- if closing fails
-
writeDirect
Writes directly to theOutputStream
of the underlying socket.- Parameters:
data
- Data to write- Throws:
IOException
- If there is no socket, the socket is closed, or for errors writing to the socket.
-