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 void
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 streamjava.nio.channels.SocketChannel
getChannel()
Lets caller get access to underlying channel.java.lang.String
getHost()
returns the host this socket is connected toprotected static java.net.Socket
getSocket(java.lang.String host, int port, int timeout)
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
isConnected()
checks if the connection is openint
read(byte[] b)
reads length bytes into the passed in byte array from dtreamjava.lang.String
readLine()
reads a line intentionally not using the deprecated readLine method from DataInputStreamjava.lang.String
toString()
returns the string representation of this socketvoid
trueClose()
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 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.IOException
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:
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.IOException
closes 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.IOException
closes 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.IOException
reads a line intentionally not using the deprecated readLine method from DataInputStream- Specified by:
readLine
in interfaceLineInputStream
- Returns:
- String that was read in
- Throws:
java.io.IOException
- if io problems during read
-
clearEOL
public void clearEOL() throws java.io.IOException
reads up to end of line and returns nothing- Specified by:
clearEOL
in interfaceLineInputStream
- Throws:
java.io.IOException
- if io problems during read
-
read
public int read(byte[] b) throws java.io.IOException
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:
java.io.IOException
- if io problems during read
-
flush
void flush() throws java.io.IOException
flushes output stream- Throws:
java.io.IOException
- if io problems during read
-
write
void write(byte[] b) throws java.io.IOException
writes 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:
hashCode
in classjava.lang.Object
- Returns:
- int hashcode
-
toString
public java.lang.String toString()
returns the string representation of this socket- Overrides:
toString
in classjava.lang.Object
- Returns:
- string
-
finalize
protected void finalize() throws java.lang.Throwable
Hack to reap any leaking children.- Overrides:
finalize
in classjava.lang.Object
- Throws:
java.lang.Throwable
-
-