com.netflix.governator.guice.BootstrapBinder Java Examples
The following examples show how to use
com.netflix.governator.guice.BootstrapBinder.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Bootstrap.java From arcusplatform with Apache License 2.0 | 6 votes |
public Injector bootstrap() { try { // Construct the injector LifecycleInjectorBuilder builder = LifecycleInjector.builder() .withBootstrapModule(new BootstrapModule() { @Override public void configure(@Nullable BootstrapBinder binder) { Preconditions.checkNotNull(binder); binder.bindConfigurationProvider().to(AgentConfigurationProvider.class); } }) .withAdditionalBootstrapModules(boostrapModules); builder.withAdditionalModuleClasses(moduleClasses); if(!modules.isEmpty()) { builder.withAdditionalModules(modules); } LifecycleInjector inj = builder.build(); Injector result = inj.createInjector(); LifeCycleService.setState(LifeCycle.STARTING_UP, LifeCycle.STARTED); return result; } catch(Exception ex) { throw new BootException("error bootstrapping", ex); } }
Example #2
Source File: SuroClient.java From suro with Apache License 2.0 | 6 votes |
private Injector createInjector(final Properties properties) { injector = LifecycleInjector .builder() .withBootstrapModule( new BootstrapModule() { @Override public void configure(BootstrapBinder binder) { binder.bindConfigurationProvider().toInstance( new PropertiesConfigurationProvider(properties)); } } ) .withModules(new SuroClientModule()) .build().createInjector(); LifecycleManager manager = injector.getInstance(LifecycleManager.class); try { manager.start(); } catch (Exception e) { throw new RuntimeException("LifecycleManager cannot start with an exception: " + e.getMessage(), e); } return injector; }
Example #3
Source File: TestSyncSuroClient.java From suro with Apache License 2.0 | 6 votes |
@Before public void setup() throws Exception { servers = TestConnectionPool.startServers(3); final Properties props = new Properties(); props.setProperty(ClientConfig.LB_SERVER, TestConnectionPool.createConnectionString(servers)); props.setProperty(ClientConfig.MINIMUM_RECONNECT_TIME_INTERVAL, "1"); props.setProperty(ClientConfig.RECONNECT_INTERVAL, "1"); props.setProperty(ClientConfig.RECONNECT_TIME_INTERVAL, "1"); props.setProperty(ClientConfig.APP, "app"); injector = LifecycleInjector.builder() .withBootstrapModule(new BootstrapModule() { @Override public void configure(BootstrapBinder binder) { binder.bindConfigurationProvider().toInstance(new PropertiesConfigurationProvider(props)); binder.bind(ILoadBalancer.class).to(StaticLoadBalancer.class); } }).build().createInjector(); injector.getInstance(LifecycleManager.class).start(); }
Example #4
Source File: TestAsyncSuroSender.java From suro with Apache License 2.0 | 6 votes |
@Before public void setup() throws Exception { servers = TestConnectionPool.startServers(3); final Properties props = new Properties(); props.setProperty(ClientConfig.LB_SERVER, TestConnectionPool.createConnectionString(servers)); props.setProperty(ClientConfig.MINIMUM_RECONNECT_TIME_INTERVAL, "1"); props.setProperty(ClientConfig.RECONNECT_INTERVAL, "1"); props.setProperty(ClientConfig.RECONNECT_TIME_INTERVAL, "1"); props.setProperty(ClientConfig.APP, "app"); injector = LifecycleInjector.builder() .withBootstrapModule(new BootstrapModule() { @Override public void configure(BootstrapBinder binder) { binder.bindConfigurationProvider().toInstance(new PropertiesConfigurationProvider(props)); binder.bind(ILoadBalancer.class).to(StaticLoadBalancer.class); } }).build().createInjector(); injector.getInstance(LifecycleManager.class).start(); }
Example #5
Source File: TestAsyncSuroClientWithNonExistentFilePath.java From suro with Apache License 2.0 | 6 votes |
private void setupFile(final Properties props, String filePath) throws Exception { servers = TestConnectionPool.startServers(3); props.put(ClientConfig.LB_SERVER, TestConnectionPool.createConnectionString(servers)); props.put(ClientConfig.ASYNC_FILEQUEUE_PATH, filePath); props.put(ClientConfig.ASYNC_QUEUE_TYPE, "file"); injector = LifecycleInjector.builder() .withBootstrapModule(new BootstrapModule() { @Override public void configure(BootstrapBinder binder) { binder.bindConfigurationProvider().toInstance(new PropertiesConfigurationProvider(props)); binder.bind(ILoadBalancer.class).to(StaticLoadBalancer.class); } }).build().createInjector(); injector.getInstance(LifecycleManager.class).start(); }
Example #6
Source File: IrisApplicationModule.java From arcusplatform with Apache License 2.0 | 6 votes |
@Override public void configure(BootstrapBinder binder) { init(); bindIfNotInEnvironmentProperty(binder, NAME_APPLICATION_NAME, getApplicationName()); bindIfNotInEnvironmentProperty(binder, NAME_APPLICATION_VERSION, getApplicationVersion()); bindIfNotInEnvironmentProperty(binder, NAME_APPLICATION_DIR, getApplicationDirectory()); IrisApplicationInfo.setApplicationName(getApplicationName()); IrisApplicationInfo.setApplicationVersion(getApplicationVersion()); IrisApplicationInfo.setApplicationDirectory(getApplicationDirectory()); FileSystemResourceFactory fs = new FileSystemResourceFactory(getApplicationDirectory()); Resources.registerDefaultFactory(fs); Resources.registerFactory(fs); Resources.registerFactory(new ClassPathResourceFactory()); Resources.registerFactory(new EnvironmentVariableResourceFactory()); registerAzureResourceFactory(binder); }
Example #7
Source File: TestConnectionOutPool.java From suro with Apache License 2.0 | 6 votes |
public void setup() throws Exception { servers = TestConnectionPool.startServers(1); props.put(ClientConfig.LB_SERVER, TestConnectionPool.createConnectionString(servers)); props.put(ClientConfig.CONNECTION_TIMEOUT, Integer.toString(Integer.MAX_VALUE)); injector = LifecycleInjector.builder() .withBootstrapModule(new BootstrapModule() { @Override public void configure(BootstrapBinder binder) { binder.bindConfigurationProvider().toInstance(new PropertiesConfigurationProvider(props)); } }) .withAdditionalModules(new AbstractModule() { @Override protected void configure() { bind(ILoadBalancer.class).to(StaticLoadBalancer.class); } }) .build().createInjector(); injector.getInstance(LifecycleManager.class).start(); pool = injector.getInstance(ConnectionPool.class); assertEquals(pool.getPoolSize(), 1); }
Example #8
Source File: SuroServer.java From suro with Apache License 2.0 | 6 votes |
public static void create(AtomicReference<Injector> injector, final Properties properties, Module... modules) throws Exception { // Create the injector injector.set(LifecycleInjector.builder() .withBootstrapModule( new BootstrapModule() { @Override public void configure(BootstrapBinder binder) { binder.bindConfigurationProvider().toInstance( new PropertiesConfigurationProvider(properties)); } } ) .withModules( new RoutingPlugin(), new ServerSinkPlugin(), new SuroInputPlugin(), new SuroDynamicPropertyModule(), new SuroModule(), StatusServer.createJerseyServletModule() ) .withAdditionalModules(modules) .build().createInjector()); }
Example #9
Source File: TestAsyncSuroClient.java From suro with Apache License 2.0 | 5 votes |
private void setupFile(final Properties props) throws Exception { props.put(ClientConfig.LB_SERVER, TestConnectionPool.createConnectionString(servers)); props.put(ClientConfig.ASYNC_FILEQUEUE_PATH, tempDir.newFolder().getAbsolutePath()); props.put(ClientConfig.ASYNC_QUEUE_TYPE, "file"); injector = LifecycleInjector.builder() .withBootstrapModule(new BootstrapModule() { @Override public void configure(BootstrapBinder binder) { binder.bindConfigurationProvider().toInstance(new PropertiesConfigurationProvider(props)); binder.bind(ILoadBalancer.class).to(StaticLoadBalancer.class); } }).build().createInjector(); injector.getInstance(LifecycleManager.class).start(); }
Example #10
Source File: Karyon.java From karyon with Apache License 2.0 | 5 votes |
public static BootstrapModule toBootstrapModule(final Class<? extends Module> moduleClass) { if (null == moduleClass) { return null; } return new BootstrapModule() { @Override public void configure(BootstrapBinder binder) { binder.include(moduleClass); } }; }
Example #11
Source File: Karyon.java From karyon with Apache License 2.0 | 5 votes |
@SafeVarargs public static BootstrapModule toBootstrapModule(final Class<? extends Module>... moduleClasses) { if (null == moduleClasses) { return null; } return new BootstrapModule() { @Override public void configure(BootstrapBinder binder) { binder.include(Lists.newArrayList(moduleClasses)); } }; }
Example #12
Source File: Karyon.java From karyon with Apache License 2.0 | 5 votes |
public static BootstrapModule toBootstrapModule(final Module... modules) { if (null == modules) { return null; } return new BootstrapModule() { @Override public void configure(BootstrapBinder binder) { binder.includeModules(modules); } }; }
Example #13
Source File: ArchaiusBootstrapModule.java From karyon with Apache License 2.0 | 5 votes |
@Override public void configure(BootstrapBinder bootstrapBinder) { if (null != propertiesLoaderClass) { bootstrapBinder.bind(PropertiesLoader.class).to(propertiesLoaderClass).asEagerSingleton(); } else { bootstrapBinder.bind(PropertiesLoader.class).toInstance(propertiesLoader); } bootstrapBinder.bind(PropertiesInitializer.class).asEagerSingleton(); ArchaiusConfigurationProvider.Builder builder = ArchaiusConfigurationProvider.builder(); builder.withOwnershipPolicy(ConfigurationOwnershipPolicies.ownsAll()); bootstrapBinder.bindConfigurationProvider().toInstance(builder.build()); }
Example #14
Source File: TestMessageSetProcessor.java From suro with Apache License 2.0 | 5 votes |
private void testQueue(final Properties props) throws Exception { injector = LifecycleInjector.builder() .withBootstrapModule(new BootstrapModule() { @Override public void configure(BootstrapBinder binder) { binder.bindConfigurationProvider().toInstance(new PropertiesConfigurationProvider(props)); } }).build().createInjector(); injector.getInstance(LifecycleManager.class).start(); MessageSetProcessor queue = injector.getInstance(MessageSetProcessor.class); assertEquals(queue.getQueueSize(), 0); assertEquals(queue.getStatus(), ServiceStatus.ALIVE); TMessageSet messageSet = TestConnectionPool.createMessageSet(100); assertEquals(queue.process(messageSet).getResultCode(), ResultCode.OK); assertEquals(queue.getQueueSize(), 1); assertEquals(queue.poll(1, TimeUnit.MILLISECONDS), messageSet); assertEquals(queue.getQueueSize(), 0); queue.stopTakingTraffic(); assertEquals(queue.process(messageSet).getResultCode(), ResultCode.OTHER_ERROR); queue.startTakingTraffic(); assertEquals(queue.getStatus(), ServiceStatus.ALIVE); assertEquals(queue.process(messageSet).getResultCode(), ResultCode.OK); injector.getInstance(LifecycleManager.class).close(); }
Example #15
Source File: TestConnectionPool.java From suro with Apache License 2.0 | 5 votes |
private void createInjector() throws Exception { props.put(ClientConfig.LB_SERVER, createConnectionString(servers)); injector = LifecycleInjector.builder() .withBootstrapModule(new BootstrapModule() { @Override public void configure(BootstrapBinder binder) { binder.bindConfigurationProvider().toInstance(new PropertiesConfigurationProvider(props)); binder.bind(ILoadBalancer.class).to(StaticLoadBalancer.class); } }).build().createInjector(); injector.getInstance(LifecycleManager.class).start(); }
Example #16
Source File: TestAsyncSuroClient.java From suro with Apache License 2.0 | 5 votes |
private void setupMemory(final Properties props) throws Exception { injector = LifecycleInjector.builder() .withBootstrapModule(new BootstrapModule() { @Override public void configure(BootstrapBinder binder) { binder.bindConfigurationProvider().toInstance(new PropertiesConfigurationProvider(props)); binder.bind(ILoadBalancer.class).to(StaticLoadBalancer.class); } }).build().createInjector(); injector.getInstance(LifecycleManager.class).start(); }
Example #17
Source File: Bootstrap.java From arcusplatform with Apache License 2.0 | 5 votes |
public Injector bootstrap() throws BootstrapException { try { final Properties merged = mergeProperties(); LifecycleInjectorBuilder builder = LifecycleInjector.builder() .withBootstrapModule(new BootstrapModule() { @Override public void configure(BootstrapBinder binder) { Names.bindProperties(binder, merged); binder.bindConfigurationProvider().toInstance(new PropertiesConfigurationProvider(merged)); } }) .withAdditionalBootstrapModules(boostrapModules); if(merged.containsKey(PROP_MODULES)) { String [] classnames = StringUtils.split(merged.getProperty(PROP_MODULES)); Set<Class<? extends Module>> modules = classnamesToClasses(Arrays.asList(classnames)); modules.addAll(moduleClasses); builder.withAdditionalModuleClasses(modules); } else if(!moduleClasses.isEmpty()) { builder.withAdditionalModuleClasses(moduleClasses); } if(!modules.isEmpty()) { builder.withAdditionalModules(modules); } return builder.build().createInjector(); } catch(Exception e) { throw new BootstrapException("Error bootstrapping the injection context", e); } }
Example #18
Source File: IrisApplicationModule.java From arcusplatform with Apache License 2.0 | 5 votes |
private void bindIfNotInEnvironmentProperty(BootstrapBinder binder, String prop, String value){ String envProp = System.getProperty(prop); if(envProp==null){ binder .bind(Key.get(String.class, Names.named(prop))) .toInstance(value); } else{ logger.info("Found property {} in system properties. It will be bound with this value {}", prop, envProp); } }
Example #19
Source File: IrisApplicationModule.java From arcusplatform with Apache License 2.0 | 5 votes |
private void registerAzureResourceFactory(BootstrapBinder binder) { try { AzureResourceModule azureResourceModule = new AzureResourceModule(); binder.requestInjection(azureResourceModule); binder.install(azureResourceModule); }catch(Exception e) { logger.warn("Unable to register AzureResourceFactory with Resources", e); } }
Example #20
Source File: TestInputManager.java From suro with Apache License 2.0 | 4 votes |
@Test public void test() throws Exception { int statusPort = TestUtils.pickPort(); int serverPort = TestUtils.pickPort(); final Properties props = new Properties(); props.put("SuroServer.statusServerPort", Integer.toString(statusPort)); props.put("SuroServer.port", Integer.toString(serverPort)); Injector injector = LifecycleInjector.builder().withBootstrapModule(new BootstrapModule() { @Override public void configure(BootstrapBinder binder) { binder.bindConfigurationProvider().toInstance(new PropertiesConfigurationProvider(props)); } }).withModules( new SuroInputPlugin(), new AbstractModule() { @Override protected void configure() { bind(ObjectMapper.class).to(DefaultObjectMapper.class); } } ).build().createInjector(); LifecycleManager lifecycleManager = injector.getInstance(LifecycleManager.class); lifecycleManager.start(); InputManager inputManager = new InputManager(); List<SuroInput> inputList = injector.getInstance(ObjectMapper.class).readValue( inputConfig, new TypeReference<List<SuroInput>>() { }); inputManager.set(inputList); assertNotNull(inputManager.getInput("thrift")); assertNotNull(inputManager.getInput("kafka_topic-kafka1")); inputList = injector.getInstance(ObjectMapper.class).readValue( addInputConfig, new TypeReference<List<SuroInput>>() { }); inputManager.set(inputList); assertNotNull(inputManager.getInput("thrift")); assertNotNull(inputManager.getInput("kafka_topic-kafka1")); assertNotNull(inputManager.getInput("kafka_topic-kafka2")); inputList = injector.getInstance(ObjectMapper.class).readValue( inputConfig, new TypeReference<List<SuroInput>>() { }); inputManager.set(inputList); assertNotNull(inputManager.getInput("thrift")); assertNotNull(inputManager.getInput("kafka_topic-kafka1")); }