net.sourceforge.jtds.jdbc
Class SharedLocalNamedPipe

java.lang.Object
  extended bynet.sourceforge.jtds.jdbc.SharedSocket
      extended bynet.sourceforge.jtds.jdbc.SharedLocalNamedPipe

public class SharedLocalNamedPipe
extends SharedSocket

This class implements inter-process communication (IPC) to the database server using local named pipes (will only work on Windows).

Version:
$Id: SharedLocalNamedPipe.java,v 1.12 2007-07-08 21:38:13 bheineman Exp $
Author:
Adam Etheredge

Nested Class Summary
(package private) static class SharedSocket.VirtualSocket
          This inner class contains the state information for the virtual socket.
 
Field Summary
(package private)  java.io.RandomAccessFile pipe
          The named pipe as a file.
protected  int serverType
          The servertype one of Driver.SQLSERVER or Driver.SYBASE
 
Constructor Summary
SharedLocalNamedPipe(ConnectionJDBC2 connection)
          Creates a new instance of SharedLocalNamedPipe.
 
Method Summary
(package private)  boolean cancel(SharedSocket.VirtualSocket vsock)
          Send a TDS cancel packet to the server.
(package private)  void close()
          Close the named pipe and virtual sockets and release any resources.
(package private)  void closeStream(SharedSocket.VirtualSocket vsock)
          Deallocate a stream linked to this socket.
(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.
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 SharedSocket.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 SharedSocket.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.
(package private)  byte[] sendNetPacket(SharedSocket.VirtualSocket vsock, byte[] buffer)
          Send an 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 SharedSocket.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 SharedSocket.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

pipe

java.io.RandomAccessFile pipe
The named pipe as a file.


serverType

protected final int serverType
The servertype one of Driver.SQLSERVER or Driver.SYBASE

Constructor Detail

SharedLocalNamedPipe

public SharedLocalNamedPipe(ConnectionJDBC2 connection)
                     throws java.io.IOException
Creates a new instance of SharedLocalNamedPipe.

Parameters:
connection - the connection object
Throws:
java.io.IOException - if an I/O error occurs
Method Detail

isConnected

boolean isConnected()
Get the connected status of this socket.

Overrides:
isConnected in class SharedSocket
Returns:
true if the underlying named pipe is connected

sendNetPacket

byte[] sendNetPacket(SharedSocket.VirtualSocket vsock,
                     byte[] buffer)
               throws java.io.IOException
Send an network packet. If output for another virtual socket is in progress this packet will be sent later.

Overrides:
sendNetPacket in class SharedSocket
Parameters:
vsock - the VirtualSocket used by the originating RequestStream
buffer - the data to send
Returns:
the same buffer received if emptied or another buffer w/ the same size if the incoming buffer is cached (to avoid copying)
Throws:
java.io.IOException - if an I/O error occurs

close

void close()
     throws java.io.IOException
Close the named pipe and virtual sockets and release any resources.

Overrides:
close in class SharedSocket
Throws:
java.io.IOException - if the socket close fails

forceClose

void forceClose()
Force close the socket causing any pending reads/writes to fail.

Used by the login timer to abort a login attempt.

Overrides:
forceClose in class SharedSocket

setTimeout

protected void setTimeout(int timeout)
Set the socket timeout.

Overrides:
setTimeout in class SharedSocket
Parameters:
timeout - the timeout value in milliseconds

enableEncryption

void enableEncryption(java.lang.String ssl)
                throws java.io.IOException
Enable TLS encryption by creating a TLS socket over the existing TCP/IP network socket.

Parameters:
ssl - the SSL URL property value
Throws:
java.io.IOException - if an I/O error occurs

disableEncryption

void disableEncryption()
                 throws java.io.IOException
Disable TLS encryption and switch back to raw TCP/IP socket.

Throws:
java.io.IOException - if an I/O error occurs

setCharsetInfo

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

getCharsetInfo

CharsetInfo getCharsetInfo()
Retrieve the character set descriptor used to translate byte arrays to or from Strings.


getCharset

java.lang.String getCharset()
Retrieve the character set name used to translate byte arrays to or from Strings.

Returns:
the character set name as a String

getRequestStream

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 the RequestStream
maxPrecision - the maximum precision for numeric/decimal types
Returns:
the server request stream as a RequestStream

getResponseStream

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 this SharedSocket
bufferSize - the initial buffer size to be used by the RequestStream
Returns:
the server response stream as a ResponseStream

getTdsVersion

int getTdsVersion()
Retrieve the TDS version that is active on the connection supported by this socket.

Returns:
the TDS version as an int

setTdsVersion

protected void setTdsVersion(int tdsVersion)
Set the TDS version field.

Parameters:
tdsVersion - the TDS version as an int

setMemoryBudget

static void setMemoryBudget(int memoryBudget)
Set the global buffer memory limit for all instances of this driver.

Parameters:
memoryBudget - the global memory budget

getMemoryBudget

static int getMemoryBudget()
Get the global buffer memory limit for all instancs of this driver.

Returns:
the memory limit as an int

setMinMemPkts

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

getMinMemPkts

static int getMinMemPkts()
Get the minimum number of memory cached packets.

Returns:
minimum memory packets as an int

cancel

boolean cancel(SharedSocket.VirtualSocket vsock)
Send a TDS cancel packet to the server.

Parameters:
vsock - the SharedSocket.VirtualSocket used by the request to be canceled
Returns:
if a cancel is actually issued by this method call

closeStream

void closeStream(SharedSocket.VirtualSocket vsock)
Deallocate a stream linked to this socket.

Parameters:
vsock - the SharedSocket.VirtualSocket to close

getNetPacket

byte[] getNetPacket(SharedSocket.VirtualSocket vsock,
                    byte[] buffer)
              throws java.io.IOException
Get a network packet. This may be read from the network directly or from previously cached buffers.

Parameters:
vsock - SharedSocket.VirtualSocket the originating ResponseStream object
buffer - the data buffer to receive the object (may be replaced)
Returns:
the data in a byte[] buffer
Throws:
java.io.IOException - if an I/O error occurs

getPktLen

static int getPktLen(byte[] buf)
Convert two bytes (in network byte order) in a byte array into a Java short integer.

Parameters:
buf - array of data
Returns:
the 16 bit unsigned value as an int

setKeepAlive

protected void setKeepAlive(boolean keepAlive)
                     throws java.net.SocketException
Set the socket keep alive.

Parameters:
keepAlive - true to turn on socket keep alive
Throws:
java.net.SocketException

getIn

protected java.io.DataInputStream getIn()
Getter for SharedSocket.in field.

Returns:
InputStream used for communication

setIn

protected void setIn(java.io.DataInputStream in)
Setter for SharedSocket.in field.

Parameters:
in - the InputStream to be used for communication

getOut

protected java.io.DataOutputStream getOut()
Getter for SharedSocket.out field.

Returns:
OutputStream used for communication

setOut

protected void setOut(java.io.DataOutputStream out)
Setter for SharedSocket.out field.

Parameters:
out - the OutputStream to be used for communication

getHost

protected java.lang.String getHost()
Get the server host name.

Returns:
the host name as a String

getPort

protected int getPort()
Get the server port number.

Returns:
the host port as an int

finalize

protected void finalize()
                 throws java.lang.Throwable
Ensure all resources are released.

Throws:
java.lang.Throwable


Generated on October 27 2012