Package com.danga.MemCached
Class SockIOPool.SockIO
java.lang.Object
com.danga.MemCached.SockIOPool.SockIO
- All Implemented Interfaces:
LineInputStream
- Enclosing class:
- SockIOPool
MemCached Java client, utility class for Socket IO.
This class is a wrapper around a Socket and its streams.
- Version:
- 1.5
- Author:
- greg whalin <greg@meetup.com>, Richard 'toast' Russo <russor@msoe.edu>
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate String
private DataInputStream
private static org.apache.log4j.Logger
private BufferedOutputStream
private SockIOPool
private Socket
-
Constructor Summary
ConstructorsConstructorDescriptionSockIO
(SockIOPool pool, String host, int timeout, int connectTimeout, boolean noDelay) creates a new SockIO object wrapping a socket connection to host:port, and its input and output streamsSockIO
(SockIOPool pool, String host, int port, int timeout, int connectTimeout, boolean noDelay) creates a new SockIO object wrapping a socket connection to host:port, and its input and output streams -
Method Summary
Modifier and TypeMethodDescriptionvoid
clearEOL()
reads up to end of line and returns nothing(package private) void
close()
sets closed flag and checks in to connection pool but does not close connectionsprotected void
finalize()
Hack to reap any leaking children.(package private) void
flush()
flushes output streamLets caller get access to underlying channel.getHost()
returns the host this socket is connected toprotected static Socket
Method which gets a connection from SocketChannel.int
hashCode()
use the sockets hashcode for this object so we can key off of SockIOs(package private) boolean
isAlive()
(package private) boolean
checks if the connection is openint
read
(byte[] b) reads length bytes into the passed in byte array from dtreamreadLine()
reads a line intentionally not using the deprecated readLine method from DataInputStreamtoString()
returns the string representation of this socketvoid
closes socket and all streams connected to itvoid
trueClose
(boolean addToDeadPool) closes socket and all streams connected to it(package private) void
write
(byte[] b) writes a byte array to the output stream
-
Field Details
-
log
private static org.apache.log4j.Logger log -
pool
-
host
-
sock
-
in
-
out
-
-
Constructor Details
-
SockIO
public SockIO(SockIOPool pool, String host, int port, int timeout, int connectTimeout, boolean noDelay) throws IOException, UnknownHostException creates a new SockIO object wrapping a socket connection to host:port, and its input and output streams- Parameters:
pool
- Pool this object is tied tohost
- host to connect toport
- port to connect totimeout
- int ms to block on data for readconnectTimeout
- timeout (in ms) for initial connectionnoDelay
- TCP NODELAY option?- Throws:
IOException
- if an io error occurrs when creating socketUnknownHostException
- if hostname is invalid
-
SockIO
public SockIO(SockIOPool pool, String host, int timeout, int connectTimeout, boolean noDelay) throws IOException, UnknownHostException creates a new SockIO object wrapping a socket connection to host:port, and its input and output streams- Parameters:
host
- hostname:porttimeout
- read timeout value for connected socketconnectTimeout
- timeout for initial connectionsnoDelay
- TCP NODELAY option?- Throws:
IOException
- if an io error occurrs when creating socketUnknownHostException
- if hostname is invalid
-
-
Method Details
-
getSocket
Method which gets a connection from SocketChannel.- Parameters:
host
- host to establish connection toport
- port on that hosttimeout
- connection timeout in ms- Returns:
- connected socket
- Throws:
IOException
- if errors connecting or if connection times out
-
getChannel
Lets caller get access to underlying channel.- Returns:
- the backing SocketChannel
-
getHost
returns the host this socket is connected to- Returns:
- String representation of host (hostname:port)
-
trueClose
closes socket and all streams connected to it- Throws:
IOException
- if fails to close streams or socket
-
trueClose
closes socket and all streams connected to it- Throws:
IOException
- if fails to close streams or socket
-
close
void close()sets closed flag and checks in to connection pool but does not close connections -
isConnected
boolean isConnected()checks if the connection is open- Returns:
- true if connected
-
isAlive
boolean isAlive() -
readLine
reads a line intentionally not using the deprecated readLine method from DataInputStream- Specified by:
readLine
in interfaceLineInputStream
- Returns:
- String that was read in
- Throws:
IOException
- if io problems during read
-
clearEOL
reads up to end of line and returns nothing- Specified by:
clearEOL
in interfaceLineInputStream
- Throws:
IOException
- if io problems during read
-
read
reads length bytes into the passed in byte array from dtream- Specified by:
read
in interfaceLineInputStream
- Parameters:
b
- byte array- Returns:
- The number of bytes actually read, or -1 if none could be read.
- Throws:
IOException
- if io problems during read
-
flush
flushes output stream- Throws:
IOException
- if io problems during read
-
write
writes a byte array to the output stream- Parameters:
b
- byte array to write- Throws:
IOException
- if an io error happens
-
hashCode
public int hashCode()use the sockets hashcode for this object so we can key off of SockIOs -
toString
returns the string representation of this socket -
finalize
Hack to reap any leaking children.
-