Upgrade ietf-{inet,yang}-types to 2013-07-15
[bgpcep.git] / bgp / bmp-impl / src / main / java / org / opendaylight / protocol / bmp / impl / BmpMessageToByteEncoder.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 com.google.common.base.Preconditions;
12 import io.netty.buffer.ByteBuf;
13 import io.netty.channel.ChannelHandler.Sharable;
14 import io.netty.channel.ChannelHandlerContext;
15 import io.netty.handler.codec.MessageToByteEncoder;
16 import org.opendaylight.protocol.bmp.spi.registry.BmpMessageRegistry;
17 import org.opendaylight.yangtools.yang.binding.Notification;
18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
20
21 @Sharable
22 public class BmpMessageToByteEncoder extends MessageToByteEncoder<Notification> {
23
24     private static final Logger LOG = LoggerFactory.getLogger(BmpMessageToByteEncoder.class);
25
26     private final BmpMessageRegistry registry;
27
28     public BmpMessageToByteEncoder(final BmpMessageRegistry registry) {
29         this.registry = Preconditions.checkNotNull(registry);
30     }
31
32     @Override
33     protected void encode(final ChannelHandlerContext ctx, final Notification message, final ByteBuf out) throws Exception {
34         LOG.trace("Encoding message: {}", message);
35         this.registry.serializeMessage(message, out);
36         LOG.debug("Message sent to output: {}", message);
37     }
38
39 }