Prev Class | Next Class | Frames | No Frames |
Summary: Nested | Field | Method | Constr | Detail: Nested | Field | Method | Constr |
java.lang.Object
net.sourceforge.jtds.jdbc.SharedSocket
(package private) class SharedSocket
extends java.lang.Object
Nested Class Summary | |
private static class |
|
Field Summary | |
private static int |
|
private static int |
|
private static int |
|
private File |
|
private Object |
|
private boolean |
|
private CharsetInfo |
|
private byte[] |
|
private static int |
|
private byte[] |
|
private String |
|
private DataInputStream |
|
private int |
|
private static int |
|
private static int |
|
private DataOutputStream |
|
private int |
|
private static int |
|
private int |
|
private int |
|
private static boolean |
|
protected int |
|
private Socket |
|
private ArrayList |
|
private Socket |
|
private int |
|
Constructor Summary | |
| |
|
Method Summary | |
(package private) boolean |
|
(package private) void |
|
(package private) void |
|
private Socket |
|
private byte[] |
|
(package private) void |
|
(package private) void |
|
private void |
|
(package private) void |
|
(package private) String |
|
(package private) CharsetInfo |
|
protected String |
|
protected DataInputStream | |
(package private) static int |
|
(package private) static int |
|
(package private) byte[] |
|
protected DataOutputStream | |
(package private) static int |
|
protected int |
|
(package private) RequestStream |
|
(package private) ResponseStream |
|
(package private) int |
|
(package private) boolean |
|
private SharedSocket.VirtualSocket |
|
private byte[] |
|
(package private) byte[] |
|
(package private) void |
|
protected void | |
(package private) static void |
|
(package private) static void |
|
protected void | |
protected void |
|
protected void |
|
private static final int TDS_DONE_LEN
Length of a TDS_DONE token.
- Field Value:
- 9
private static final int TDS_DONE_TOKEN
TDS done token.
- Field Value:
- 253
private static final int TDS_HDR_LEN
Length of TDS packet header.
- Field Value:
- 8
private final File bufferDir
The directory to buffer data to.
private Object cancelMonitor
Synchronization monitor forcancelPending
andresponseOwner
.
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 static int globalMemUsage
Total memory usage in all instances of the driver NB. Access to this field should probably be synchronized but in practice lost updates will not matter much and I think all VMs tend to do atomic saves to integer variables.
private final byte[] hdrBuf
Buffer for packet header.
private String host
The server host name.
private DataInputStream in
Input stream for network socket.
private int maxBufSize
Current maxium input buffer size.
private static int memoryBudget
Max memory limit to use for buffers. Only when this limit is exceeded will the driver start caching to disk.
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 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 int responseOwner
The Stream ID 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 final int serverType
The servertype one of Driver.SQLSERVER or Driver.SYBASE
private Socket socket
The shared network socket.
private final ArrayList socketTable
Table of stream objects sharing this socket.
private Socket sslSocket
The shared SSL network socket;
private int tdsVersion
Tds protocol version
protected SharedSocket(File bufferDir, int tdsVersion, int serverType)
(package private) SharedSocket(ConnectionJDBC2 connection) throws IOException, UnknownHostException
Construct aSharedSocket
object specifying host name and port.
- Parameters:
connection
- the connection object
(package private) boolean cancel(int streamId)
Send a TDS cancel packet to the server.
- Parameters:
streamId
- theRequestStream
id
- Returns:
boolean
true if a cancel is actually issued by this method call.
(package private) void close() throws IOException
Close the socket and release all resources.
(package private) void closeStream(int streamId)
Deallocate a stream linked to this socket.
- Parameters:
streamId
- theResponseStream
id
private Socket createSocketForJDBC3(ConnectionJDBC2 connection) throws IOException
Creates aSocket
through reflection whenDriver.JDBC3
istrue
. Reflection must be used to stay compatible with JDK 1.3.
- Parameters:
connection
- the connection object
- Returns:
- a socket open to the host and port with the given timeout
private byte[] dequeueInput(SharedSocket.VirtualSocket vsock) throws IOException
Read a cached packet from the in memory queue or from a disk based queue.
- Parameters:
vsock
- the virtual socket owning this data
- Returns:
- a buffer containing the packet
(package private) void disableEncryption() throws IOException
Disable TLS encryption and switch back to raw TCP/IP socket.
(package private) void enableEncryption(String ssl) throws IOException
Enable TLS encryption by creating a TLS socket over the existing TCP/IP network socket.
- Parameters:
ssl
- the SSL URL property value
private void enqueueInput(SharedSocket.VirtualSocket vsock, byte[] buffer) throws IOException
Save a packet buffer in a memory queue or to a disk queue if the global memory limit for the driver has been exceeded.
- Parameters:
vsock
- the virtual socket owning this databuffer
- the data to queue
(package private) void forceClose()
Force close the socket causing any pending reads/writes to fail. Used by the login timer to abort a login attempt.
(package private) String getCharset()
Retrieve the character set name used to translate byte arrays to or from Strings.
- Returns:
- the character set name as a
String
(package private) CharsetInfo getCharsetInfo()
Retrieve the character set descriptor used to translate byte arrays to or from Strings.
protected String getHost()
Get the server host name.
- Returns:
- the host name as a
String
protected DataInputStream getIn()
Getter forin
field.
- Returns:
InputStream
used for communication
(package private) static int getMemoryBudget()
Get the global buffer memory limit for all instancs of this driver.
- Returns:
- the memory limit as an
int
(package private) static int getMinMemPkts()
Get the minimum number of memory cached packets.
- Returns:
- minimum memory packets as an
int
(package private) byte[] getNetPacket(int streamId, buffer[] ) throws IOException
Get a network packet. This may be read from the network directly or from previously cached buffers.
- Parameters:
streamId
- the originating ResponseStream object
- Returns:
- the data in a
byte[]
buffer
protected DataOutputStream getOut()
Getter forout
field.
- Returns:
OutputStream
used for communication
(package private) static int getPktLen(buf[] )
Convert two bytes (in network byte order) in a byte array into a Java short integer.
- Parameters:
- Returns:
- the 16 bit unsigned value as an
int
protected int getPort()
Get the server port number.
- Returns:
- the host port as an
int
(package private) RequestStream getRequestStream(int bufferSize, int maxPrecision)
Obtain an instance of a server request stream for this socket.
- Parameters:
bufferSize
- the initial buffer size to be used by theRequestStream
maxPrecision
- the maximum precision for numeric/decimal types
- Returns:
- the server request stream as a
RequestStream
(package private) ResponseStream getResponseStream(RequestStream requestStream, int bufferSize)
Obtain an instance of a server response stream for this socket. NB. getRequestStream() must be used first to obtain the RequestStream needed as a parameter for this method.
- Parameters:
requestStream
- an existing server request stream object obtained from thisSharedSocket
bufferSize
- the initial buffer size to be used by theRequestStream
- Returns:
- the server response stream as a
ResponseStream
(package private) int getTdsVersion()
Retrieve the TDS version that is active on the connection supported by this socket.
- Returns:
- the TDS version as an
int
(package private) boolean isConnected()
Get the connected status of this socket.
- Returns:
true
if the underlying socket is connected
private SharedSocket.VirtualSocket lookup(int streamId)
Retrieves the virtual socket with the given id.
- Parameters:
streamId
- id of the virtual socket to retrieve
private byte[] readPacket(buffer[] ) throws IOException
Read a physical TDS packet from the network.
- Parameters:
- Returns:
- either the incoming buffer if it was large enough or a newly allocated buffer with the read packet
(package private) byte[] sendNetPacket(int streamId, buffer[] ) throws IOException
Send a network packet. If output for another virtual socket is in progress this packet will be sent later.
- Parameters:
streamId
- the originatingRequestStream
object
- Returns:
- the same buffer received if emptied or another buffer w/ the same size if the incoming buffer is cached (to avoid copying)
(package private) void setCharsetInfo(CharsetInfo charsetInfo)
Set the character set descriptor to be used to translate byte arrays to or from Strings.
- Parameters:
charsetInfo
- the character set descriptor
protected void setIn(DataInputStream in)
Setter forin
field.
- Parameters:
in
- theInputStream
to be used for communication
(package private) static void setMemoryBudget(int memoryBudget)
Set the global buffer memory limit for all instances of this driver.
- Parameters:
memoryBudget
- the global memory budget
(package private) static void setMinMemPkts(int minMemPkts)
Set the minimum number of packets to cache in memory before writing to disk.
- Parameters:
minMemPkts
- the minimum number of packets to cache
protected void setOut(DataOutputStream out)
Setter forout
field.
- Parameters:
out
- theOutputStream
to be used for communication
protected void setTdsVersion(int tdsVersion)
Set the TDS version field.
- Parameters:
tdsVersion
- the TDS version as anint
protected void setTimeout(int timeout) throws SocketException
Set the socket timeout.
- Parameters:
timeout
- the timeout value in milliseconds