Package com.danga.MemCached
Class SockIOPool.SockIO
- java.lang.Object
-
- com.danga.MemCached.SockIOPool.SockIO
-
- All Implemented Interfaces:
LineInputStream
- Enclosing class:
- SockIOPool
public static class SockIOPool.SockIO extends java.lang.Object implements LineInputStream
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
, Richard 'toast' Russo
-
-
Constructor Summary
Constructors Constructor Description SockIO(SockIOPool pool, java.lang.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, java.lang.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
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclearEOL()reads up to end of line and returns nothing(package private) voidclose()sets closed flag and checks in to connection pool but does not close connectionsprotected voidfinalize()Hack to reap any leaking children.(package private) voidflush()flushes output streamjava.nio.channels.SocketChannelgetChannel()Lets caller get access to underlying channel.java.lang.StringgetHost()returns the host this socket is connected toprotected static java.net.SocketgetSocket(java.lang.String host, int port, int timeout)Method which gets a connection from SocketChannel.inthashCode()use the sockets hashcode for this object so we can key off of SockIOs(package private) booleanisAlive()(package private) booleanisConnected()checks if the connection is openintread(byte[] b)reads length bytes into the passed in byte array from dtreamjava.lang.StringreadLine()reads a line intentionally not using the deprecated readLine method from DataInputStreamjava.lang.StringtoString()returns the string representation of this socketvoidtrueClose()closes socket and all streams connected to itvoidtrueClose(boolean addToDeadPool)closes socket and all streams connected to it(package private) voidwrite(byte[] b)writes a byte array to the output stream
-
-
-
Field Detail
-
log
private static org.apache.log4j.Logger log
-
pool
private SockIOPool pool
-
host
private java.lang.String host
-
sock
private java.net.Socket sock
-
in
private java.io.DataInputStream in
-
out
private java.io.BufferedOutputStream out
-
-
Constructor Detail
-
SockIO
public SockIO(SockIOPool pool, java.lang.String host, int port, int timeout, int connectTimeout, boolean noDelay) throws java.io.IOException, java.net.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:
java.io.IOException- if an io error occurrs when creating socketjava.net.UnknownHostException- if hostname is invalid
-
SockIO
public SockIO(SockIOPool pool, java.lang.String host, int timeout, int connectTimeout, boolean noDelay) throws java.io.IOException, java.net.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:
java.io.IOException- if an io error occurrs when creating socketjava.net.UnknownHostException- if hostname is invalid
-
-
Method Detail
-
getSocket
protected static java.net.Socket getSocket(java.lang.String host, int port, int timeout) throws java.io.IOExceptionMethod 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:
java.io.IOException- if errors connecting or if connection times out
-
getChannel
public java.nio.channels.SocketChannel getChannel()
Lets caller get access to underlying channel.- Returns:
- the backing SocketChannel
-
getHost
public java.lang.String getHost()
returns the host this socket is connected to- Returns:
- String representation of host (hostname:port)
-
trueClose
public void trueClose() throws java.io.IOExceptioncloses socket and all streams connected to it- Throws:
java.io.IOException- if fails to close streams or socket
-
trueClose
public void trueClose(boolean addToDeadPool) throws java.io.IOExceptioncloses socket and all streams connected to it- Throws:
java.io.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
public java.lang.String readLine() throws java.io.IOExceptionreads a line intentionally not using the deprecated readLine method from DataInputStream- Specified by:
readLinein interfaceLineInputStream- Returns:
- String that was read in
- Throws:
java.io.IOException- if io problems during read
-
clearEOL
public void clearEOL() throws java.io.IOExceptionreads up to end of line and returns nothing- Specified by:
clearEOLin interfaceLineInputStream- Throws:
java.io.IOException- if io problems during read
-
read
public int read(byte[] b) throws java.io.IOExceptionreads length bytes into the passed in byte array from dtream- Specified by:
readin interfaceLineInputStream- Parameters:
b- byte array- Returns:
- The number of bytes actually read, or -1 if none could be read.
- Throws:
java.io.IOException- if io problems during read
-
flush
void flush() throws java.io.IOExceptionflushes output stream- Throws:
java.io.IOException- if io problems during read
-
write
void write(byte[] b) throws java.io.IOExceptionwrites a byte array to the output stream- Parameters:
b- byte array to write- Throws:
java.io.IOException- if an io error happens
-
hashCode
public int hashCode()
use the sockets hashcode for this object so we can key off of SockIOs- Overrides:
hashCodein classjava.lang.Object- Returns:
- int hashcode
-
toString
public java.lang.String toString()
returns the string representation of this socket- Overrides:
toStringin classjava.lang.Object- Returns:
- string
-
finalize
protected void finalize() throws java.lang.ThrowableHack to reap any leaking children.- Overrides:
finalizein classjava.lang.Object- Throws:
java.lang.Throwable
-
-