2 * Copyright (c) 2013 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
8 package org.opendaylight.protocol.bgp.parser.spi.pojo;
10 import io.netty.buffer.ByteBuf;
12 import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
13 import org.opendaylight.protocol.bgp.parser.spi.AbstractMessageRegistry;
14 import org.opendaylight.protocol.bgp.parser.spi.MessageParser;
15 import org.opendaylight.protocol.bgp.parser.spi.MessageSerializer;
16 import org.opendaylight.protocol.concepts.HandlerRegistry;
17 import org.opendaylight.yangtools.yang.binding.DataContainer;
18 import org.opendaylight.yangtools.yang.binding.Notification;
20 final class SimpleMessageRegistry extends AbstractMessageRegistry {
22 private final HandlerRegistry<DataContainer, MessageParser, MessageSerializer> handlers = new HandlerRegistry<>();
25 protected Notification parseBody(final int type, final ByteBuf body, final int messageLength) throws BGPDocumentedException {
26 final MessageParser parser = this.handlers.getParser(type);
31 return parser.parseMessageBody(body, messageLength);
35 protected void serializeMessageImpl(final Notification message, final ByteBuf buffer) {
36 final MessageSerializer serializer = this.handlers.getSerializer(message.getImplementedInterface());
37 if (serializer == null) {
40 serializer.serializeMessage(message, buffer);
43 AutoCloseable registerMessageParser(final int messageType, final MessageParser parser) {
44 return this.handlers.registerParser(messageType, parser);
47 AutoCloseable registerMessageSerializer(final Class<? extends Notification> messageClass, final MessageSerializer serializer) {
48 return this.handlers.registerSerializer(messageClass, serializer);