-
Notifications
You must be signed in to change notification settings - Fork 41.2k
Add auto-configuration support for Apache Geode as a caching provider. #6967
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
jxblum
wants to merge
1
commit into
spring-projects:master
from
jxblum:autoconfigure-cache-data-geode
+549
−96
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
...e/src/main/java/org/springframework/boot/autoconfigure/cache/GeodeCacheConfiguration.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
* Copyright 2011-2016 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.springframework.boot.autoconfigure.cache; | ||
|
||
import java.util.HashSet; | ||
|
||
import org.apache.geode.cache.Cache; | ||
import org.apache.geode.cache.GemFireCache; | ||
import org.apache.geode.cache.client.ClientCache; | ||
|
||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; | ||
import org.springframework.cache.CacheManager; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Conditional; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.data.gemfire.CacheFactoryBean; | ||
import org.springframework.data.gemfire.client.ClientCacheFactoryBean; | ||
import org.springframework.data.gemfire.support.GemfireCacheManager; | ||
|
||
/** | ||
* GemFire cache configuration. | ||
* | ||
* @author John Blum | ||
* @see org.apache.geode.cache.Cache | ||
* @see org.apache.geode.cache.GemFireCache | ||
* @see org.apache.geode.cache.client.ClientCache | ||
* @see org.springframework.context.annotation.Bean | ||
* @see org.springframework.context.annotation.Configuration | ||
* @see org.springframework.data.gemfire.support.GemfireCacheManager | ||
* @since 1.5.0 | ||
*/ | ||
@Configuration | ||
@ConditionalOnBean({ CacheFactoryBean.class, Cache.class, | ||
ClientCacheFactoryBean.class, ClientCache.class }) | ||
@ConditionalOnClass(GemfireCacheManager.class) | ||
@ConditionalOnMissingBean(CacheManager.class) | ||
@Conditional(CacheCondition.class) | ||
class GeodeCacheConfiguration { | ||
|
||
private final CacheProperties cacheProperties; | ||
|
||
private final CacheManagerCustomizers cacheManagerCustomizers; | ||
|
||
GeodeCacheConfiguration(CacheProperties cacheProperties, | ||
CacheManagerCustomizers cacheManagerCustomizers) { | ||
|
||
this.cacheProperties = cacheProperties; | ||
this.cacheManagerCustomizers = cacheManagerCustomizers; | ||
} | ||
|
||
@Bean | ||
public GemfireCacheManager cacheManager(GemFireCache gemfireCache) { | ||
GemfireCacheManager cacheManager = new GemfireCacheManager(); | ||
|
||
cacheManager.setCache(gemfireCache); | ||
cacheManager.setCacheNames(new HashSet<String>(this.cacheProperties.getCacheNames())); | ||
|
||
return this.cacheManagerCustomizers.customize(cacheManager); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't the condition be on
GemfireCache
there?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No. I mean
GemfireCache
is a class in Spring Data Geode and I cannot obviously use theConditionalOnBean
condition since that is a Spring BootCondition
class.I somewhat modeled my
GeodeCacheConfiguration
class after theRedisCacheConfiguration
class, and specifically this.RedisTemplate
comes from spring-data-redis and it would be weird to put aCondition
on theRedisTemplate
for caching.I guess I was maybe a bit paranoid after our discussion about GemFire/Geode being a System of Record (SoR) in certain UCs and overstepping another, perhaps preferred caching solution (e.g. Ehcache) in a Spring Boot user's application. As such I went a little nuts with the
Conditional
annotations onGeodeCacheConfiguration
.I suppose the following
Conditional
annotations would be sufficient...I could maybe add a
Conditional
annotation onGemfireCache
in SDG, but I'd rather not.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's not what I mean. Shouldn't that condition above be
@ConditionalOnBean({ CacheFactoryBean.class, GemfireCache.class,...
rather than@ConditionalOnBean({ CacheFactoryBean.class, Cache.class,...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@snicoll - Alright, I see what you are saying now, but, as an FYI, I think you need to be more careful in what you mean. It is not "GemfireCache", it is "GemFireCache"
Unfortunately, there are a bunch of class names in SDG that are inappropriately named (e.g. GemfireTemplate) or confusing (e.g. GemfireCache). Personally, I like the lower case 'f' in the naming, but, it is inconsistent with GemFire/Geode, and has been that way since the project inception, so would very disrupting to users to change the class names now.
My plan is to introduce new configuration models that will allow them to rely less on the SDG API (and naming conventions; and even the GemFire/Geode API for that matter) and more on abstractions I introduce by way of Annotations, that will allow me to clean up the prior mess.
Regarding the recommendations on
@ConditionalOnBean
bean class references... the SDGFactoryBeans
return very specific types (e.g.Cache
andClientCache
). In earlier versions of the Spring Framework (possibly as recent as 4.1 and earlier) you could not refer to and inject a GemFire/Geode cache instance generically (i.e. as inGemFireCache
); it simply could not resolve the bean type. In fact, I think this problem was specific to theClientCache
interface in particular. Oddly enough, the actual implementing class in GemFire/Geode isGemFireCacheImpl
, which implements bothCache
andClientCache
.Then, something changed in latter versions of core Spring Framework where this started working. I suppose I can reconsider this now since Spring Boot 1.5 is based on core Spring Framework 4.3.