class SharedSocket
extends java.lang.Object
Constraints and assumptions:
Modifier and Type | Class and Description |
---|---|
(package private) static class |
SharedSocket.VirtualSocket
This inner class contains the state information for the virtual socket.
|
Modifier and Type | Field and Description |
---|---|
private java.util.concurrent.atomic.AtomicInteger |
_LastID
last ID assigned to a VirtualSocket instance
|
private java.util.concurrent.ConcurrentMap<java.lang.Integer,SharedSocket.VirtualSocket> |
_VirtualSockets
Table of stream objects sharing this socket.
|
private java.io.File |
bufferDir
The directory to buffer data to.
|
private java.lang.Object |
cancelMonitor
Synchronization monitor for
cancelPending and
responseOwner . |
private boolean |
cancelPending
A cancel packet is pending.
|
private CharsetInfo |
charsetInfo
The character set to use for converting strings to/from bytes.
|
private byte[] |
doneBuffer
Buffer for TDS_DONE packets
|
private int |
doneBufferFrag
How much of the doneBuffer has been filled with data, |
private static int |
globalMemUsage
Total memory usage in all instances of the driver
NB.
|
private byte[] |
hdrBuf
Buffer for packet header.
|
private java.lang.String |
host
The server host name.
|
private java.io.DataInputStream |
in
Input stream for network socket.
|
private int |
maxBufSize
Current maximum input buffer size.
|
private static int |
memoryBudget
Max memory limit to use for buffers.
|
private static int |
minMemPkts
Minimum number of packets that will be cached in memory
before the driver tries to write to disk even if
memoryBudget has been exceeded.
|
private java.io.DataOutputStream |
out
Output stream for network socket.
|
private int |
packetCount
Count of packets received.
|
private static int |
peakMemUsage
Peak memory usage for debug purposes.
|
private int |
port
The server port number.
|
private SharedSocket.VirtualSocket |
responseOwner
The virtual socket of the object that is expecting a response from the server.
|
private static boolean |
securityViolation
Global flag to indicate that security constraints mean
that attempts to create work files will fail.
|
protected int |
serverType
The servertype one of Driver.SQLSERVER or Driver.SYBASE
|
private java.net.Socket |
socket
The shared network socket.
|
private java.net.Socket |
sslSocket
The shared SSL network socket;
|
private static int |
TDS_DONE_LEN
Length of a TDS_DONE token.
|
private static int |
TDS_DONE_TOKEN
TDS done token.
|
private static int |
TDS_HDR_LEN
Length of TDS packet header.
|
private int |
tdsVersion
Tds protocol version
|
Modifier | Constructor and Description |
---|---|
protected |
SharedSocket(java.io.File bufferDir,
int tdsVersion,
int serverType) |
(package private) |
SharedSocket(JtdsConnection connection)
Construct a
SharedSocket object specifying host name and
port. |
Modifier and Type | Method and Description |
---|---|
(package private) boolean |
cancel(SharedSocket.VirtualSocket vsock)
Send a TDS cancel packet to the server.
|
(package private) void |
close()
Close the socket and release all resources.
|
(package private) void |
closeStream(SharedSocket.VirtualSocket vsock)
Deallocate a stream linked to this socket.
|
private java.net.Socket |
createSocketForJDBC3(JtdsConnection connection)
Creates a
Socket connection. |
private byte[] |
dequeueInput(SharedSocket.VirtualSocket vsock)
Read a cached packet from the in memory queue or from a disk based queue.
|
(package private) void |
disableEncryption()
Disable TLS encryption and switch back to raw TCP/IP socket.
|
(package private) void |
enableEncryption(java.lang.String ssl)
Enable TLS encryption by creating a TLS socket over the
existing TCP/IP network socket.
|
private void |
enqueueInput(SharedSocket.VirtualSocket vsock,
byte[] buffer)
Save a packet buffer in a memory queue or to a disk queue if the global
memory limit for the driver has been exceeded.
|
protected void |
finalize()
Ensure all resources are released.
|
(package private) void |
forceClose()
Force close the socket causing any pending reads/writes to fail.
|
(package private) java.lang.String |
getCharset()
Retrieve the character set name used to translate byte arrays to
or from Strings.
|
(package private) CharsetInfo |
getCharsetInfo()
Retrieve the character set descriptor used to translate byte arrays to
or from Strings.
|
protected java.lang.String |
getHost()
Get the server host name.
|
protected java.io.DataInputStream |
getIn()
Getter for
in field. |
(package private) java.lang.String |
getMAC() |
(package private) static int |
getMemoryBudget()
Get the global buffer memory limit for all instancs of this driver.
|
(package private) static int |
getMinMemPkts()
Get the minimum number of memory cached packets.
|
(package private) byte[] |
getNetPacket(SharedSocket.VirtualSocket vsock,
byte[] buffer)
Get a network packet.
|
protected java.io.DataOutputStream |
getOut()
Getter for
out field. |
(package private) static int |
getPktLen(byte[] buf)
Convert two bytes (in network byte order) in a byte array into a Java
short integer.
|
protected int |
getPort()
Get the server port number.
|
(package private) RequestStream |
getRequestStream(int bufferSize,
int maxPrecision)
Obtain an instance of a server request stream for this socket.
|
(package private) ResponseStream |
getResponseStream(RequestStream requestStream,
int bufferSize)
Obtain an instance of a server response stream for this socket.
|
(package private) int |
getTdsVersion()
Retrieve the TDS version that is active on the connection
supported by this socket.
|
(package private) boolean |
isConnected()
Get the connected status of this socket.
|
private byte[] |
readPacket(byte[] buffer)
Read a physical TDS packet from the network.
|
(package private) byte[] |
sendNetPacket(SharedSocket.VirtualSocket vsock,
byte[] buffer)
Send a network packet.
|
(package private) void |
setCharsetInfo(CharsetInfo charsetInfo)
Set the character set descriptor to be used to translate byte arrays to
or from Strings.
|
protected void |
setIn(java.io.DataInputStream in)
Setter for
in field. |
protected void |
setKeepAlive(boolean keepAlive)
Set the socket keep alive.
|
(package private) static void |
setMemoryBudget(int memoryBudget)
Set the global buffer memory limit for all instances of this driver.
|
(package private) static void |
setMinMemPkts(int minMemPkts)
Set the minimum number of packets to cache in memory before
writing to disk.
|
protected void |
setOut(java.io.DataOutputStream out)
Setter for
out field. |
protected void |
setTdsVersion(int tdsVersion)
Set the TDS version field.
|
protected void |
setTimeout(int timeout)
Set the socket timeout.
|
private java.net.Socket socket
private java.net.Socket sslSocket
private java.io.DataOutputStream out
private java.io.DataInputStream in
private int maxBufSize
private final java.util.concurrent.atomic.AtomicInteger _LastID
private final java.util.concurrent.ConcurrentMap<java.lang.Integer,SharedSocket.VirtualSocket> _VirtualSockets
private SharedSocket.VirtualSocket responseOwner
private final byte[] hdrBuf
private final java.io.File bufferDir
private static int globalMemUsage
private static int peakMemUsage
private static int memoryBudget
private static int minMemPkts
private static boolean securityViolation
private int tdsVersion
protected final int serverType
private CharsetInfo charsetInfo
private int packetCount
private java.lang.String host
private int port
private boolean cancelPending
private final java.lang.Object cancelMonitor
cancelPending
and
responseOwner
.private final byte[] doneBuffer
private int doneBufferFrag
private static final int TDS_DONE_TOKEN
private static final int TDS_DONE_LEN
private static final int TDS_HDR_LEN
protected SharedSocket(java.io.File bufferDir, int tdsVersion, int serverType)
SharedSocket(JtdsConnection connection) throws java.io.IOException, java.net.UnknownHostException
SharedSocket
object specifying host name and
port.connection
- the connection objectjava.io.IOException
- if socket open failsjava.net.UnknownHostException
private java.net.Socket createSocketForJDBC3(JtdsConnection connection) throws java.io.IOException
Socket
connection.connection
- the connection objectjava.io.IOException
- if socket open failsjava.lang.String getMAC()
void enableEncryption(java.lang.String ssl) throws java.io.IOException
ssl
- the SSL URL property valuejava.io.IOException
- if an I/O error occursvoid disableEncryption() throws java.io.IOException
java.io.IOException
- if an I/O error occursvoid setCharsetInfo(CharsetInfo charsetInfo)
charsetInfo
- the character set descriptorCharsetInfo getCharsetInfo()
java.lang.String getCharset()
String
RequestStream getRequestStream(int bufferSize, int maxPrecision)
bufferSize
- the initial buffer size to be used by the RequestStream
maxPrecision
- the maximum precision for numeric/decimal typesRequestStream
ResponseStream getResponseStream(RequestStream requestStream, int bufferSize)
requestStream
- an existing server request stream object obtained
from this SharedSocket
bufferSize
- the initial buffer size to be used by the
RequestStream
ResponseStream
int getTdsVersion()
int
protected void setTdsVersion(int tdsVersion)
tdsVersion
- the TDS version as an int
static void setMemoryBudget(int memoryBudget)
memoryBudget
- the global memory budgetstatic int getMemoryBudget()
int
static void setMinMemPkts(int minMemPkts)
minMemPkts
- the minimum number of packets to cachestatic int getMinMemPkts()
int
boolean isConnected()
true
if the underlying socket is connectedboolean cancel(SharedSocket.VirtualSocket vsock)
vsock
- the SharedSocket.VirtualSocket
used by the request to be canceledtrue
if a cancel is actually issued by this method callvoid close() throws java.io.IOException
java.io.IOException
- if the socket close failsvoid forceClose()
Used by the login timer to abort a login attempt.
void closeStream(SharedSocket.VirtualSocket vsock)
vsock
- the SharedSocket.VirtualSocket
to closebyte[] sendNetPacket(SharedSocket.VirtualSocket vsock, byte[] buffer) throws java.io.IOException
vsock
- SharedSocket.VirtualSocket
of the originating RequestStream
buffer
- the data to sendjava.io.IOException
- if an I/O error occursbyte[] getNetPacket(SharedSocket.VirtualSocket vsock, byte[] buffer) throws java.io.IOException
vsock
- SharedSocket.VirtualSocket
the originating ResponseStream objectbuffer
- the data buffer to receive the object (may be replaced)byte[]
bufferjava.io.IOException
- if an I/O error occursprivate void enqueueInput(SharedSocket.VirtualSocket vsock, byte[] buffer) throws java.io.IOException
vsock
- the virtual socket owning this databuffer
- the data to queuejava.io.IOException
private byte[] dequeueInput(SharedSocket.VirtualSocket vsock) throws java.io.IOException
vsock
- the virtual socket owning this datajava.io.IOException
private byte[] readPacket(byte[] buffer) throws java.io.IOException
buffer
- a buffer to read the data into (if it fits) or nulljava.io.IOException
static int getPktLen(byte[] buf)
buf
- array of dataint
protected void setTimeout(int timeout) throws java.net.SocketException
timeout
- the timeout value in millisecondsjava.net.SocketException
protected void setKeepAlive(boolean keepAlive) throws java.net.SocketException
keepAlive
- true
to turn on socket keep alivejava.net.SocketException
protected java.io.DataInputStream getIn()
in
field.InputStream
used for communicationprotected void setIn(java.io.DataInputStream in)
in
field.in
- the InputStream
to be used for communicationprotected java.io.DataOutputStream getOut()
out
field.OutputStream
used for communicationprotected void setOut(java.io.DataOutputStream out)
out
field.out
- the OutputStream
to be used for communicationprotected java.lang.String getHost()
String
protected int getPort()
int
protected void finalize() throws java.lang.Throwable
finalize
in class java.lang.Object
java.lang.Throwable
Generated on June 8 2013