下面列出了android.appwidget.AppWidgetProvider#javax.inject.Singleton 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
protected void configure() {
bind(ShutdownHooks.class).asEagerSingleton();
bind(PersistenceStartup.class).asEagerSingleton();
bind(PersistenceStartupShutdownHookInstaller.class).asEagerSingleton();
if (persistenceConfigurationService.getMode() == PersistenceConfigurationService.PersistenceMode.FILE) {
install(new PersistenceMigrationFileModule());
} else {
install(new LocalPersistenceMemoryModule(null));
}
bind(PublishPayloadPersistence.class).to(PublishPayloadPersistenceImpl.class).in(Singleton.class);
bind(MetricRegistry.class).toInstance(metricRegistry);
bind(MetricsHolder.class).toProvider(MetricsHolderProvider.class).asEagerSingleton();
bind(ListeningScheduledExecutorService.class).annotatedWith(PayloadPersistence.class)
.toProvider(PayloadPersistenceScheduledExecutorProvider.class)
.in(LazySingleton.class);
bind(MessageDroppedService.class).toProvider(MessageDroppedServiceProvider.class).in(Singleton.class);
}
@Override
protected void configure() {
// Within this (private) module, there should only be a single tree panel.
bind(BlocksTreeViewPanel.class)
.in(Singleton.class);
// Bind the tree panel annotated with the given annotation to our single
// instance and expose only this annotated version.
bind(AbstractTreeViewPanel.class)
.to(BlocksTreeViewPanel.class);
expose(BlocksTreeViewPanel.class);
// Bind TreeView to the single tree panel, too.
bind(TreeView.class)
.to(BlocksTreeViewPanel.class);
// Bind and expose a single manager for the single tree view/panel.
bind(BlocksTreeViewManager.class)
.in(Singleton.class);
expose(BlocksTreeViewManager.class);
bind(MouseListener.class)
.to(BlockMouseListener.class);
}
@Singleton
@Named(MY_STREAM)
KStream<String, String> myStream(
@Named(MY_STREAM) ConfiguredStreamBuilder builder) {
// end::namedStream[]
// set default serdes
Properties props = builder.getConfiguration();
props.put(StreamsConfig.DEFAULT_KEY_SERDE_CLASS_CONFIG, Serdes.String().getClass().getName());
props.put(StreamsConfig.DEFAULT_VALUE_SERDE_CLASS_CONFIG, Serdes.String().getClass().getName());
props.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest");
KStream<String, String> source = builder.stream(NAMED_WORD_COUNT_INPUT);
KTable<String, Long> counts = source
.flatMapValues(value -> Arrays.asList(value.toLowerCase(Locale.getDefault()).split(" ")))
.groupBy((key, value) -> value)
.count();
// need to override value serde to Long type
counts.toStream().to(NAMED_WORD_COUNT_OUTPUT, Produced.with(Serdes.String(), Serdes.Long()));
return source;
}
@Singleton
@Provides
KuduClientSession createKuduClientSession(KuduClientConfig config)
{
requireNonNull(config, "config is null");
KuduClient.KuduClientBuilder builder = new KuduClient.KuduClientBuilder(config.getMasterAddresses());
builder.defaultAdminOperationTimeoutMs(config.getDefaultAdminOperationTimeout().toMillis());
builder.defaultOperationTimeoutMs(config.getDefaultOperationTimeout().toMillis());
builder.defaultSocketReadTimeoutMs(config.getDefaultSocketReadTimeout().toMillis());
if (config.isDisableStatistics()) {
builder.disableStatistics();
}
KuduClient client = builder.build();
SchemaEmulation strategy;
if (config.isSchemaEmulationEnabled()) {
strategy = new SchemaEmulationByTableNameConvention(config.getSchemaEmulationPrefix());
}
else {
strategy = new NoSchemaEmulation();
}
return new KuduClientSession(client, strategy);
}
private void bindLocalPersistence(
final @NotNull Class localPersistenceClass,
final @NotNull Class localPersistenceImplClass,
final @Nullable Class localPersistenceProviderClass) {
final Object instance = persistenceInjector.getInstance(localPersistenceImplClass);
if (instance != null) {
bind(localPersistenceImplClass).toInstance(instance);
bind(localPersistenceClass).toInstance(instance);
} else {
if (localPersistenceProviderClass != null) {
bind(localPersistenceClass).toProvider(localPersistenceProviderClass).in(Singleton.class);
} else {
bind(localPersistenceClass).to(localPersistenceImplClass).in(Singleton.class);
}
}
}
@SuppressWarnings("deprecation")
private void configureControlCenterDependencies() {
KernelControlCenterConfiguration configuration
= getConfigBindingProvider().get(KernelControlCenterConfiguration.PREFIX,
KernelControlCenterConfiguration.class);
bind(KernelControlCenterConfiguration.class).toInstance(configuration);
Multibinder<org.opentcs.components.kernel.ControlCenterPanel> modellingBinder
= controlCenterPanelBinderModelling();
// No extensions for modelling mode, yet.
Multibinder<org.opentcs.components.kernel.ControlCenterPanel> operatingBinder
= controlCenterPanelBinderOperating();
operatingBinder.addBinding().to(DriverGUI.class);
install(new FactoryModuleBuilder().build(ControlCenterInfoHandlerFactory.class));
bind(KernelControlCenter.class).in(Singleton.class);
}
@Singleton
@Named(STREAM_WORD_COUNT)
KStream<String, String> wordCountStream(ConfiguredStreamBuilder builder) { // <3>
// set default serdes
Properties props = builder.getConfiguration();
props.put(StreamsConfig.DEFAULT_KEY_SERDE_CLASS_CONFIG, Serdes.String().getClass().getName());
props.put(StreamsConfig.DEFAULT_VALUE_SERDE_CLASS_CONFIG, Serdes.String().getClass().getName());
props.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest");
KStream<String, String> source = builder
.stream(INPUT);
KTable<String, Long> groupedByWord = source
.flatMapValues(value -> Arrays.asList(value.toLowerCase().split("\\W+")))
.groupBy((key, word) -> word, Grouped.with(Serdes.String(), Serdes.String()))
//Store the result in a store for lookup later
.count(Materialized.as(WORD_COUNT_STORE)); // <4>
groupedByWord
//convert to stream
.toStream()
//send to output using specific serdes
.to(OUTPUT, Produced.with(Serdes.String(), Serdes.Long()));
return source;
}
/**
* The {@link StackdriverSender} bean.
* @param cloudConfiguration The google cloud configuration
* @param credentials The credentials
* @param channel The channel to use
* @return The sender
*/
@RequiresGoogleProjectId
@Requires(classes = StackdriverSender.class)
@Singleton
protected @Nonnull Sender stackdriverSender(
@Nonnull GoogleCloudConfiguration cloudConfiguration,
@Nonnull GoogleCredentials credentials,
@Nonnull @Named("stackdriverTraceSenderChannel") ManagedChannel channel) {
GoogleCredentials traceCredentials = credentials.createScoped(Arrays.asList(TRACE_SCOPE.toString()));
return StackdriverSender.newBuilder(channel)
.projectId(cloudConfiguration.getProjectId())
.callOptions(CallOptions.DEFAULT
.withCallCredentials(MoreCallCredentials.from(traceCredentials)))
.build();
}
/**
* @param environment The {@link Environment}
* @return An {@link AwsCredentialsProviderChain} that attempts to read the values from the Micronaut environment
* first, then delegates to {@link DefaultCredentialsProvider}.
*/
@Bean(preDestroy = "close")
@Singleton
public AwsCredentialsProviderChain awsCredentialsProvider(Environment environment) {
return AwsCredentialsProviderChain.of(
EnvironmentAwsCredentialsProvider.create(environment),
DefaultCredentialsProvider.create()
);
}
/**
* @return client A pool of connections.
*/
@Singleton
@Bean(preDestroy = "close")
public MySQLPool client() {
if (this.vertx == null) {
return createClient();
} else {
return createClient(vertx);
}
}
/**
* The server interceptor.
* @param configuration The configuration
* @return The server interceptor
*/
@Requires(beans = GrpcServerTracingInterceptorConfiguration.class)
@Singleton
@Bean
protected @Nonnull ServerInterceptor serverTracingInterceptor(@Nonnull GrpcServerTracingInterceptorConfiguration configuration) {
return configuration.getBuilder().build();
}
@Singleton
@Provides
ProtocolSchedule provideProtocolSchedule(
final GenesisConfigOptions configOptions,
@Named("RevertReasonEnabled") final boolean revertReasonEnabled) {
throw new RuntimeException("Abstract");
}
@Singleton
@Provides
HttpLoggingInterceptor providesHttpLoggingInterceptor() {
HttpLoggingInterceptor logging = new HttpLoggingInterceptor(new HttpLoggingInterceptor.Logger() {
@Override
public void log(@NonNull String message) {
Logger.t("OkHttp").d(message);
}
});
logging.setLevel(HttpLoggingInterceptor.Level.HEADERS);
return logging;
}
@Provides
@Singleton
@Named("worldState")
KeyValueStorage provideWorldStateKeyValueStorage(
@Named("KeyValueStorageName") final String keyValueStorageName,
final BesuConfiguration commonConfiguration,
final MetricsSystem metricsSystem) {
return constructKeyValueStorage(
keyValueStorageName,
commonConfiguration,
metricsSystem,
KeyValueSegmentIdentifier.WORLD_STATE);
}
/**
* The client returned from a builder.
* @return client object
*/
@Requires(beans = AWSLambdaConfiguration.class)
@Singleton
AWSLambdaAsync awsLambdaAsyncClient() {
AWSLambdaAsyncClientBuilder builder = configuration.getBuilder();
return builder.build();
}
@Provides
@Singleton
@ForEnvironment
public String getEnvironment(ResourceGroupConfigurationManagerContext context)
{
return context.getEnvironment();
}
@Provides
@Singleton
@ForExtraCredentialProvider
public CredentialProvider getCredentialProvider(ConfigFileBasedCredentialProviderConfig fileConfig)
throws IOException
{
Map<String, String> properties = loadPropertiesFrom(fileConfig.getCredentialFile());
CredentialConfig config = new ConfigurationFactory(properties).build(CredentialConfig.class);
return new StaticCredentialProvider(config.getConnectionUser(), config.getConnectionPassword());
}
@Provides
@Singleton
@ForExtraCredentialProvider
public CredentialProvider getCredentialProvider(KeyStoreBasedCredentialProviderConfig config)
throws IOException, GeneralSecurityException
{
KeyStore keyStore = loadKeyStore(config.getKeyStoreType(), config.getKeyStoreFilePath(), config.getKeyStorePassword());
String user = readEntity(keyStore, config.getUserCredentialName(), config.getPasswordForUserCredentialName());
String password = readEntity(keyStore, config.getPasswordCredentialName(), config.getPasswordForPasswordCredentialName());
return new StaticCredentialProvider(Optional.of(user), Optional.of(password));
}
@Singleton
@Named(STREAM_OPTIMIZATION_ON)
KStream<String, String> optimizationOn(
@Named(STREAM_OPTIMIZATION_ON) ConfiguredStreamBuilder builder) {
// set default serdes
Properties props = builder.getConfiguration();
props.put(StreamsConfig.DEFAULT_KEY_SERDE_CLASS_CONFIG, Serdes.String().getClass().getName());
props.put(StreamsConfig.DEFAULT_VALUE_SERDE_CLASS_CONFIG, Serdes.String().getClass().getName());
props.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest");
KTable<String, String> table = builder
.table(OPTIMIZATION_ON_INPUT, Materialized.as(OPTIMIZATION_ON_STORE));
return table.toStream();
}
@Provides
@Singleton
@ForStatementResource
public static BoundedExecutor createStatementResponseExecutor(@ForStatementResource ExecutorService coreExecutor, TaskManagerConfig config)
{
return new BoundedExecutor(coreExecutor, config.getHttpResponseThreads());
}
@Provides
@Singleton
@ForStatementResource
public static ScheduledExecutorService createStatementTimeoutExecutor(TaskManagerConfig config)
{
return newScheduledThreadPool(config.getHttpTimeoutThreads(), daemonThreadsNamed("statement-timeout-%s"));
}
/**
* @param configuration The Netty client configuration
* @return an instance of {@link SdkAsyncHttpClient}
*/
@Bean(preDestroy = "close")
@Singleton
@Requires(property = ASYNC_SERVICE_IMPL, value = NETTY_SDK_ASYNC_HTTP_SERVICE)
public SdkAsyncHttpClient systemPropertyClient(NettyClientConfiguration configuration) {
return doCreateClient(configuration);
}
/**
*
* @return An Skill using the {@link AlexaSkillBuilder} and the {@link SkillBuilderProvider} bean.
*/
@Singleton
public Skill createSkill() {
AlexaSkill alexaSkill = alexaSkillBuilder.buildSkill(skillBuilderProvider.getSkillBuilder(), null);
if (alexaSkill instanceof Skill) {
return (Skill) alexaSkill;
}
return null;
}
private void bindLocalPersistence(final @NotNull Class localPersistenceClass,
final @NotNull Class localPersistenceImplClass) {
final Object instance = injector == null ? null : injector.getInstance(localPersistenceImplClass);
if (instance != null) {
bind(localPersistenceImplClass).toInstance(instance);
bind(localPersistenceClass).toInstance(instance);
} else {
bind(localPersistenceClass).to(localPersistenceImplClass).in(Singleton.class);
}
}
@Provides
@Singleton
@ForAsyncHttp
public static ExecutorService createAsyncHttpResponseCoreExecutor()
{
return newCachedThreadPool(daemonThreadsNamed("async-http-response-%s"));
}
@Provides
@Singleton
@ForAsyncHttp
public static BoundedExecutor createAsyncHttpResponseExecutor(@ForAsyncHttp ExecutorService coreExecutor, TaskManagerConfig config)
{
return new BoundedExecutor(coreExecutor, config.getHttpResponseThreads());
}
/**
* A GRPC name resolver factory that integrates with Micronaut's discovery client.
* @param discoveryClient The discovery client
* @param serviceInstanceLists The service instance list
* @return The name resolver
*/
@Singleton
@Requires(beans = DiscoveryClient.class)
@Requires(property = ENABLED, value = StringUtils.TRUE, defaultValue = StringUtils.FALSE)
protected NameResolver.Factory nameResolverFactory(
DiscoveryClient discoveryClient,
List<ServiceInstanceList> serviceInstanceLists) {
return new GrpcNameResolverProvider(discoveryClient, serviceInstanceLists);
}
/**
* @return The executor configurations
*/
@Singleton
@Bean
@Named(TaskExecutors.MESSAGE_CONSUMER)
ExecutorConfiguration configuration() {
return UserExecutorConfiguration.of(ExecutorType.FIXED, 75);
}
@Override
@Bean(preDestroy = "close")
@Singleton
@Requires(beans = SdkAsyncHttpClient.class)
public SesAsyncClient asyncClient(SesAsyncClientBuilder builder) {
return super.asyncClient(builder);
}
@ForMetadata
@Singleton
@Provides
DataSource createDataSource(JdbcDatabaseConfig config, @ForMetadata MySqlDataSourceConfig mysqlConfig)
{
ServiceDescriptor descriptor = serviceDescriptor("mysql")
.addProperty("jdbc", config.getUrl())
.build();
return new MySqlDataSource(new StaticServiceSelector(descriptor), mysqlConfig);
}