Merge "Add config classifier to netconf-mdsal-config jar"
[controller.git] / opendaylight / md-sal / messagebus-impl / src / main / java / org / opendaylight / controller / mdsal / InitializationContext.java
1 /**
2  * Copyright (c) 2014 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.controller.mdsal;
9
10 import org.opendaylight.controller.config.yang.messagebus.app.impl.NamespaceToStream;
11 import org.opendaylight.controller.messagebus.app.impl.EventAggregator;
12 import org.opendaylight.controller.messagebus.app.impl.EventSourceManager;
13 import org.opendaylight.controller.messagebus.app.impl.EventSourceTopology;
14 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
15 import org.opendaylight.controller.sal.core.api.Broker;
16 import org.slf4j.Logger;
17 import org.slf4j.LoggerFactory;
18
19 import java.util.List;
20
21 public class InitializationContext {
22     private static final Logger LOGGER = LoggerFactory.getLogger(InitializationContext.class);
23
24     private final MdSAL mdSal;
25     private final DataStore dataStore;
26     private final EventSourceTopology eventSourceTopology;
27     private final EventSourceManager eventSourceManager;
28     private final EventAggregator eventAggregator;
29
30     public InitializationContext(List<NamespaceToStream> namespaceMapping) {
31         this.mdSal = new MdSAL();
32         this.dataStore = new DataStore(mdSal);
33         this.eventSourceTopology = new EventSourceTopology(dataStore);
34         this.eventSourceManager = new EventSourceManager(dataStore, mdSal, eventSourceTopology, namespaceMapping);
35         this.eventAggregator = new EventAggregator(mdSal, eventSourceTopology);
36     }
37
38     public synchronized void set(BindingAwareBroker.ProviderContext session) {
39         mdSal.setBindingAwareContext(session);
40
41         if (mdSal.isReady()) {
42             initialize();
43         }
44     }
45
46     public synchronized void set(Broker.ProviderSession session) {
47         mdSal.setBindingIndependentContext(session);
48
49         if (mdSal.isReady()) {
50             initialize();
51         }
52     }
53
54     private void initialize() {
55         eventSourceTopology.mdsalReady();
56         eventSourceManager.mdsalReady();
57         eventAggregator.mdsalReady();
58
59         LOGGER.info("InitializationContext started.");
60     }
61 }