Search in sources :

Example 36 with Singleton

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);
}
Also used : MyriadStateStore(org.apache.myriad.state.MyriadStateStore) SchedulerState(org.apache.myriad.state.SchedulerState) Singleton(com.google.inject.Singleton) Provides(com.google.inject.Provides)

Example 37 with Singleton

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);
    }
}
Also used : FastForwardReporter(com.spotify.metrics.ffwd.FastForwardReporter) IOException(java.io.IOException) Singleton(com.google.inject.Singleton) Provides(com.google.inject.Provides)

Example 38 with Singleton

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);
}
Also used : DriverConnectionFactory(com.facebook.presto.plugin.jdbc.DriverConnectionFactory) Properties(java.util.Properties) OracleDriver(oracle.jdbc.OracleDriver) Singleton(com.google.inject.Singleton) Provides(com.google.inject.Provides)

Example 39 with Singleton

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));
}
Also used : Injector(com.google.inject.Injector) Singleton(com.google.inject.Singleton) Provides(com.google.inject.Provides) AbstractModule(com.google.inject.AbstractModule) Test(org.junit.Test)

Example 40 with Singleton

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;
}
Also used : CmdLineParser(com.google.gerrit.util.cli.CmdLineParser) StringWriter(java.io.StringWriter) Singleton(com.google.inject.Singleton) CmdLineException(org.kohsuke.args4j.CmdLineException)

Aggregations

Singleton (com.google.inject.Singleton)80 Provides (com.google.inject.Provides)77 AbstractModule (com.google.inject.AbstractModule)8 Injector (com.google.inject.Injector)8 Named (com.google.inject.name.Named)7 UICommand (org.ovirt.engine.ui.uicommonweb.UICommand)7 ConfirmationModel (org.ovirt.engine.ui.uicommonweb.models.ConfirmationModel)7 Model (org.ovirt.engine.ui.uicommonweb.models.Model)7 IOException (java.io.IOException)5 SearchableDetailTabModelProvider (org.ovirt.engine.ui.common.uicommon.model.SearchableDetailTabModelProvider)5 PermissionListModel (org.ovirt.engine.ui.uicommonweb.models.configure.PermissionListModel)5 DataSourceFactory (io.dropwizard.db.DataSourceFactory)4 ManagedDataSource (io.dropwizard.db.ManagedDataSource)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 File (java.io.File)3 InetSocketAddress (java.net.InetSocketAddress)3 SocketAddress (java.net.SocketAddress)3 Properties (java.util.Properties)3 Test (org.junit.Test)3 ConfigModule (co.cask.cdap.common.guice.ConfigModule)2