db5557f0d062414f232bbd8bf1260d56aa104a31
[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.Singleton;
27 import com.google.inject.multibindings.Multibinder;
28 import com.google.inject.name.Names;
29 import io.fd.honeycomb.lisp.cfgattrs.LispConfiguration;
30 import io.fd.honeycomb.lisp.context.util.AdjacenciesMappingContext;
31 import io.fd.honeycomb.lisp.context.util.ContextsReaderFactoryProvider;
32 import io.fd.honeycomb.lisp.context.util.EidMappingContext;
33 import io.fd.honeycomb.lisp.translate.read.factory.LispStateReaderFactory;
34 import io.fd.honeycomb.lisp.translate.write.factory.LispWriterFactory;
35 import io.fd.honeycomb.translate.read.ReaderFactory;
36 import io.fd.honeycomb.translate.vpp.util.NamingContext;
37 import io.fd.honeycomb.translate.write.WriterFactory;
38 import net.jmob.guice.conf.core.ConfigurationModule;
39 import org.slf4j.Logger;
40 import org.slf4j.LoggerFactory;
41
42 public class LispModule extends AbstractModule {
43
44     private static final Logger LOG = LoggerFactory.getLogger(LispModule.class);
45
46     @Override
47     protected void configure() {
48         LOG.info("Configuring module Lisp");
49         install(ConfigurationModule.create());
50         requestInjection(LispConfiguration.class);
51
52         LOG.info("Binding Naming context[{}]", LOCATOR_SET_CONTEXT);
53         bind(NamingContext.class)
54                 .annotatedWith(Names.named(LOCATOR_SET_CONTEXT))
55                 .toInstance(new NamingContext(LOCATOR_SET_CONTEXT_PREFIX, LOCATOR_SET_CONTEXT));
56
57         LOG.info("Binding Eid context[{}]", LOCAL_MAPPING_CONTEXT);
58         bind(EidMappingContext.class)
59                 .annotatedWith(Names.named(LOCAL_MAPPING_CONTEXT))
60                 .toInstance(new EidMappingContext(LOCAL_MAPPING_CONTEXT));
61
62         LOG.info("Binding Eid context[{}]", REMOTE_MAPPING_CONTEXT);
63         bind(EidMappingContext.class)
64                 .annotatedWith(Names.named(REMOTE_MAPPING_CONTEXT))
65                 .toInstance(new EidMappingContext(REMOTE_MAPPING_CONTEXT));
66
67         LOG.info("Binding Adjacencies context");
68         bind(AdjacenciesMappingContext.class)
69                 .annotatedWith(Names.named(LispConfiguration.ADJACENCIES_IDENTIFICATION_CONTEXT))
70                 .toInstance(new AdjacenciesMappingContext(LispConfiguration.ADJACENCIES_IDENTIFICATION_CONTEXT));
71
72         LOG.info("Binding reader factories");
73         final Multibinder<ReaderFactory> readerFactoryBinder = Multibinder.newSetBinder(binder(), ReaderFactory.class);
74         readerFactoryBinder.addBinding().to(LispStateReaderFactory.class);
75         LOG.info("Reader factories binded");
76
77         LOG.info("Binding writer factories");
78         final Multibinder<WriterFactory> writerFactoryBinder = Multibinder.newSetBinder(binder(), WriterFactory.class);
79         writerFactoryBinder.addBinding().to(LispWriterFactory.class);
80         LOG.info("Writer factories binded");
81
82         final Multibinder<ReaderFactory> readerBinder = Multibinder.newSetBinder(binder(), ReaderFactory.class);
83         readerBinder.addBinding().toProvider(ContextsReaderFactoryProvider.class).in(Singleton.class);
84
85         LOG.info("Module Lisp successfully configured");
86     }
87 }