|
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Objectorg.jppf.comm.socket.AbstractSocketWrapper
public abstract class AbstractSocketWrapper
Common abstract superclass for all socket clients. This class is provided as a convenience and provides
as set of common methods to all classes implementing the
SocketWrapper interface.
| Field Summary | |
|---|---|
protected DataInputStream |
dis
A buffered stream built on top of to the underlying socket's input stream. |
protected DataOutputStream |
dos
A reference to the underlying socket's output stream. |
protected String |
host
The host the socket connects to. |
protected boolean |
opened
Flag indicating the opened state of the underlying socket. |
protected int |
port
The port number on the host the socket connects to. |
protected ObjectSerializer |
serializer
Used to serialize or deserialize an object into or from an array of bytes. |
protected Socket |
socket
The underlying socket wrapped by this SocketClient. |
| Fields inherited from interface org.jppf.comm.socket.SocketWrapper |
|---|
SOCKET_RECEIVE_BUFFER_SIZE |
| Constructor Summary | |
|---|---|
protected |
AbstractSocketWrapper()
Default constructor is visible to subclasses only. |
|
AbstractSocketWrapper(Socket socket)
Initialize this socket client with an already opened and connected socket. |
|
AbstractSocketWrapper(String host,
int port,
ObjectSerializer serializer)
Initialize this socket client and connect it to the specified host on the specified port. |
| Method Summary | |
|---|---|
protected void |
checkOpened()
Check whether the underlying socket is opened or not. |
void |
close()
Close the underlying socket connection. |
void |
flush()
Flush the data currently in the send buffer. |
String |
getHost()
Get the remote host the underlying socket connects to. |
int |
getPort()
Get the remote port the underlying socket connects to. |
ObjectSerializer |
getSerializer()
This implementation does nothing. |
Socket |
getSocket()
Get the underlying socket used by this socket wrapper. |
long |
getSocketTimestamp()
Returns a timestamp that should reflect the system millisecond counter at the last known good usage of the underlying socket. |
protected void |
initStreams()
Initialize all the stream used for receiving and sending objects through the underlying socket connection. |
boolean |
isOpened()
Determine whether this socket client is opened or not. |
void |
open()
Open the underlying socket connection. |
int |
read(byte[] data,
int offset,
int len)
Read len bytes from a TCP connection into a byte array, starting
at position offset in that array. |
int |
readInt()
Read an int value from a socket connection. |
Object |
receive()
Read an object from a TCP socket connection. |
JPPFBuffer |
receiveBytes(int timeout)
Read an object from a TCP socket connection. |
void |
sendBytes(JPPFBuffer buf)
Send an array of bytes over a TCP socket connection. |
void |
setHost(String host)
Set the remote host the underlying socket connects to. |
void |
setPort(int port)
Get the remote port the underlying socket connects to. |
void |
setSerializer(ObjectSerializer serializer)
This implementation does nothing. |
void |
setSocket(Socket socket)
Set the underlying socket to be used by this socket wrapper. |
int |
skip(int n)
Skip n bytes of data from the socket or channel input stream. |
protected void |
updateSocketTimestamp()
Marks the socket "known good" usage timestamp with the current value of the system millisecond counter. |
void |
write(byte[] data,
int offset,
int len)
Send an array of bytes over a TCP socket connection. |
void |
writeInt(int n)
Write an int value over a socket connection. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Methods inherited from interface org.jppf.comm.socket.SocketWrapper |
|---|
receive, send |
| Field Detail |
|---|
protected Socket socket
protected DataOutputStream dos
protected DataInputStream dis
protected String host
protected int port
protected boolean opened
protected ObjectSerializer serializer
| Constructor Detail |
|---|
protected AbstractSocketWrapper()
public AbstractSocketWrapper(String host,
int port,
ObjectSerializer serializer)
throws ConnectException,
IOException
host - the remote host this socket client connects to.port - the remote port on the host this socket client connects to.serializer - the object serializer used by this socket client.
ConnectException - if the connection fails.
IOException - if there is an issue with the socket streams.
public AbstractSocketWrapper(Socket socket)
throws JPPFException
socket - the underlying socket this socket client wraps around.
JPPFException - if the socket connection fails.| Method Detail |
|---|
public void sendBytes(JPPFBuffer buf)
throws IOException
sendBytes in interface SocketWrapperbuf - the buffer container for the data to send.
IOException - if the underlying output stream throws an exception.SocketWrapper.sendBytes(org.jppf.utils.JPPFBuffer)
public void write(byte[] data,
int offset,
int len)
throws Exception
write in interface SocketWrapperdata - the data to send.offset - the position where to start reading data from the input array.len - the length of data to write.
Exception - if the underlying output stream throws an exception.SocketWrapper.write(byte[], int, int)
public void writeInt(int n)
throws Exception
writeInt in interface SocketWrappern - the value to write.
Exception - if the underlying output stream throws an exception.SocketWrapper.writeInt(int)
public void flush()
throws IOException
flush in interface SocketWrapperIOException - if an I/O error occurs.SocketWrapper.flush()
public Object receive()
throws Exception
receive in interface SocketWrapperException - if the underlying input stream throws an exception.SocketWrapper.receive()
public JPPFBuffer receiveBytes(int timeout)
throws IOException
receiveBytes in interface SocketWrappertimeout - timeout after which the operation is aborted. A timeout of zero is interpreted as an infinite timeout.
IOException - if the underlying input stream throws an exception.SocketWrapper.receiveBytes(int)
public int read(byte[] data,
int offset,
int len)
throws IOException
len bytes from a TCP connection into a byte array, starting
at position offset in that array.
This method blocks until at least one byte of data is received.
read in interface SocketWrapperdata - an array of bytes into which the data is stored.offset - the position where to start storing data read from the socket.len - the length of data to read.
IOException - if the underlying input stream throws an exception.SocketWrapper.read(byte[], int, int)
public int readInt()
throws Exception
readInt in interface SocketWrapperException - if the underlying input stream throws an exception.SocketWrapper.readInt()
public final void open()
throws ConnectException,
IOException
open in interface SocketWrapperConnectException - if the socket fails to connect.
IOException - if the underlying input and output streams raise an error.SocketWrapper.open()
protected final void initStreams()
throws IOException
IOException - if an error occurs during the streams initialization.
public void close()
throws ConnectException,
IOException
close in interface SocketWrapperConnectException - if the socket connection is not opened.
IOException - if the underlying input and output streams raise an error.SocketWrapper.close()public boolean isOpened()
isOpened in interface SocketWrapperSocketWrapper.isOpened()
protected void checkOpened()
throws ConnectException
ConnectException - if the connection is not opened.public ObjectSerializer getSerializer()
getSerializer in interface SocketWrapperSocketWrapper.getSerializer()public void setSerializer(ObjectSerializer serializer)
setSerializer in interface SocketWrapperserializer - not used.SocketWrapper.setSerializer(org.jppf.utils.ObjectSerializer)public String getHost()
getHost in interface SocketWrapperpublic void setHost(String host)
setHost in interface SocketWrapperhost - the host name or ip address as a string.public int getPort()
getPort in interface SocketWrapperpublic void setPort(int port)
setPort in interface SocketWrapperport - the port number on the remote host.public Socket getSocket()
getSocket in interface SocketWrapperSocketWrapper.getSocket()public void setSocket(Socket socket)
setSocket in interface SocketWrappersocket - a Socket instance.SocketWrapper.setSocket(java.net.Socket)
public int skip(int n)
throws Exception
n bytes of data from the socket or channel input stream.
skip in interface SocketWrappern - the number of bytes to skip.
Exception - if an IO error occurs.SocketWrapper.skip(int)public long getSocketTimestamp()
getSocketTimestamp in interface SocketWrapperprotected void updateSocketTimestamp()
|
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||