HONEYCOMB-58 - Routing Api
[honeycomb.git] / nsh / impl / src / main / java / io / fd / honeycomb / vppnsh / impl / VppNshModule.java
1 /*
2  * Copyright (c) 2016 Intel 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.vppnsh.impl;
18
19 import com.google.common.annotations.VisibleForTesting;
20 import com.google.inject.AbstractModule;
21 import com.google.inject.Provider;
22 import com.google.inject.Singleton;
23 import com.google.inject.multibindings.Multibinder;
24 import com.google.inject.name.Names;
25 import io.fd.honeycomb.translate.read.ReaderFactory;
26 import io.fd.honeycomb.translate.vpp.util.NamingContext;
27 import io.fd.honeycomb.translate.write.WriterFactory;
28 import io.fd.honeycomb.vppnsh.impl.config.VppNshWriterFactory;
29 import io.fd.honeycomb.vppnsh.impl.oper.VppNshReaderFactory;
30 import io.fd.honeycomb.vppnsh.impl.util.JVppNshProvider;
31 import io.fd.vpp.jvpp.nsh.future.FutureJVppNsh;
32 import io.fd.vpp.jvpp.nsh.future.FutureJVppNshFacade;
33 import org.slf4j.Logger;
34 import org.slf4j.LoggerFactory;
35
36 /**
37  * This is some glue code necessary for Honeycomb distribution to pick up the plugin classes
38  */
39 public final class VppNshModule extends AbstractModule {
40
41     private static final Logger LOG = LoggerFactory.getLogger(VppNshModule.class);
42     private final Class<? extends Provider<FutureJVppNshFacade>> jvppNshProviderClass;
43
44     public VppNshModule() {
45         this(JVppNshProvider.class);
46     }
47     @VisibleForTesting
48     VppNshModule(Class<? extends Provider<FutureJVppNshFacade>> jvppNshProvider) {
49         this.jvppNshProviderClass = jvppNshProvider;
50     }
51
52     @Override
53     protected void configure() {
54         LOG.debug("Installing NSH module");
55
56         // Naming contexts
57         bind(NamingContext.class)
58             .annotatedWith(Names.named("nsh-entry-context"))
59             .toInstance(new NamingContext("nsh-entry-", "nsh-entry-context"));
60
61         bind(NamingContext.class)
62             .annotatedWith(Names.named("nsh-map-context"))
63             .toInstance(new NamingContext("nsh-map-", "nsh-map-context"));
64
65         // Bind to Plugin's JVPP.
66         bind(FutureJVppNsh.class).toProvider(jvppNshProviderClass).in(Singleton.class);
67
68         // Below are classes picked up by HC framework
69         Multibinder.newSetBinder(binder(), WriterFactory.class).addBinding().to(VppNshWriterFactory.class);
70         Multibinder.newSetBinder(binder(), ReaderFactory.class).addBinding().to(VppNshReaderFactory.class);
71         LOG.info("Module NSH successfully configured");
72     }
73 }