Use switch expression in FramingMechanismHandlerFactory
[netconf.git] / netconf / netconf-netty-util / src / main / java / org / opendaylight / netconf / nettyutil / handler / FramingMechanismHandlerFactory.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.netconf.nettyutil.handler;
9
10 import io.netty.buffer.ByteBuf;
11 import io.netty.handler.codec.MessageToByteEncoder;
12 import org.opendaylight.netconf.util.messages.FramingMechanism;
13 import org.slf4j.Logger;
14 import org.slf4j.LoggerFactory;
15
16 public final class FramingMechanismHandlerFactory {
17     private static final Logger LOG = LoggerFactory.getLogger(FramingMechanismHandlerFactory.class);
18
19     private FramingMechanismHandlerFactory() {
20         // not called - private constructor for utility class
21     }
22
23     public static MessageToByteEncoder<ByteBuf> createHandler(final FramingMechanism framingMechanism) {
24         LOG.debug("{} framing mechanism was selected.", framingMechanism);
25         return switch (framingMechanism) {
26             case CHUNK -> new ChunkedFramingMechanismEncoder();
27             case EOM -> new EOMFramingMechanismEncoder();
28         };
29     }
30 }