From 4d1213bc04138e630c720656c18a45397e038b70 Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Tue, 3 Dec 2019 15:27:29 +0100 Subject: [PATCH] Reuse StringEncoders for all connections StringEncoder is stateless and therefore can be shared across multiple channel pipelines. Create a single instance for use by all connections. Change-Id: I660cb90ac3de0476f5637d6a53a8c49826c71f1d Signed-off-by: Robert Varga --- .../ovsdb/lib/impl/OvsdbConnectionService.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/library/impl/src/main/java/org/opendaylight/ovsdb/lib/impl/OvsdbConnectionService.java b/library/impl/src/main/java/org/opendaylight/ovsdb/lib/impl/OvsdbConnectionService.java index 0e4ad09df..77be4ca1e 100644 --- a/library/impl/src/main/java/org/opendaylight/ovsdb/lib/impl/OvsdbConnectionService.java +++ b/library/impl/src/main/java/org/opendaylight/ovsdb/lib/impl/OvsdbConnectionService.java @@ -30,8 +30,8 @@ import io.netty.handler.logging.LoggingHandler; import io.netty.handler.ssl.SslHandler; import io.netty.handler.timeout.IdleStateHandler; import io.netty.handler.timeout.ReadTimeoutHandler; -import io.netty.util.CharsetUtil; import java.net.InetAddress; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -92,6 +92,8 @@ public class OvsdbConnectionService implements AutoCloseable, OvsdbConnection { private static final String USE_SSL = "use-ssl"; private static final int RETRY_PERIOD = 100; // retry after 100 milliseconds + private static final StringEncoder UTF8_ENCODER = new StringEncoder(StandardCharsets.UTF_8); + private static final ScheduledExecutorService EXECUTOR_SERVICE = Executors.newScheduledThreadPool(10, new ThreadFactoryBuilder().setNameFormat("OVSDBPassiveConnServ-%d").build()); @@ -165,7 +167,7 @@ public class OvsdbConnectionService implements AutoCloseable, OvsdbConnection { channel.pipeline().addLast( //new LoggingHandler(LogLevel.INFO), new JsonRpcDecoder(jsonRpcDecoderMaxFrameLength), - new StringEncoder(CharsetUtil.UTF_8), + UTF8_ENCODER, new IdleStateHandler(IDLE_READER_TIMEOUT, 0, 0), new ReadTimeoutHandler(READ_TIMEOUT), new ExceptionHandler(OvsdbConnectionService.this)); @@ -348,7 +350,7 @@ public class OvsdbConnectionService implements AutoCloseable, OvsdbConnection { channel.pipeline().addLast( new JsonRpcDecoder(jsonRpcDecoderMaxFrameLength), - new StringEncoder(CharsetUtil.UTF_8), + UTF8_ENCODER, new IdleStateHandler(IDLE_READER_TIMEOUT, 0, 0), new ReadTimeoutHandler(READ_TIMEOUT), new ExceptionHandler(OvsdbConnectionService.this)); -- 2.36.6