Example usage for org.springframework.integration.ip.tcp.connection TcpNioServerConnectionFactory setSoTimeout

List of usage examples for org.springframework.integration.ip.tcp.connection TcpNioServerConnectionFactory setSoTimeout

Introduction

In this page you can find the example usage for org.springframework.integration.ip.tcp.connection TcpNioServerConnectionFactory setSoTimeout.

Prototype

public void setSoTimeout(int soTimeout) 

Source Link

Usage

From source file:org.springframework.integration.ip.tcp.connection.TcpNioConnectionTests.java

@Test
public void testAssemblerUsesSecondaryExecutor() throws Exception {
    TcpNioServerConnectionFactory factory = new TcpNioServerConnectionFactory(0);
    factory.setApplicationEventPublisher(nullPublisher);

    CompositeExecutor compositeExec = compositeExecutor();

    factory.setSoTimeout(1000);
    factory.setTaskExecutor(compositeExec);
    final AtomicReference<String> threadName = new AtomicReference<String>();
    final CountDownLatch latch = new CountDownLatch(1);
    factory.registerListener(new TcpListener() {

        @Override/*from   ww  w .java 2 s . c om*/
        public boolean onMessage(Message<?> message) {
            if (!(message instanceof ErrorMessage)) {
                threadName.set(Thread.currentThread().getName());
                latch.countDown();
            }
            return false;
        }

    });
    factory.start();
    TestingUtilities.waitListening(factory, null);
    int port = factory.getPort();

    Socket socket = null;
    int n = 0;
    while (n++ < 100) {
        try {
            socket = SocketFactory.getDefault().createSocket("localhost", port);
            break;
        } catch (ConnectException e) {
        }
        Thread.sleep(100);
    }
    assertTrue("Could not open socket to localhost:" + port, n < 100);
    socket.getOutputStream().write("foo\r\n".getBytes());
    socket.close();

    assertTrue(latch.await(10, TimeUnit.SECONDS));
    assertThat(threadName.get(), containsString("assembler"));

    factory.stop();
}