5344dfc7fddd83c698643dbbf17d88aaf5e447ac
[honeycomb.git] / lisp / lisp2vpp / src / main / java / io / fd / honeycomb / lisp / LispModule.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.lisp;
18
19
20 import static io.fd.honeycomb.lisp.cfgattrs.LispConfiguration.LOCAL_MAPPING_CONTEXT;
21 import static io.fd.honeycomb.lisp.cfgattrs.LispConfiguration.LOCATOR_SET_CONTEXT;
22 import static io.fd.honeycomb.lisp.cfgattrs.LispConfiguration.LOCATOR_SET_CONTEXT_PREFIX;
23 import static io.fd.honeycomb.lisp.cfgattrs.LispConfiguration.REMOTE_MAPPING_CONTEXT;
24
25 import com.google.inject.AbstractModule;
26 import com.google.inject.multibindings.Multibinder;
27 import com.google.inject.name.Names;
28 import io.fd.honeycomb.data.init.DataTreeInitializer;
29 import io.fd.honeycomb.lisp.cfgattrs.LispConfiguration;
30 import io.fd.honeycomb.lisp.context.util.EidMappingContext;
31 import io.fd.honeycomb.lisp.translate.initializers.LispInitializer;
32 import io.fd.honeycomb.lisp.translate.read.factory.LispStateReaderFactory;
33 import io.fd.honeycomb.lisp.translate.write.factory.LispWriterFactory;
34 import io.fd.honeycomb.translate.read.ReaderFactory;
35 import io.fd.honeycomb.translate.vpp.util.NamingContext;
36 import io.fd.honeycomb.translate.write.WriterFactory;
37 import net.jmob.guice.conf.core.ConfigurationModule;
38 import org.slf4j.Logger;
39 import org.slf4j.LoggerFactory;
40
41 public class LispModule extends AbstractModule {
42
43     private static final Logger LOG = LoggerFactory.getLogger(LispModule.class);
44
45     @Override
46     protected void configure() {
47         LOG.info("Installing configuration module");
48         install(ConfigurationModule.create());
49
50         LOG.info("Injecting Lisp configuration");
51         requestInjection(LispConfiguration.class);
52
53         LOG.info("Binding Naming context[{}]", LOCATOR_SET_CONTEXT);
54         bind(NamingContext.class)
55                 .annotatedWith(Names.named(LOCATOR_SET_CONTEXT))
56                 .toInstance(new NamingContext(LOCATOR_SET_CONTEXT_PREFIX, LOCATOR_SET_CONTEXT));
57
58         LOG.info("Binding Eid context[{}]", LOCAL_MAPPING_CONTEXT);
59         bind(EidMappingContext.class)
60                 .annotatedWith(Names.named(LOCAL_MAPPING_CONTEXT))
61                 .toInstance(new EidMappingContext(LOCAL_MAPPING_CONTEXT));
62
63         LOG.info("Binding Eid context[{}]", REMOTE_MAPPING_CONTEXT);
64         bind(EidMappingContext.class)
65                 .annotatedWith(Names.named(REMOTE_MAPPING_CONTEXT))
66                 .toInstance(new EidMappingContext(REMOTE_MAPPING_CONTEXT));
67
68         LOG.info("Binding reader factories");
69         final Multibinder<ReaderFactory> readerFactoryBinder = Multibinder.newSetBinder(binder(), ReaderFactory.class);
70
71         LOG.info("Binding [{}]", LispStateReaderFactory.class.getName());
72         readerFactoryBinder.addBinding().to(LispStateReaderFactory.class);
73         LOG.info("Reader factories binded");
74
75         LOG.info("Binding writer factories");
76         final Multibinder<WriterFactory> writerFactoryBinder = Multibinder.newSetBinder(binder(), WriterFactory.class);
77
78         LOG.info("Binding [{}]", LispWriterFactory.class.getName());
79         writerFactoryBinder.addBinding().to(LispWriterFactory.class);
80         LOG.info("Writer factories binded");
81
82         LOG.info("Binding initializers");
83         final Multibinder<DataTreeInitializer> initializerBinder =
84                 Multibinder.newSetBinder(binder(), DataTreeInitializer.class);
85
86         LOG.info("Binding [{}]", LispInitializer.class.getName());
87         initializerBinder.addBinding().to(LispInitializer.class);
88         LOG.info("Initializers binded");
89
90         LOG.info("Module Lisp successfully configured");
91     }
92 }