2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
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
9 package org.opendaylight.protocol.bmp.impl;
11 import static java.util.Objects.requireNonNull;
13 import io.netty.buffer.ByteBuf;
14 import io.netty.channel.ChannelHandler.Sharable;
15 import io.netty.channel.ChannelHandlerContext;
16 import io.netty.handler.codec.MessageToByteEncoder;
17 import org.opendaylight.protocol.bmp.spi.registry.BmpMessageRegistry;
18 import org.opendaylight.yangtools.yang.binding.Notification;
19 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory;
23 public class BmpMessageToByteEncoder extends MessageToByteEncoder<Notification> {
25 private static final Logger LOG = LoggerFactory.getLogger(BmpMessageToByteEncoder.class);
27 private final BmpMessageRegistry registry;
29 public BmpMessageToByteEncoder(final BmpMessageRegistry registry) {
30 this.registry = requireNonNull(registry);
34 protected void encode(final ChannelHandlerContext ctx, final Notification message, final ByteBuf out)
36 LOG.trace("Encoding message: {}", message);
37 this.registry.serializeMessage(message, out);
38 LOG.debug("Message sent to output: {}", message);