Replace Preconditions.CheckNotNull per RequireNonNull
[bgpcep.git] / bgp / bmp-impl / src / main / java / org / opendaylight / protocol / bmp / impl / BmpByteToMessageDecoder.java
1 /*
2  * Copyright (c) 2015 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.protocol.bmp.impl;
10
11 import static java.util.Objects.requireNonNull;
12
13 import io.netty.buffer.ByteBuf;
14 import io.netty.buffer.ByteBufUtil;
15 import io.netty.channel.ChannelHandlerContext;
16 import io.netty.handler.codec.ByteToMessageDecoder;
17 import java.util.List;
18 import org.opendaylight.protocol.bmp.spi.parser.BmpDeserializationException;
19 import org.opendaylight.protocol.bmp.spi.registry.BmpMessageRegistry;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
22
23 public class BmpByteToMessageDecoder extends ByteToMessageDecoder {
24
25     private static final Logger LOG = LoggerFactory.getLogger(BmpByteToMessageDecoder.class);
26     private final BmpMessageRegistry registry;
27
28     public BmpByteToMessageDecoder(final BmpMessageRegistry registry) {
29         this.registry = requireNonNull(registry);
30     }
31
32     @Override
33     protected void decode(final ChannelHandlerContext ctx, final ByteBuf in, final List<Object> out)
34         throws BmpDeserializationException {
35         if (in.isReadable()) {
36             LOG.trace("Received to decode: {}", ByteBufUtil.hexDump(in));
37             out.add(this.registry.parseMessage(in));
38         } else {
39             LOG.trace("No more content in incoming buffer.");
40         }
41     }
42
43 }