use of com.google.inject.Provides in project camel by apache.
the class CamelModuleWithRouteTypes method routes.
@Provides
Set<RoutesBuilder> routes(Injector injector) {
Set<RoutesBuilder> answer = Sets.newHashSet();
for (Class<? extends RoutesBuilder> type : routes) {
RoutesBuilder route = injector.getInstance(type);
answer.add(route);
}
return answer;
}
use of com.google.inject.Provides in project cdap by caskdata.
the class DefaultPreviewManager method createPreviewInjector.
/**
* Create injector for the given application id.
*/
@VisibleForTesting
Injector createPreviewInjector(ApplicationId applicationId) throws IOException {
CConfiguration previewCConf = CConfiguration.copy(cConf);
java.nio.file.Path previewDirPath = Paths.get(cConf.get(Constants.CFG_LOCAL_DATA_DIR), "preview").toAbsolutePath();
Files.createDirectories(previewDirPath);
java.nio.file.Path previewDir = Files.createDirectories(Paths.get(previewDirPath.toAbsolutePath().toString(), applicationId.getApplication()));
previewCConf.set(Constants.CFG_LOCAL_DATA_DIR, previewDir.toString());
Configuration previewHConf = new Configuration(hConf);
previewHConf.set(Constants.CFG_LOCAL_DATA_DIR, previewDir.toString());
previewCConf.setIfUnset(Constants.CFG_DATA_LEVELDB_DIR, previewDir.toString());
previewCConf.setBoolean(Constants.Explore.EXPLORE_ENABLED, false);
return Guice.createInjector(new ConfigModule(previewCConf, previewHConf), new IOModule(), new AuthenticationContextModules().getMasterModule(), new SecurityModules().getStandaloneModules(), new PreviewSecureStoreModule(secureStore), new PreviewStreamAdminModule(streamAdmin), new PreviewDiscoveryRuntimeModule(discoveryService), new LocationRuntimeModule().getStandaloneModules(), new ConfigStoreModule().getStandaloneModule(), new PreviewRunnerModule(artifactRepository, artifactStore, authorizerInstantiator, authorizationEnforcer, privilegesManager, streamCoordinatorClient, preferencesStore), new ProgramRunnerRuntimeModule().getStandaloneModules(), new PreviewDataModules().getDataFabricModule(transactionManager), new PreviewDataModules().getDataSetsModule(datasetFramework), new DataSetServiceModules().getStandaloneModules(), new MetricsClientRuntimeModule().getStandaloneModules(), new LoggingModules().getStandaloneModules(), new NamespaceStoreModule().getStandaloneModules(), new MessagingServerRuntimeModule().getInMemoryModules(), new AbstractModule() {
@Override
protected void configure() {
// Bind system datasets defined in App-fabric.
// Have to do it here as public binding, instead of inside PreviewRunnerModule due to Guice 3
// doesn't support exporting multi-binder from private module
MapBinder<String, DatasetModule> datasetModuleBinder = MapBinder.newMapBinder(binder(), String.class, DatasetModule.class, Constants.Dataset.Manager.DefaultDatasetModules.class);
datasetModuleBinder.addBinding("app-fabric").toInstance(new AppFabricDatasetModule());
}
@Provides
@Named(Constants.Service.MASTER_SERVICES_BIND_ADDRESS)
@SuppressWarnings("unused")
public InetAddress providesHostname(CConfiguration cConf) {
String address = cConf.get(Constants.Preview.ADDRESS);
return Networks.resolve(address, new InetSocketAddress("localhost", 0).getAddress());
}
});
}
use of com.google.inject.Provides in project graphhopper by graphhopper.
the class GraphHopperServletModule method createObjectMapper.
@Provides
@Singleton
ObjectMapper createObjectMapper() {
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.setDateFormat(new ISO8601DateFormat());
objectMapper.registerModule(new JtsModule());
SimpleModule pathDetailModule = new SimpleModule();
pathDetailModule.addSerializer(PathDetail.class, new PathDetailSerializer());
pathDetailModule.addDeserializer(PathDetail.class, new PathDetailDeserializer());
objectMapper.registerModule(pathDetailModule);
// Because VirtualEdgeIteratorState has getters which throw Exceptions.
// http://stackoverflow.com/questions/35359430/how-to-make-jackson-ignore-properties-if-the-getters-throw-exceptions
objectMapper.registerModule(new SimpleModule().setSerializerModifier(new BeanSerializerModifier() {
@Override
public List<BeanPropertyWriter> changeProperties(SerializationConfig config, BeanDescription beanDesc, List<BeanPropertyWriter> beanProperties) {
return beanProperties.stream().map(bpw -> new BeanPropertyWriter(bpw) {
@Override
public void serializeAsField(Object bean, JsonGenerator gen, SerializerProvider prov) throws Exception {
try {
super.serializeAsField(bean, gen, prov);
} catch (Exception e) {
// Ignoring expected exception, see above.
}
}
}).collect(Collectors.toList());
}
}));
return objectMapper;
}
use of com.google.inject.Provides in project druid by druid-io.
the class SpnegoFilterConfigTest method testserde.
@Test
public void testserde() {
Injector injector = Guice.createInjector(new Module() {
@Override
public void configure(Binder binder) {
binder.install(new PropertiesModule(Arrays.asList("test.runtime.properties")));
binder.install(new ConfigModule());
binder.install(new DruidGuiceExtensions());
JsonConfigProvider.bind(binder, "druid.hadoop.security.spnego", SpnegoFilterConfig.class);
}
@Provides
@LazySingleton
public ObjectMapper jsonMapper() {
return new DefaultObjectMapper();
}
});
Properties props = injector.getInstance(Properties.class);
SpnegoFilterConfig config = injector.getInstance(SpnegoFilterConfig.class);
Assert.assertEquals(props.getProperty("druid.hadoop.security.spnego.principal"), config.getPrincipal());
Assert.assertEquals(props.getProperty("druid.hadoop.security.spnego.keytab"), config.getKeytab());
Assert.assertEquals(props.getProperty("druid.hadoop.security.spnego.authToLocal"), config.getAuthToLocal());
}
use of com.google.inject.Provides in project druid by druid-io.
the class EmitterModule method getServiceEmitter.
@Provides
@ManageLifecycle
public ServiceEmitter getServiceEmitter(@Self Supplier<DruidNode> configSupplier, Emitter emitter) {
final DruidNode config = configSupplier.get();
String version = getClass().getPackage().getImplementationVersion();
final ImmutableMap<String, String> otherServiceDimensions = ImmutableMap.of("version", // Version is null during `mvn test`.
Strings.nullToEmpty(version));
final ServiceEmitter retVal = new ServiceEmitter(config.getServiceName(), config.getHostAndPort(), emitter, otherServiceDimensions);
EmittingLogger.registerEmitter(retVal);
return retVal;
}
Aggregations