|
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Objectorg.jppf.comm.socket.SocketChannelClient
public class SocketChannelClient
This SocketWrapper implementation relies on an underlying SocketChannel, in order to allow writing to, and reading from, at the same time from the same socket connection.
| Field Summary |
|---|
| Fields inherited from interface org.jppf.comm.socket.SocketWrapper |
|---|
SOCKET_RECEIVE_BUFFER_SIZE |
| Constructor Summary | |
|---|---|
SocketChannelClient(boolean blocking)
Initialize this socket channel client. |
|
SocketChannelClient(String host,
int port,
boolean blocking)
Initialize this socket channel client with a specified host and port. |
|
| Method Summary | |
|---|---|
void |
close()
Close the underlying socket connection. |
void |
flush()
This method does nothing, there is no flush on socket channels. |
SocketChannel |
getChannel()
Get the underlying socket used by this socket wrapper. |
String |
getHost()
Get the remote host the underlying socket connects to. |
int |
getPort()
Get the remote port the underlying socket connects to. |
ObjectSerializer |
getSerializer()
Get an object serializer / deserializer to convert an object to or from an array of bytes. |
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. |
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. |
Object |
receive(int timeout)
Read an object from a TCP socket connection. |
JPPFBuffer |
receiveBytes(int timeout)
Read an object from a TCP socket connection. |
void |
send(Object o)
Send an object over a TCP socket connection. |
void |
sendBytes(JPPFBuffer buf)
Send an array of bytes over a TCP socket connection. |
void |
setChannel(SocketChannel channel)
Set the underlying socket to be used by this socket wrapper. |
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)
Set the object serializer / deserializer to convert an object to or from an array of bytes. |
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 sokcet of channel input stream. |
void |
write(byte[] data)
Send an array of bytes over a TCP socket connection. |
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 |
| Constructor Detail |
|---|
public SocketChannelClient(boolean blocking)
throws IOException
blocking - true if the socket channel is in blocking mode, false otherwise.
IOException - if the socket channel could not be opened.
public SocketChannelClient(String host,
int port,
boolean blocking)
throws IOException
host - the host to connect to.port - the port to listen on the host.blocking - true if the socket channel is in blocking mode, false otherwise.
IOException - if the socket channel could not be opened.| Method Detail |
|---|
public void send(Object o)
throws Exception
send in interface SocketWrappero - the object to send.
Exception - if the underlying output stream throws an exception.SocketWrapper.send(java.lang.Object)
public void sendBytes(JPPFBuffer buf)
throws Exception
sendBytes in interface SocketWrapperbuf - the buffer container for the data to send.
Exception - 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 Object receive(int timeout)
throws Exception
receive in interface SocketWrappertimeout - timeout after which the operation is aborted. A timeout of zero is interpreted as an infinite timeout.
Exception - if the underlying input stream throws an exception.SocketWrapper.receive(int)
public JPPFBuffer receiveBytes(int timeout)
throws Exception
receiveBytes in interface SocketWrappertimeout - timeout after which the operation is aborted. A timeout of zero is interpreted as an infinite timeout.
Exception - if the underlying input stream throws an exception.SocketWrapper.receiveBytes(int)
public int read(byte[] data,
int offset,
int len)
throws Exception
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.
Exception - 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 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()
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()public ObjectSerializer getSerializer()
getSerializer in interface SocketWrapperObjectSerializer instance.SocketWrapper.getSerializer()public void setSerializer(ObjectSerializer serializer)
setSerializer in interface SocketWrapperserializer - an ObjectSerializer instance.SocketWrapper.setSerializer(org.jppf.utils.ObjectSerializer)public String getHost()
getHost in interface SocketWrapperSocketWrapper.getHost()public void setHost(String host)
setHost in interface SocketWrapperhost - the host name or ip address as a string.SocketWrapper.setHost(java.lang.String)public int getPort()
getPort in interface SocketWrapperSocketWrapper.getPort()public void setPort(int port)
setPort in interface SocketWrapperport - the port number on the remote host.SocketWrapper.setPort(int)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 SocketChannel getChannel()
public void setChannel(SocketChannel channel)
channel - a SocketChannel instance.
public int skip(int n)
throws Exception
n bytes of data from the sokcet of channel input stream.
skip in interface SocketWrappern - the number of bytes to skip.
Exception - if an IO error occurs.SocketWrapper.skip(int)
public void write(byte[] data)
throws Exception
data - the data to send.
Exception - if the underlying output stream throws an exception.write(byte[],int,int)public long getSocketTimestamp()
getSocketTimestamp in interface SocketWrapper
|
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||