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;
11 import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
12 import org.opendaylight.protocol.bgp.parser.spi.AbstractMessageRegistry;
13 import org.opendaylight.protocol.bgp.parser.spi.MessageParser;
14 import org.opendaylight.protocol.bgp.parser.spi.MessageSerializer;
15 import org.opendaylight.protocol.bgp.parser.spi.PeerSpecificParserConstraint;
16 import org.opendaylight.protocol.concepts.HandlerRegistry;
17 import org.opendaylight.yangtools.concepts.Registration;
18 import org.opendaylight.yangtools.yang.binding.DataContainer;
19 import org.opendaylight.yangtools.yang.binding.Notification;
21 final class SimpleMessageRegistry extends AbstractMessageRegistry {
23 private final HandlerRegistry<DataContainer, MessageParser, MessageSerializer> handlers = new HandlerRegistry<>();
26 protected Notification parseBody(final int type, final ByteBuf body, final int messageLength,
27 final PeerSpecificParserConstraint constraint) throws BGPDocumentedException {
28 final MessageParser parser = this.handlers.getParser(type);
32 return parser.parseMessageBody(body, messageLength, constraint);
36 protected void serializeMessageImpl(final Notification message, final ByteBuf buffer) {
37 final MessageSerializer serializer = this.handlers.getSerializer(message.implementedInterface());
38 if (serializer == null) {
41 serializer.serializeMessage(message, buffer);
44 Registration registerMessageParser(final int messageType, final MessageParser parser) {
45 return this.handlers.registerParser(messageType, parser);
48 Registration registerMessageSerializer(final Class<? extends Notification> messageClass,
49 final MessageSerializer serializer) {
50 return this.handlers.registerSerializer(messageClass, serializer);