Java Code Examples for org.springframework.beans.factory.ObjectProvider#getIfAvailable()

The following examples show how to use org.springframework.beans.factory.ObjectProvider#getIfAvailable() . 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: CachingServiceInstanceListSupplierTests.java    From spring-cloud-commons with Apache License 2.0 6 votes vote down vote up
@Bean
ServiceInstanceListSupplier supplier(ConfigurableApplicationContext context,
		ReactiveDiscoveryClient discoveryClient,
		LoadBalancerProperties loadBalancerProperties,
		WebClient.Builder webClientBuilder) {
	DiscoveryClientServiceInstanceListSupplier firstDelegate = new DiscoveryClientServiceInstanceListSupplier(
			discoveryClient, context.getEnvironment());
	HealthCheckServiceInstanceListSupplier delegate = new TestHealthCheckServiceInstanceListSupplier(
			firstDelegate, loadBalancerProperties.getHealthCheck(),
			webClientBuilder.build());
	delegate.afterPropertiesSet();
	ObjectProvider<LoadBalancerCacheManager> cacheManagerProvider = context
			.getBeanProvider(LoadBalancerCacheManager.class);
	return new CachingServiceInstanceListSupplier(delegate,
			cacheManagerProvider.getIfAvailable());
}
 
Example 2
Source File: GradleProjectGenerationConfiguration.java    From initializr with Apache License 2.0 5 votes vote down vote up
@Bean
@ConditionalOnGradleVersion({ "4", "5", "6" })
BuildCustomizer<GradleBuild> springBootPluginContributor(ProjectDescription description,
		ObjectProvider<DependencyManagementPluginVersionResolver> versionResolver, InitializrMetadata metadata) {
	return new SpringBootPluginBuildCustomizer(description, versionResolver
			.getIfAvailable(() -> new InitializrDependencyManagementPluginVersionResolver(metadata)));
}
 
Example 3
Source File: RedisHttpSessionConfiguration.java    From spring-session with Apache License 2.0 5 votes vote down vote up
@Autowired
public void setRedisConnectionFactory(
		@SpringSessionRedisConnectionFactory ObjectProvider<RedisConnectionFactory> springSessionRedisConnectionFactory,
		ObjectProvider<RedisConnectionFactory> redisConnectionFactory) {
	RedisConnectionFactory redisConnectionFactoryToUse = springSessionRedisConnectionFactory.getIfAvailable();
	if (redisConnectionFactoryToUse == null) {
		redisConnectionFactoryToUse = redisConnectionFactory.getObject();
	}
	this.redisConnectionFactory = redisConnectionFactoryToUse;
}
 
Example 4
Source File: ZookeeperAutoConfiguration.java    From spring-cloud-zookeeper with Apache License 2.0 5 votes vote down vote up
@Bean(destroyMethod = "close")
@ConditionalOnMissingBean
public CuratorFramework curatorFramework(RetryPolicy retryPolicy,
		ZookeeperProperties properties,
		ObjectProvider<CuratorFrameworkCustomizer> optionalCuratorFrameworkCustomizerProvider,
		ObjectProvider<EnsembleProvider> optionalEnsembleProvider,
		ObjectProvider<TracerDriver> optionalTracerDriverProvider) throws Exception {
	CuratorFrameworkFactory.Builder builder = CuratorFrameworkFactory.builder();

	EnsembleProvider ensembleProvider = optionalEnsembleProvider.getIfAvailable();
	if (ensembleProvider != null) {
		builder.ensembleProvider(ensembleProvider);
	}
	else {
		builder.connectString(properties.getConnectString());
	}
	builder.sessionTimeoutMs((int) properties.getSessionTimeout().toMillis())
			.connectionTimeoutMs((int) properties.getConnectionTimeout().toMillis())
			.retryPolicy(retryPolicy);

	optionalCuratorFrameworkCustomizerProvider.orderedStream()
			.forEach(curatorFrameworkCustomizer -> curatorFrameworkCustomizer
					.customize(builder));

	CuratorFramework curator = builder.build();
	optionalTracerDriverProvider.ifAvailable(tracerDriver -> {
		if (curator.getZookeeperClient() != null) {
			curator.getZookeeperClient().setTracerDriver(tracerDriver);
		}
	});

	curator.start();
	log.trace("blocking until connected to zookeeper for "
			+ properties.getBlockUntilConnectedWait()
			+ properties.getBlockUntilConnectedUnit());
	curator.blockUntilConnected(properties.getBlockUntilConnectedWait(),
			properties.getBlockUntilConnectedUnit());
	log.trace("connected to zookeeper");
	return curator;
}
 
Example 5
Source File: HazelcastHttpSessionConfiguration.java    From spring-session with Apache License 2.0 5 votes vote down vote up
@Autowired
public void setHazelcastInstance(
		@SpringSessionHazelcastInstance ObjectProvider<HazelcastInstance> springSessionHazelcastInstance,
		ObjectProvider<HazelcastInstance> hazelcastInstance) {
	HazelcastInstance hazelcastInstanceToUse = springSessionHazelcastInstance.getIfAvailable();
	if (hazelcastInstanceToUse == null) {
		hazelcastInstanceToUse = hazelcastInstance.getObject();
	}
	this.hazelcastInstance = hazelcastInstanceToUse;
}
 
Example 6
Source File: FlowableSecurityAutoConfiguration.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
public SpringSecurityAuthenticationContextConfiguration(ObjectProvider<AuthenticationContext> authenticationContext) {
    AuthenticationContext context = authenticationContext.getIfAvailable();
    if (context == null) {
        context = new SpringSecurityAuthenticationContext();
    }

    Authentication.setAuthenticationContext(context);
}
 
Example 7
Source File: DefaultUserInfoRestTemplateFactory.java    From spring-security-oauth2-boot with Apache License 2.0 5 votes vote down vote up
public DefaultUserInfoRestTemplateFactory(ObjectProvider<List<UserInfoRestTemplateCustomizer>> customizers,
		ObjectProvider<OAuth2ProtectedResourceDetails> details,
		ObjectProvider<OAuth2ClientContext> oauth2ClientContext) {
	this.customizers = customizers.getIfAvailable();
	this.details = details.getIfAvailable();
	this.oauth2ClientContext = oauth2ClientContext.getIfAvailable();
}
 
Example 8
Source File: ContractVerifierJmsConfiguration.java    From spring-cloud-contract with Apache License 2.0 5 votes vote down vote up
@Bean
@ConditionalOnMissingBean
MessageVerifier<Message> contractVerifierJmsMessageExchange(
		ObjectProvider<JmsTemplate> jmsTemplateProvider) {
	JmsTemplate jmsTemplate = jmsTemplateProvider.getIfAvailable(JmsTemplate::new);
	return new JmsStubMessages(jmsTemplate);
}
 
Example 9
Source File: ApiBootWebSecurityMemoryAutoConfiguration.java    From beihu-boot with Apache License 2.0 4 votes vote down vote up
public ApiBootWebSecurityMemoryAutoConfiguration(ApiBootSecurityProperties apiBootSecurityProperties, ObjectProvider<AccessDeniedHandler> accessDeniedHandler, ObjectProvider<AuthenticationEntryPoint> authenticationEntryPoint) {
    super(apiBootSecurityProperties, accessDeniedHandler.getIfAvailable(), authenticationEntryPoint.getIfAvailable());
}
 
Example 10
Source File: ApiBootResourceRedisLoadAutoConfiguration.java    From api-boot with Apache License 2.0 4 votes vote down vote up
public ApiBootResourceRedisLoadAutoConfiguration(ObjectProvider<ApiBootResourceStoreDelegate> resourceStoreDelegateObjectProvider) {
    this.resourceStoreDelegate = resourceStoreDelegateObjectProvider.getIfAvailable();
}
 
Example 11
Source File: EventPublicationConfiguration.java    From spring-domain-events with Apache License 2.0 4 votes vote down vote up
@Bean
PersistentApplicationEventMulticaster applicationEventMulticaster(ObjectProvider<EventPublicationRegistry> registry) {

	return new PersistentApplicationEventMulticaster(
			() -> registry.getIfAvailable(() -> new MapEventPublicationRegistry()));
}
 
Example 12
Source File: ApiBootResourceLoadAutoConfiguration.java    From api-boot with Apache License 2.0 4 votes vote down vote up
public ApiBootResourceLoadAutoConfiguration(ObjectProvider<ApiBootResourceStoreDelegate> resourceStoreDelegateObjectProvider) {
    this.resourceStoreDelegate = resourceStoreDelegateObjectProvider.getIfAvailable();
}
 
Example 13
Source File: TraceClientAutoConfigurer.java    From bird-java with MIT License 4 votes vote down vote up
public TraceClientAutoConfigurer(ApplicationContext applicationContext, ObjectProvider<List<ITraceLogCustomizer>> logCustomizersProvider) {
    this.applicationContext = applicationContext;
    this.logCustomizers = logCustomizersProvider.getIfAvailable();
}
 
Example 14
Source File: SentinelWebFluxAutoConfiguration.java    From spring-cloud-alibaba with Apache License 2.0 4 votes vote down vote up
public SentinelWebFluxAutoConfiguration(
		ObjectProvider<List<ViewResolver>> viewResolvers,
		ServerCodecConfigurer serverCodecConfigurer) {
	this.viewResolvers = viewResolvers.getIfAvailable(Collections::emptyList);
	this.serverCodecConfigurer = serverCodecConfigurer;
}
 
Example 15
Source File: MailSenderAutoConfiguration.java    From spring-cloud-aws with Apache License 2.0 4 votes vote down vote up
public MailSenderAutoConfiguration(ObjectProvider<RegionProvider> regionProvider) {
	this.regionProvider = regionProvider.getIfAvailable();
}
 
Example 16
Source File: ApiBootWebSecurityMemoryAutoConfiguration.java    From api-boot with Apache License 2.0 4 votes vote down vote up
public ApiBootWebSecurityMemoryAutoConfiguration(ApiBootSecurityProperties apiBootSecurityProperties, ObjectProvider<AccessDeniedHandler> accessDeniedHandler, ObjectProvider<AuthenticationEntryPoint> authenticationEntryPoint) {
    super(apiBootSecurityProperties, accessDeniedHandler.getIfAvailable(), authenticationEntryPoint.getIfAvailable());
}
 
Example 17
Source File: ChronusAutoConfiguration.java    From chronus with Apache License 2.0 4 votes vote down vote up
public ChronusAutoConfiguration(ObjectProvider<ApplicationConfig> applicationConfig,
                                ObjectProvider<RegistryConfig> registryConfig) {
    this.applicationConfig = applicationConfig.getIfAvailable();
    this.registryConfig = registryConfig.getIfAvailable();
}
 
Example 18
Source File: SentinelConfig.java    From lion with Apache License 2.0 4 votes vote down vote up
public SentinelConfig(ObjectProvider<List<ViewResolver>> viewResolversProvider, ServerCodecConfigurer serverCodecConfigurer) {
    this.viewResolvers = viewResolversProvider.getIfAvailable(Collections::emptyList);
    this.serverCodecConfigurer = serverCodecConfigurer;
}
 
Example 19
Source File: WebsocketSyncDataConfiguration.java    From soul with Apache License 2.0 3 votes vote down vote up
/**
 * Websocket sync data service.
 *
 * @param websocketConfig   the websocket config
 * @param pluginSubscriber the plugin subscriber
 * @param metaSubscribers   the meta subscribers
 * @param authSubscribers   the auth subscribers
 * @return the sync data service
 */
@Bean
public SyncDataService websocketSyncDataService(final ObjectProvider<WebsocketConfig> websocketConfig, final ObjectProvider<PluginDataSubscriber> pluginSubscriber,
                                       final ObjectProvider<List<MetaDataSubscriber>> metaSubscribers, final ObjectProvider<List<AuthDataSubscriber>> authSubscribers) {
    log.info("you use websocket sync soul data.......");
    return new WebsocketSyncDataService(websocketConfig.getIfAvailable(WebsocketConfig::new), pluginSubscriber.getIfAvailable(),
            metaSubscribers.getIfAvailable(Collections::emptyList), authSubscribers.getIfAvailable(Collections::emptyList));
}
 
Example 20
Source File: SpringCloudPluginConfiguration.java    From soul with Apache License 2.0 2 votes vote down vote up
/**
 * init springCloud plugin.
 *
 * @param loadBalancerClient the load balancer client
 * @return {@linkplain SpringCloudPlugin}
 */
@Bean
public SoulPlugin springCloudPlugin(final ObjectProvider<LoadBalancerClient> loadBalancerClient) {
    return new SpringCloudPlugin(loadBalancerClient.getIfAvailable());
}