net.sourceforge.jtds.jdbc
Class SharedNamedPipe

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

public class SharedNamedPipe
extends SharedSocket

This class implements inter-process communication (IPC) to the database server using named pipes.

Version:
$Id: SharedNamedPipe.java,v 1.19.2.2 2009-12-10 09:54:04 ickzon Exp $
Author:
David D. Kilzer
To do:
Extract abstract base class SharedIpc from SharedSocket and this class., Implement connection timeouts for named pipes.

Nested Class Summary
(package private) static class SharedSocket.VirtualSocket
          This inner class contains the state information for the virtual socket.
 
Field Summary
private  jcifs.smb.SmbNamedPipe pipe
          The shared named pipe.
protected  int serverType
          The servertype one of Driver.SQLSERVER or Driver.SYBASE
 
Constructor Summary
SharedNamedPipe(ConnectionJDBC2 connection)
          Creates a new instance of SharedNamedPipe.
 
Method Summary
(package private)  boolean cancel(SharedSocket.VirtualSocket vsock)
          Send a TDS cancel packet to the server.
(package private)  void close()
          Close the socket (noop if in shared mode).
(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.
private  jcifs.smb.SmbNamedPipe getPipe()
          Getter for pipe 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 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 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.
private  void setPipe(jcifs.smb.SmbNamedPipe pipe)
          Setter for pipe 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

private jcifs.smb.SmbNamedPipe pipe
The shared named pipe.


serverType

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

Constructor Detail

SharedNamedPipe

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

Parameters:
connection -
Throws:
java.io.IOException - if the named pipe or its input or output streams do not open
java.net.UnknownHostException - if host cannot be found for the named pipe
Method Detail

isConnected

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

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

close

void close()
     throws java.io.IOException
Close the socket (noop if in shared mode).

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

getPipe

private jcifs.smb.SmbNamedPipe getPipe()
Getter for pipe field.

Returns:
SmbNamedPipe used for communication

setPipe

private void setPipe(jcifs.smb.SmbNamedPipe pipe)
Setter for pipe field.

Parameters:
pipe - SmbNamedPipe to be used for communication

setTimeout

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

Noop for now; timeouts are not implemented for SMB named pipes.

Overrides:
setTimeout in class SharedSocket
Parameters:
timeout - 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

sendNetPacket

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

Parameters:
vsock - SharedSocket.VirtualSocket of 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

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