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.impl;
10 import java.util.List;
12 import org.opendaylight.protocol.bgp.parser.BGPMessageFactory;
13 import org.opendaylight.protocol.bgp.parser.spi.MessageRegistry;
14 import org.opendaylight.protocol.bgp.parser.spi.ProviderContext;
15 import org.opendaylight.protocol.framework.DeserializerException;
16 import org.opendaylight.protocol.framework.DocumentedException;
17 import org.opendaylight.yangtools.yang.binding.Notification;
19 import com.google.common.base.Preconditions;
20 import com.google.common.collect.Lists;
22 public final class BGPMessageFactoryImpl implements BGPMessageFactory {
23 private static final class Holder {
24 private static final BGPMessageFactoryImpl INSTANCE;
27 final ProviderContext pc = SingletonProviderContext.getInstance();
29 new ActivatorImpl().start(pc);
31 INSTANCE = new BGPMessageFactoryImpl(pc.getMessageRegistry());
35 private final MessageRegistry registry;
37 private BGPMessageFactoryImpl(final MessageRegistry registry) {
38 this.registry = Preconditions.checkNotNull(registry);
41 public static BGPMessageFactoryImpl getInstance() {
42 return Holder.INSTANCE;
47 * @see org.opendaylight.protocol.bgp.parser.BGPMessageParser#parse(byte[])
50 public final List<Notification> parse(final byte[] bytes) throws DeserializerException, DocumentedException {
51 return Lists.newArrayList(registry.parseMessage(bytes));
55 public final byte[] put(final Notification msg) {
56 return registry.serializeMessage(msg);