Fix message aggregator for chunked netconf messages.
[controller.git] / opendaylight / netconf / netconf-util / src / main / java / org / opendaylight / controller / netconf / util / 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
9 package org.opendaylight.controller.netconf.util.handler;
10
11 import org.opendaylight.controller.netconf.util.messages.FramingMechanism;
12 import org.slf4j.Logger;
13 import org.slf4j.LoggerFactory;
14
15 import io.netty.buffer.ByteBuf;
16 import io.netty.handler.codec.MessageToByteEncoder;
17
18 public class FramingMechanismHandlerFactory {
19
20     private static final Logger logger = LoggerFactory.getLogger(FramingMechanismHandlerFactory.class);
21
22     private FramingMechanismHandlerFactory() {}
23
24     public static MessageToByteEncoder<ByteBuf> createHandler(FramingMechanism framingMechanism) {
25         logger.debug("{} framing mechanism was selected.", framingMechanism);
26         if (framingMechanism == FramingMechanism.EOM) {
27             return new EOMFramingMechanismEncoder();
28         } else {
29             return new ChunkedFramingMechanismEncoder();
30         }
31     }
32 }