|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object net.sourceforge.jtds.jdbc.SharedSocket
This class manages the physical connection to the SQL Server and serialises its use amongst a number of virtual sockets. This allows one physical connection to service a number of concurrent statements.
Constraints and assumptions:
Nested Class Summary | |
(package private) static class |
SharedSocket.VirtualSocket
This inner class contains the state information for the virtual socket. |
Field Summary | |
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.util.ArrayList |
socketTable
Table of stream objects sharing this 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 |
Constructor Summary | |
(package private) |
SharedSocket(ConnectionJDBC2 connection)
Construct a SharedSocket object specifying host name and
port. |
protected |
SharedSocket(java.io.File bufferDir,
int tdsVersion,
int serverType)
|
Method Summary | |
(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(ConnectionJDBC2 connection)
Creates a SharedSocket.VirtualSocket through reflection when Driver.JDBC3
is true . |
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) 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. |
Methods inherited from class java.lang.Object |
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
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.ArrayList socketTable
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
Constructor Detail |
protected SharedSocket(java.io.File bufferDir, int tdsVersion, int serverType)
SharedSocket(ConnectionJDBC2 connection) throws java.io.IOException, java.net.UnknownHostException
SharedSocket
object specifying host name and
port.
connection
- the connection object
java.io.IOException
- if socket open fails
java.net.UnknownHostException
Method Detail |
private java.net.Socket createSocketForJDBC3(ConnectionJDBC2 connection) throws java.io.IOException
SharedSocket.VirtualSocket
through reflection when Driver.JDBC3
is true
. Reflection must be used to stay compatible
with JDK 1.3.
connection
- the connection object
java.io.IOException
- if socket open failsvoid enableEncryption(java.lang.String ssl) throws java.io.IOException
ssl
- the SSL URL property value
java.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 types
RequestStream
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 canceled
void 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 send
java.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[]
buffer
java.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 queue
java.io.IOException
private byte[] dequeueInput(SharedSocket.VirtualSocket vsock) throws java.io.IOException
vsock
- the virtual socket owning this data
java.io.IOException
private byte[] readPacket(byte[] buffer) throws java.io.IOException
buffer
- a buffer to read the data into (if it fits) or null
java.io.IOException
static int getPktLen(byte[] buf)
buf
- array of data
int
protected void setTimeout(int timeout) throws java.net.SocketException
timeout
- the timeout value in milliseconds
java.net.SocketException
protected void setKeepAlive(boolean keepAlive) throws java.net.SocketException
keepAlive
- true
to turn on socket keep alive
java.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
java.lang.Throwable
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |