Search in sources :

Example 1 with ServicePropertiesModule

use of com.peterphi.std.guice.common.serviceprops.ServicePropertiesModule in project stdlib by petergeneric.

the class CoreGuiceRole method register.

@Override
public void register(final Stage stage, final ClassScannerFactory scanner, final GuiceConfig config, final GuiceSetup setup, final List<Module> modules, final AtomicReference<Injector> injectorRef, final MetricRegistry metrics) {
    modules.add(new ServicePropertiesModule(config));
    modules.add(new ConfigurationPropertyRegistryModule(config, injectorRef));
    modules.add(new GuiceLifecycleModule());
    modules.add(new CoreMetricsModule(metrics));
    modules.add(new CacheModule(metrics));
    modules.add(new RetryModule(metrics));
    modules.add(new JAXBModule(config));
    modules.add(new Log4JModule(config, metrics));
}
Also used : CoreMetricsModule(com.peterphi.std.guice.common.metrics.CoreMetricsModule) RetryModule(com.peterphi.std.guice.common.retry.module.RetryModule) JAXBModule(com.peterphi.std.guice.common.JAXBModule) ConfigurationPropertyRegistryModule(com.peterphi.std.guice.common.serviceprops.ConfigurationPropertyRegistryModule) GuiceLifecycleModule(com.peterphi.std.guice.common.lifecycle.GuiceLifecycleModule) ServicePropertiesModule(com.peterphi.std.guice.common.serviceprops.ServicePropertiesModule) Log4JModule(com.peterphi.std.guice.common.logging.Log4JModule) CacheModule(com.peterphi.std.guice.common.cached.module.CacheModule)

Example 2 with ServicePropertiesModule

use of com.peterphi.std.guice.common.serviceprops.ServicePropertiesModule in project stdlib by petergeneric.

the class TimeoutConverterTest method test.

@Test
public void test() {
    PropertyFile props = new PropertyFile();
    props.set("timeout1msNoUnit", "1");
    props.set("timeout1ms", "1ms");
    props.set("timeout1s", "1s");
    props.set("timeout1h", "1h");
    props.set("timeout60m", "60m");
    props.set("timeout50h", "50h");
    final Injector injector = Guice.createInjector(new ServicePropertiesModule(props));
    injector.injectMembers(this);
    // extract values
    assertEquals(new Timeout(1, TimeUnit.MILLISECONDS), timeout1msNoUnit);
    assertEquals(new Timeout(1, TimeUnit.MILLISECONDS), timeout1ms);
    assertEquals(new Timeout(1, TimeUnit.SECONDS), timeout1s);
    assertEquals(new Timeout(60, TimeUnit.MINUTES), timeout60m);
    assertEquals(new Timeout(1, TimeUnit.HOURS), timeout1h);
    // compare against one another
    assertEquals(timeout60m, timeout1h);
    assertEquals(timeout1msNoUnit, timeout1ms);
    assertFalse(timeout50h.equals(timeout1h));
}
Also used : ServicePropertiesModule(com.peterphi.std.guice.common.serviceprops.ServicePropertiesModule) Injector(com.google.inject.Injector) Timeout(com.peterphi.std.threading.Timeout) PropertyFile(com.peterphi.std.io.PropertyFile) Test(org.junit.Test)

Aggregations

ServicePropertiesModule (com.peterphi.std.guice.common.serviceprops.ServicePropertiesModule)2 Injector (com.google.inject.Injector)1 JAXBModule (com.peterphi.std.guice.common.JAXBModule)1 CacheModule (com.peterphi.std.guice.common.cached.module.CacheModule)1 GuiceLifecycleModule (com.peterphi.std.guice.common.lifecycle.GuiceLifecycleModule)1 Log4JModule (com.peterphi.std.guice.common.logging.Log4JModule)1 CoreMetricsModule (com.peterphi.std.guice.common.metrics.CoreMetricsModule)1 RetryModule (com.peterphi.std.guice.common.retry.module.RetryModule)1 ConfigurationPropertyRegistryModule (com.peterphi.std.guice.common.serviceprops.ConfigurationPropertyRegistryModule)1 PropertyFile (com.peterphi.std.io.PropertyFile)1 Timeout (com.peterphi.std.threading.Timeout)1 Test (org.junit.Test)1