package org.opendaylight.protocol.bgp.parser.impl;
import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
-import org.opendaylight.protocol.bgp.parser.BGPMessageFactory;
import org.opendaylight.protocol.bgp.parser.impl.message.BGPKeepAliveMessageParser;
import org.opendaylight.protocol.bgp.parser.impl.message.BGPNotificationMessageParser;
import org.opendaylight.protocol.bgp.parser.impl.message.BGPOpenMessageParser;
import org.opendaylight.yangtools.yang.binding.Notification;
public final class SimpleBGPMessageFactory extends AbstractMessageRegistry {
+ private static final class Holder {
+ private static final SimpleBGPMessageFactory INSTANCE;
- public static final BGPMessageFactory INSTANCE;
+ static {
+ final SimpleBGPMessageFactory reg = new SimpleBGPMessageFactory();
- static {
- final SimpleBGPMessageFactory reg = new SimpleBGPMessageFactory();
+ reg.registerMessageParser(BGPOpenMessageParser.TYPE, BGPOpenMessageParser.PARSER);
+ reg.registerMessageSerializer(Open.class, BGPOpenMessageParser.SERIALIZER);
+ reg.registerMessageParser(BGPUpdateMessageParser.TYPE, BGPUpdateMessageParser.PARSER);
+ // Serialization of Update message is not supported
+ reg.registerMessageParser(BGPNotificationMessageParser.TYPE, BGPNotificationMessageParser.PARSER);
+ reg.registerMessageSerializer(Notify.class, BGPNotificationMessageParser.SERIALIZER);
+ reg.registerMessageParser(BGPKeepAliveMessageParser.TYPE, BGPKeepAliveMessageParser.PARSER);
+ reg.registerMessageSerializer(Keepalive.class, BGPKeepAliveMessageParser.SERIALIZER);
- reg.registerMessageParser(BGPOpenMessageParser.TYPE, BGPOpenMessageParser.PARSER);
- reg.registerMessageSerializer(Open.class, BGPOpenMessageParser.SERIALIZER);
- reg.registerMessageParser(BGPUpdateMessageParser.TYPE, BGPUpdateMessageParser.PARSER);
- // Serialization of Update message is not supported
- reg.registerMessageParser(BGPNotificationMessageParser.TYPE, BGPNotificationMessageParser.PARSER);
- reg.registerMessageSerializer(Notify.class, BGPNotificationMessageParser.SERIALIZER);
- reg.registerMessageParser(BGPKeepAliveMessageParser.TYPE, BGPKeepAliveMessageParser.PARSER);
- reg.registerMessageSerializer(Keepalive.class, BGPKeepAliveMessageParser.SERIALIZER);
-
- INSTANCE = reg;
+ INSTANCE = reg;
+ }
}
private final HandlerRegistry<DataContainer, MessageParser, MessageSerializer> handlers = new HandlerRegistry<>();
}
+ public static SimpleBGPMessageFactory getInstance() {
+ return Holder.INSTANCE;
+ }
+
@Override
protected Notification parseBody(final int type, final byte[] body, final int messageLength) throws BGPDocumentedException {
final MessageParser parser = handlers.getParser(type);