com.go.trove.net
Class CheckedSocket

java.lang.Object
  |
  +--java.net.Socket
        |
        +--com.go.trove.net.FilteredSocket
              |
              +--com.go.trove.net.CheckedSocket

public class CheckedSocket
extends FilteredSocket

A socket that tracks if any I/O exceptions have occured and ensures that plain I/O exceptions are thrown as SocketExceptions. InterruptedIOExceptions do not affect the exception count, and they are not converted to SocketExceptions.

All socket exceptions thrown will actually be instances of CheckedSocketException, which subclasses SocketException. The error messages will contain additional information, and the original exception and socket can be obtained from it.

Version:
10 , 01/03/16
Author:
Brian S O'Neill

Inner Class Summary
static interface CheckedSocket.ExceptionListener
           
 
Fields inherited from class com.go.trove.net.FilteredSocket
mSocket
 
Constructor Summary
protected CheckedSocket(java.net.Socket socket)
           
 
Method Summary
 void addExceptionListener(CheckedSocket.ExceptionListener listener)
          Internally, the collection of listeners is saved in a set so that listener instances may be added multiple times without harm.
static CheckedSocket check(java.net.Socket socket)
          Returns a new CheckedSocket instance only if the given socket isn't already one.
 void close()
           
 int getExceptionCount()
          Returns the total number of exceptions encountered while using this socket, excluding InterruptedIOExceptions.
 java.io.InputStream getInputStream()
           
 boolean getKeepAlive()
           
 java.io.OutputStream getOutputStream()
           
 int getReceiveBufferSize()
           
 int getSendBufferSize()
           
 int getSoLinger()
           
 int getSoTimeout()
           
 boolean getTcpNoDelay()
           
 void removeExceptionListener(CheckedSocket.ExceptionListener listener)
           
 void setKeepAlive(boolean on)
           
 void setReceiveBufferSize(int size)
           
 void setSendBufferSize(int size)
           
 void setSoLinger(boolean on, int linger)
           
 void setSoTimeout(int timeout)
           
 void setTcpNoDelay(boolean on)
           
 void shutdownInput()
           
 void shutdownOutput()
           
 
Methods inherited from class java.net.Socket
getInetAddress, getLocalAddress, getLocalPort, getPort, setSocketImplFactory, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

CheckedSocket

protected CheckedSocket(java.net.Socket socket)
                 throws java.net.SocketException
Method Detail

check

public static CheckedSocket check(java.net.Socket socket)
                           throws java.net.SocketException
Returns a new CheckedSocket instance only if the given socket isn't already one.

getExceptionCount

public int getExceptionCount()
Returns the total number of exceptions encountered while using this socket, excluding InterruptedIOExceptions. If this count is not zero, then the socket is potentially in an unrecoverable state.

addExceptionListener

public void addExceptionListener(CheckedSocket.ExceptionListener listener)
Internally, the collection of listeners is saved in a set so that listener instances may be added multiple times without harm.

removeExceptionListener

public void removeExceptionListener(CheckedSocket.ExceptionListener listener)

getInputStream

public java.io.InputStream getInputStream()
                                   throws java.io.IOException
Overrides:
getInputStream in class java.net.Socket

getOutputStream

public java.io.OutputStream getOutputStream()
                                     throws java.io.IOException
Overrides:
getOutputStream in class java.net.Socket

setTcpNoDelay

public void setTcpNoDelay(boolean on)
                   throws java.net.SocketException
Overrides:
setTcpNoDelay in class java.net.Socket

getTcpNoDelay

public boolean getTcpNoDelay()
                      throws java.net.SocketException
Overrides:
getTcpNoDelay in class java.net.Socket

setSoLinger

public void setSoLinger(boolean on,
                        int linger)
                 throws java.net.SocketException
Overrides:
setSoLinger in class java.net.Socket

getSoLinger

public int getSoLinger()
                throws java.net.SocketException
Overrides:
getSoLinger in class java.net.Socket

setSoTimeout

public void setSoTimeout(int timeout)
                  throws java.net.SocketException
Overrides:
setSoTimeout in class java.net.Socket

getSoTimeout

public int getSoTimeout()
                 throws java.net.SocketException
Overrides:
getSoTimeout in class java.net.Socket

setSendBufferSize

public void setSendBufferSize(int size)
                       throws java.net.SocketException
Overrides:
setSendBufferSize in class java.net.Socket

getSendBufferSize

public int getSendBufferSize()
                      throws java.net.SocketException
Overrides:
getSendBufferSize in class java.net.Socket

setReceiveBufferSize

public void setReceiveBufferSize(int size)
                          throws java.net.SocketException
Overrides:
setReceiveBufferSize in class java.net.Socket

getReceiveBufferSize

public int getReceiveBufferSize()
                         throws java.net.SocketException
Overrides:
getReceiveBufferSize in class java.net.Socket

close

public void close()
           throws java.io.IOException
Overrides:
close in class java.net.Socket

setKeepAlive

public void setKeepAlive(boolean on)
                  throws java.net.SocketException
Overrides:
setKeepAlive in class java.net.Socket

getKeepAlive

public boolean getKeepAlive()
                     throws java.net.SocketException
Overrides:
getKeepAlive in class java.net.Socket

shutdownInput

public void shutdownInput()
                   throws java.io.IOException
Overrides:
shutdownInput in class java.net.Socket

shutdownOutput

public void shutdownOutput()
                    throws java.io.IOException
Overrides:
shutdownOutput in class java.net.Socket