clean test environment
[transportpce.git] / tests / honeynode / 2.2.1 / minimal-distribution-core / src / main / java / io / fd / honeycomb / infra / distro / data / context / ContextPipelineModule.java
1 /*
2  * Copyright (c) 2016 Cisco and/or its affiliates.
3  *
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:
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 package io.fd.honeycomb.infra.distro.data.context;
18
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;
31
32 public class ContextPipelineModule extends PrivateModule {
33
34     public static final String HONEYCOMB_CONTEXT_NOPERSIST = "honeycomb-context-nopersist";
35     public static final String HONEYCOMB_CONTEXT = "honeycomb-context";
36
37     @Override
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);
49
50         // Data Tree manager (without any delegation) on top of context data tree
51         bind(ModifiableDataManager.class).toProvider(ModifiableDTMgrProvider.class).in(Singleton.class);
52
53         // DOMDataBroker interface on top of data tree manager
54         HoneycombContextDOMDataBrokerProvider domBrokerProvider = new HoneycombContextDOMDataBrokerProvider();
55         bind(DOMDataBroker.class).toProvider(domBrokerProvider).in(Singleton.class);
56
57         // BA version of data broker for context
58         bind(DataBroker.class).annotatedWith(Names.named(HONEYCOMB_CONTEXT)).toProvider(BindingDataBrokerProvider.class)
59                 .in(Singleton.class);
60         expose(DataBroker.class).annotatedWith(Names.named(HONEYCOMB_CONTEXT));
61
62         // Create initializer to init persisted config data
63         bind(DataTreeInitializer.class).annotatedWith(Names.named(HONEYCOMB_CONTEXT))
64                 .toProvider(PersistedContextInitializerProvider.class)
65                 .in(Singleton.class);
66         expose(DataTreeInitializer.class).annotatedWith(Names.named(HONEYCOMB_CONTEXT));
67
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));
72     }
73 }