Merge "Remove bgp-update-api-config"
[bgpcep.git] / pcep / spi / src / main / java / org / opendaylight / protocol / pcep / spi / pojo / ServiceLoaderPCEPExtensionProviderContext.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.pcep.spi.pojo;
9
10 import java.util.ServiceLoader;
11
12 import org.opendaylight.protocol.pcep.spi.PCEPExtensionProviderActivator;
13 import org.opendaylight.protocol.pcep.spi.PCEPExtensionProviderContext;
14
15 public final class ServiceLoaderPCEPExtensionProviderContext extends SimplePCEPExtensionProviderContext {
16         private static final class Holder {
17                 private static final PCEPExtensionProviderContext INSTANCE;
18
19                 static {
20                         try {
21                                 INSTANCE = create();
22                         } catch (final Exception e) {
23                                 throw new ExceptionInInitializerError(e);
24                         }
25                 }
26         }
27
28         private ServiceLoaderPCEPExtensionProviderContext() {
29
30         }
31
32         public static PCEPExtensionProviderContext create() throws Exception {
33                 final PCEPExtensionProviderContext ctx = new SimplePCEPExtensionProviderContext();
34
35                 final ServiceLoader<PCEPExtensionProviderActivator> loader = ServiceLoader.load(PCEPExtensionProviderActivator.class);
36                 for (final PCEPExtensionProviderActivator a : loader) {
37                         a.start(ctx);
38                 }
39
40                 return ctx;
41         }
42
43         public static PCEPExtensionProviderContext getSingletonInstance() {
44                 return Holder.INSTANCE;
45         }
46 }