462a1e4f650608d2225a0aa5c21913c90e7205f3
[hc2vpp.git] /
1 /*
2  * Copyright (c) 2018 Bell Canada, Pantheon Technologies 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.hc2vpp.fib.management;
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 io.fd.hc2vpp.fib.management.read.FibManagementReaderFactory;
25 import io.fd.hc2vpp.fib.management.services.FibTableService;
26 import io.fd.hc2vpp.fib.management.services.FibTableServiceProvider;
27 import io.fd.hc2vpp.fib.management.write.FibManagementWriterFactory;
28 import io.fd.honeycomb.translate.read.ReaderFactory;
29 import io.fd.honeycomb.translate.write.WriterFactory;
30 import javax.annotation.Nonnull;
31 import net.jmob.guice.conf.core.ConfigurationModule;
32 import org.slf4j.Logger;
33 import org.slf4j.LoggerFactory;
34
35 /**
36  * FibManagementModule class instantiating FIB management plugin components.
37  */
38 public class FibManagementModule extends AbstractModule {
39
40     private static final Logger LOG = LoggerFactory.getLogger(FibManagementModule.class);
41     private final Class<? extends Provider<FibTableService>> fibTableServiceProvider;
42
43     public FibManagementModule() {
44         this(FibTableServiceProvider.class);
45     }
46
47     @VisibleForTesting
48     protected FibManagementModule(@Nonnull final Class<? extends Provider<FibTableService>> fibTableServiceProvider) {
49         this.fibTableServiceProvider = fibTableServiceProvider;
50     }
51
52     @Override
53     protected void configure() {
54         LOG.info("Starting FibManagementModule initialization");
55         // requests injection of properties
56         install(ConfigurationModule.create());
57         bind(FibTableService.class).toProvider(fibTableServiceProvider).in(Singleton.class);
58
59         LOG.debug("Injecting FibManagementModule reader factories");
60         // creates reader factory binding
61         final Multibinder<ReaderFactory> readerFactoryBinder = Multibinder.newSetBinder(binder(), ReaderFactory.class);
62         readerFactoryBinder.addBinding().to(FibManagementReaderFactory.class);
63
64         LOG.debug("Injecting FibManagementModule writers factories");
65         // create writer factory binding
66         final Multibinder<WriterFactory> writerFactoryBinder = Multibinder.newSetBinder(binder(), WriterFactory.class);
67         writerFactoryBinder.addBinding().to(FibManagementWriterFactory.class);
68
69         LOG.info("FibManagementModule started successfully");
70     }
71 }