Search in sources :

Example 1 with MllpBufferedSocketWriter

use of org.apache.camel.component.mllp.impl.MllpBufferedSocketWriter 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);
        }
    }
}
Also used : MllpSocketReader(org.apache.camel.component.mllp.impl.MllpSocketReader) MllpBufferedSocketWriter(org.apache.camel.component.mllp.impl.MllpBufferedSocketWriter) InetSocketAddress(java.net.InetSocketAddress) MllpSocketWriter(org.apache.camel.component.mllp.impl.MllpSocketWriter) Socket(java.net.Socket)

Aggregations

InetSocketAddress (java.net.InetSocketAddress)1 Socket (java.net.Socket)1 MllpBufferedSocketWriter (org.apache.camel.component.mllp.impl.MllpBufferedSocketWriter)1 MllpSocketReader (org.apache.camel.component.mllp.impl.MllpSocketReader)1 MllpSocketWriter (org.apache.camel.component.mllp.impl.MllpSocketWriter)1