Search in sources :

Example 16 with TcpNioServerConnectionFactory

use of org.springframework.integration.ip.tcp.connection.TcpNioServerConnectionFactory in project spring-integration by spring-projects.

the class ConnectionFacforyTests method shouldReturnNioFlavor.

@Test
public void shouldReturnNioFlavor() throws Exception {
    AbstractServerConnectionFactory server = Tcp.nioServer(0).get();
    assertTrue(server instanceof TcpNioServerConnectionFactory);
    AbstractClientConnectionFactory client = Tcp.nioClient("localhost", server.getPort()).get();
    assertTrue(client instanceof TcpNioClientConnectionFactory);
}
Also used : AbstractClientConnectionFactory(org.springframework.integration.ip.tcp.connection.AbstractClientConnectionFactory) TcpNioServerConnectionFactory(org.springframework.integration.ip.tcp.connection.TcpNioServerConnectionFactory) AbstractServerConnectionFactory(org.springframework.integration.ip.tcp.connection.AbstractServerConnectionFactory) TcpNioClientConnectionFactory(org.springframework.integration.ip.tcp.connection.TcpNioClientConnectionFactory) Test(org.junit.Test)

Example 17 with TcpNioServerConnectionFactory

use of org.springframework.integration.ip.tcp.connection.TcpNioServerConnectionFactory in project faf-java-server by FAForever.

the class LegacyAdapterConfig method tcpServerConnectionFactory.

/**
 * Non-blocking TCP connection factory that deserializes into byte array messages.
 */
@Bean
public TcpNioServerConnectionFactory tcpServerConnectionFactory() {
    ByteArrayLengthHeaderSerializer serializer = new ByteArrayLengthHeaderSerializer();
    serializer.setMaxMessageSize(100 * 1024);
    serializer.setApplicationEventPublisher(applicationEventPublisher);
    TcpNioServerConnectionFactory connectionFactory = new TcpNioServerConnectionFactory(serverProperties.getPort());
    connectionFactory.setDeserializer(serializer);
    connectionFactory.setSerializer(serializer);
    connectionFactory.setUsingDirectBuffers(true);
    connectionFactory.getMapper().setApplySequence(true);
    // See https://docs.spring.io/spring-integration/reference/html/ip.html#_thread_pool_task_executor_with_caller_runs_policy
    connectionFactory.setTaskExecutor(new CompositeExecutor(createNioTaskExecutor("legacy-io-"), createNioTaskExecutor("legacy-assembler-")));
    return connectionFactory;
}
Also used : CompositeExecutor(org.springframework.integration.util.CompositeExecutor) TcpNioServerConnectionFactory(org.springframework.integration.ip.tcp.connection.TcpNioServerConnectionFactory) ByteArrayLengthHeaderSerializer(org.springframework.integration.ip.tcp.serializer.ByteArrayLengthHeaderSerializer) Bean(org.springframework.context.annotation.Bean)

Aggregations

TcpNioServerConnectionFactory (org.springframework.integration.ip.tcp.connection.TcpNioServerConnectionFactory)17 Test (org.junit.Test)13 QueueChannel (org.springframework.integration.channel.QueueChannel)9 Socket (java.net.Socket)8 ServerSocket (java.net.ServerSocket)7 AbstractServerConnectionFactory (org.springframework.integration.ip.tcp.connection.AbstractServerConnectionFactory)7 ByteArrayCrLfSerializer (org.springframework.integration.ip.tcp.serializer.ByteArrayCrLfSerializer)5 BeanFactory (org.springframework.beans.factory.BeanFactory)4 HashSet (java.util.HashSet)3 TcpNioClientConnectionFactory (org.springframework.integration.ip.tcp.connection.TcpNioClientConnectionFactory)3 Executor (java.util.concurrent.Executor)2 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)2 SimpleAsyncTaskExecutor (org.springframework.core.task.SimpleAsyncTaskExecutor)2 ServiceActivatingHandler (org.springframework.integration.handler.ServiceActivatingHandler)2 IOException (java.io.IOException)1 DatagramSocket (java.net.DatagramSocket)1 LinkedList (java.util.LinkedList)1 Map (java.util.Map)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 Log (org.apache.commons.logging.Log)1