Package org.jppf.comm.socket
Class BootstrapSocketClient
java.lang.Object
org.jppf.comm.socket.AbstractSocketWrapper
org.jppf.comm.socket.BootstrapSocketClient
- All Implemented Interfaces:
Closeable,AutoCloseable,SocketWrapper
This class provides a simple API to transfer objects over a TCP socket connection.
- Author:
- Laurent Cohen
-
Field Summary
Fields inherited from class org.jppf.comm.socket.AbstractSocketWrapper
dis, dos, host, opened, port, serializer, socket -
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor is invisible to other classes.BootstrapSocketClient(String host, int port) Initialize this socket client and connect it to the specified host on the specified port.BootstrapSocketClient(Socket socket) Initialize this socket client with an already opened and connected socket. -
Method Summary
Modifier and TypeMethodDescriptionGet the object serializer for this socket connection.receive(int timeout) Read an object from a TCP socket connection.voidSend an object over a TCP socket connection.Methods inherited from class org.jppf.comm.socket.AbstractSocketWrapper
checkOpened, close, flush, getHost, getPort, getSocket, getSocketTimestamp, initStreams, isOpened, open, read, readInt, readPartial, receive, receiveBytes, sendBytes, setHost, setPort, setSerializer, setSocket, skip, toString, updateSocketTimestamp, write, writeInt
-
Constructor Details
-
BootstrapSocketClient
public BootstrapSocketClient()Default constructor is invisible to other classes. SeeBootstrapSocketClient(String, int) -
BootstrapSocketClient
Initialize this socket client and connect it to the specified host on the specified port.- Parameters:
host- the remote host this socket client connects to.port- the remote port on the host this socket client connects to.- Throws:
ConnectException- if the connection fails.IOException- if there is an issue with the socket streams.
-
BootstrapSocketClient
Initialize this socket client with an already opened and connected socket.- Parameters:
socket- the underlying socket this socket client wraps around.- Throws:
JPPFException- if the socket connection fails.
-
-
Method Details
-
send
Send an object over a TCP socket connection.- Parameters:
o- the object to send.- Throws:
Exception- if the underlying output stream throws an exception.
-
receive
Read an object from a TCP socket connection. This method blocks until an object is received or the specified timeout has expired, whichever happens first.- Parameters:
timeout- timeout after which the operation is aborted. A timeout of zero is interpreted as an infinite timeout.- Returns:
- the object that was read from the underlying input stream or null if the operation timed out.
- Throws:
Exception- if the underlying input stream throws an exception.
-
getSerializer
Get the object serializer for this socket connection.- Specified by:
getSerializerin interfaceSocketWrapper- Overrides:
getSerializerin classAbstractSocketWrapper- Returns:
- an instance of
ObjectSerializer. - See Also:
-