use of org.apache.camel.component.mllp.impl.MllpSocketReader in project camel by apache.
the class MllpTcpClientProducer method checkConnection.
/**
* Validate the TCP Connection
*
* @return null if the connection is valid, otherwise the Exception encountered checking the connection
*/
void checkConnection() throws IOException {
if (null == socket || socket.isClosed() || !socket.isConnected()) {
socket = new Socket();
socket.setKeepAlive(endpoint.keepAlive);
socket.setTcpNoDelay(endpoint.tcpNoDelay);
if (null != endpoint.receiveBufferSize) {
socket.setReceiveBufferSize(endpoint.receiveBufferSize);
} else {
endpoint.receiveBufferSize = socket.getReceiveBufferSize();
}
if (null != endpoint.sendBufferSize) {
socket.setSendBufferSize(endpoint.sendBufferSize);
} else {
endpoint.sendBufferSize = socket.getSendBufferSize();
}
socket.setReuseAddress(endpoint.reuseAddress);
socket.setSoLinger(false, -1);
InetSocketAddress socketAddress;
if (null == endpoint.getHostname()) {
socketAddress = new InetSocketAddress(endpoint.getPort());
} else {
socketAddress = new InetSocketAddress(endpoint.getHostname(), endpoint.getPort());
}
log.debug("Connecting to socket on {}", socketAddress);
socket.connect(socketAddress, endpoint.connectTimeout);
log.debug("Creating MllpSocketReader and MllpSocketWriter");
mllpSocketReader = new MllpSocketReader(socket, endpoint.receiveTimeout, endpoint.readTimeout, true);
if (endpoint.bufferWrites) {
mllpSocketWriter = new MllpBufferedSocketWriter(socket, false);
} else {
mllpSocketWriter = new MllpSocketWriter(socket, false);
}
}
}
Aggregations