Bug 498 - Fixed PCEP and BGP testtools
[bgpcep.git] / bgp / parser-spi / src / main / java / org / opendaylight / protocol / bgp / parser / spi / pojo / ServiceLoaderBGPExtensionProviderContext.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.protocol.bgp.parser.spi.pojo;
9
10 import java.util.ServiceLoader;
11
12 import org.opendaylight.protocol.bgp.parser.spi.BGPExtensionProviderActivator;
13 import org.opendaylight.protocol.bgp.parser.spi.BGPExtensionProviderContext;
14
15 public final class ServiceLoaderBGPExtensionProviderContext {
16     private static final class Holder {
17         private static final BGPExtensionProviderContext INSTANCE;
18
19         static {
20             try {
21                 INSTANCE = create();
22             } catch (final Exception e) {
23                 throw new ExceptionInInitializerError(e);
24             }
25         }
26     }
27
28     public static BGPExtensionProviderContext create() throws Exception {
29         final BGPExtensionProviderContext ctx = new SimpleBGPExtensionProviderContext();
30
31         final ServiceLoader<BGPExtensionProviderActivator> loader = ServiceLoader
32                 .load(BGPExtensionProviderActivator.class);
33         for (BGPExtensionProviderActivator a : loader) {
34             a.start(ctx);
35         }
36
37         return ctx;
38     }
39
40     public static BGPExtensionProviderContext getSingletonInstance() {
41         return Holder.INSTANCE;
42     }
43
44     private ServiceLoaderBGPExtensionProviderContext() {
45
46     }
47 }