use of com.google.inject.Singleton in project incubator-myriad by apache.
the class MyriadModule method providesSchedulerState.
@Provides
@Singleton
SchedulerState providesSchedulerState(MyriadConfiguration cfg) {
LOGGER.debug("Configuring SchedulerState provider");
MyriadStateStore myriadStateStore = null;
if (cfg.isHAEnabled()) {
myriadStateStore = providesMyriadStateStore();
if (myriadStateStore == null) {
throw new RuntimeException("Could not find a state store" + " implementation for Myriad. The 'yarn.resourcemanager.store.class'" + " property should be set to a class implementing the" + " MyriadStateStore interface. For e.g." + " org.apache.hadoop.yarn.server.resourcemanager.recovery.MyriadFileSystemRMStateStore");
}
}
return new SchedulerState(myriadStateStore);
}
use of com.google.inject.Singleton in project apollo by spotify.
the class MetricsModule method fastForwardReporter.
@Provides
@Singleton
public FastForwardReporter fastForwardReporter(SemanticMetricRegistry metricRegistry, MetricId metricId, FfwdConfig ffwdConfig) {
try {
final FastForwardReporter.Builder builder = FastForwardReporter.forRegistry(metricRegistry).schedule(TimeUnit.SECONDS, ffwdConfig.getInterval()).prefix(metricId);
ffwdConfig.host().ifPresent(builder::host);
ffwdConfig.port().ifPresent(builder::port);
final FastForwardReporter reporter = builder.build();
reporter.start();
return reporter;
} catch (IOException e) {
throw new IllegalStateException("Failed to start ffwd reporter", e);
}
}
use of com.google.inject.Singleton in project presto by prestodb.
the class OracleClientModule method connectionFactory.
@Provides
@Singleton
public static ConnectionFactory connectionFactory(BaseJdbcConfig config, OracleConfig oracleConfig) throws SQLException {
Properties connectionProperties = new Properties();
connectionProperties.setProperty(OracleConnection.CONNECTION_PROPERTY_INCLUDE_SYNONYMS, String.valueOf(oracleConfig.isSynonymsEnabled()));
return new DriverConnectionFactory(new OracleDriver(), config.getConnectionUrl(), Optional.empty(), Optional.empty(), connectionProperties);
}
use of com.google.inject.Singleton in project ninja by ninjaframework.
the class LifecycleSupportTest method providedSingletonDisposableShouldBeDisposed.
@Test
public void providedSingletonDisposableShouldBeDisposed() {
Injector injector = createInjector(new AbstractModule() {
@Override
protected void configure() {
}
@Provides
@Singleton
public MockSingletonService provide() {
return new MockSingletonService();
}
});
start(injector);
stop(injector);
assertThat(MockSingletonService.disposed, equalTo(1));
}
use of com.google.inject.Singleton in project gerrit by GerritCodeReview.
the class ParameterParser method parse.
/**
* Parses query parameters ({@code in}) into annotated option fields of {@code param}.
*
* @return true if parsing was successful. Requesting help is considered failure and returns
* false.
*/
<T> boolean parse(T param, DynamicOptions pluginOptions, ListMultimap<String, String> in, HttpServletRequest req, HttpServletResponse res) throws IOException {
if (param.getClass().getAnnotation(Singleton.class) != null) {
// Command-line parsing mutates the object, so we can't have options on @Singleton.
return true;
}
CmdLineParser clp = parserFactory.create(param);
pluginOptions.setBean(param);
pluginOptions.startLifecycleListeners();
pluginOptions.parseDynamicBeans(clp);
pluginOptions.setDynamicBeans();
pluginOptions.onBeanParseStart();
try {
clp.parseOptionMap(in);
} catch (CmdLineException | NumberFormatException e) {
if (!clp.wasHelpRequestedByOption()) {
replyError(req, res, SC_BAD_REQUEST, e.getMessage(), e);
return false;
}
}
if (clp.wasHelpRequestedByOption()) {
StringWriter msg = new StringWriter();
clp.printQueryStringUsage(req.getRequestURI(), msg);
msg.write('\n');
msg.write('\n');
clp.printUsage(msg, null);
msg.write('\n');
CacheHeaders.setNotCacheable(res);
replyBinaryResult(req, res, BinaryResult.create(msg.toString()).setContentType("text/plain"));
return false;
}
pluginOptions.onBeanParseEnd();
return true;
}
Aggregations