2 * Copyright (c) 2016 Cisco and/or its affiliates.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at:
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package io.fd.honeycomb.infra.distro.data.context;
19 import com.google.inject.PrivateModule;
20 import com.google.inject.Singleton;
21 import com.google.inject.name.Names;
22 import io.fd.honeycomb.data.ModifiableDataManager;
23 import io.fd.honeycomb.data.init.DataTreeInitializer;
24 import io.fd.honeycomb.infra.distro.data.BindingDataBrokerProvider;
25 import io.fd.honeycomb.infra.distro.data.DataTreeProvider;
26 import io.fd.honeycomb.infra.distro.data.PersistingDataTreeProvider;
27 import io.fd.honeycomb.translate.MappingContext;
28 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
29 import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
30 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree;
32 public class ContextPipelineModule extends PrivateModule {
34 public static final String HONEYCOMB_CONTEXT_NOPERSIST = "honeycomb-context-nopersist";
35 public static final String HONEYCOMB_CONTEXT = "honeycomb-context";
38 protected void configure() {
39 // Non persisting data tree for context
40 DataTreeProvider.ContextDataTreeProvider noPersistDataTreeProvider =
41 new DataTreeProvider.ContextDataTreeProvider();
42 bind(DataTree.class).annotatedWith(Names.named(HONEYCOMB_CONTEXT_NOPERSIST))
43 .toProvider(noPersistDataTreeProvider).in(Singleton.class);
44 expose(DataTree.class).annotatedWith(Names.named(HONEYCOMB_CONTEXT_NOPERSIST));
45 // Persisting data tree wrapper for context
46 PersistingDataTreeProvider.ContextPersistingDataTreeProvider dataTreeProvider =
47 new PersistingDataTreeProvider.ContextPersistingDataTreeProvider();
48 bind(DataTree.class).toProvider(dataTreeProvider).in(Singleton.class);
50 // Data Tree manager (without any delegation) on top of context data tree
51 bind(ModifiableDataManager.class).toProvider(ModifiableDTMgrProvider.class).in(Singleton.class);
53 // DOMDataBroker interface on top of data tree manager
54 HoneycombContextDOMDataBrokerProvider domBrokerProvider = new HoneycombContextDOMDataBrokerProvider();
55 bind(DOMDataBroker.class).toProvider(domBrokerProvider).in(Singleton.class);
57 // BA version of data broker for context
58 bind(DataBroker.class).annotatedWith(Names.named(HONEYCOMB_CONTEXT)).toProvider(BindingDataBrokerProvider.class)
60 expose(DataBroker.class).annotatedWith(Names.named(HONEYCOMB_CONTEXT));
62 // Create initializer to init persisted config data
63 bind(DataTreeInitializer.class).annotatedWith(Names.named(HONEYCOMB_CONTEXT))
64 .toProvider(PersistedContextInitializerProvider.class)
66 expose(DataTreeInitializer.class).annotatedWith(Names.named(HONEYCOMB_CONTEXT));
68 // Mapping context is just a small adapter on top of BA data broker to simplify CRUD of context data
69 bind(MappingContext.class).annotatedWith(Names.named(HONEYCOMB_CONTEXT))
70 .toProvider(RealtimeMappingContextProvider.class).in(Singleton.class);
71 expose(MappingContext.class).annotatedWith(Names.named(HONEYCOMB_CONTEXT));