Skip to content

Add auto-configuration for Hazelcast #2942

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
snicoll opened this issue May 13, 2015 · 8 comments
Closed

Add auto-configuration for Hazelcast #2942

snicoll opened this issue May 13, 2015 · 8 comments
Assignees
Labels
type: enhancement A general enhancement
Milestone

Comments

@snicoll
Copy link
Member

snicoll commented May 13, 2015

This was the original intent of #2848 but unfortunately the actual discussion moved to another direction.

Hazelcast can be used for "non-caching" scenario. In particular, spring-integration has a specific Hazelcast integration. This integration needs the HazelcastInstance as a @Bean definition and it does not need to be necessarily coupled with caching. So it should work even if HazelcastCacheManager is not present and if @EnableCaching has not been specified.

This brings some interesting use cases:

  • Use Hazelcast for SI channels and "Foo" for caching
  • Use Hazelcast for SI channels and Hazelcast for caching
  • Only using Hazelcast for SI channels or only use Hazelcast for caching

Since HazelcastInstance provides cache-related features and other features, we would need to move the processing to a dedicated auto-configuration. We should probably integrate the caching-related bits in there if need to be (i.e. HazelcastAutoConfiguration has a dependency to the caching support, i.e. CachingProperties).

spring.cache.config should probably move away to spring.cache.hazelcast.config, spring.cache.ehcache.config and spring.cache.jcache.config and a new spring.hazelcast.config should be created. The mere presences of two separate properties would allow to create two HazelcastInstance if need to be. The condition to figure that out won't be easy to implement though.

Remains one last issue related to JCache. If we use Hazelcast and JCache for caching with hazelcast behind the scenes, we may bootstrap two HazelcastInstance while the user may expect the same configuration to be used with a single instance. Not sure yet if that's a problem and how to handle it.

@snicoll snicoll added the type: enhancement A general enhancement label May 13, 2015
@snicoll snicoll self-assigned this May 13, 2015
@snicoll snicoll added this to the 1.3.0 milestone May 13, 2015
@artembilan
Copy link
Member

Thanks, @snicoll , this sounds good!

Sorry, if I wasn't so clear in that issue with caching.

Don't forget here about Spring Cloud - see the first comment in #2848

I wonder if should just expose an option like spring.hazelcast.enable, true by default. Similar we do for JMX.

CC: @jvalkeal

@snicoll
Copy link
Member Author

snicoll commented May 15, 2015

What should I not forget? Checking for HazelcastConfig bean?

@snicoll
Copy link
Member Author

snicoll commented Jul 17, 2015

Don't forget here about Spring Cloud - see the first comment in #2848

I don't understand what you mean, sorry. Please clarify.

@artembilan
Copy link
Member

Hello, @snicoll !

Sorry, for delay. Realy have missed this ticket somehow... Was busy outside of Hazelcast stuff 😄

Regarding Spring Cloud: I meant just keep it in mind that it is one more Spring Portfolio projects which uses Hazelcast and Boot. Although, as we see by their code, it does that wrong way - without any @Conditionals. And my point here is to fix that code when we will have this HazelcastAutoConfiguration already.
CC @jvalkeal

What should I not forget? Checking for HazelcastConfig bean?

Yes, I think so. Something similar what you do in the HazelcastCacheConfiguration but for common auto-config exposing it as a conditional bean and that cache abstraction (@AutoConfigureAfter ?) can reuse the config:

@Autowired(required = false)
private Config hazelcastConfig;

The instance may look like this:

@Bean
@ConditionalOnMissingBean
public HazelcastInstance hazelcastInstance(Config hazelcastConfig) {
    if (StringUtils.hasText(config.getInstanceName())) {
        return Hazelcast.getOrCreateHazelcastInstance(cfg);
    }
    return Hazelcast.newHazelcastInstance(cfg);
}

and so on.

@snicoll
Copy link
Member Author

snicoll commented Jul 17, 2015

okay so checking for the presence of HazelcastInstance or Config is what I was looking for. Thanks.

@philwebb philwebb modified the milestones: 1.3.0.M3, 1.3.0.RC1 Aug 5, 2015
@snicoll snicoll modified the milestones: 1.4.0, 1.3.0.RC1 Aug 20, 2015
@shakuzen
Copy link
Member

👍 for this enhancement. And if possible (though I know the release date for RC1 is quickly approaching), I'd love to see this in 1.3.

@shakuzen
Copy link
Member

@snicoll Would it be worth opening a separate issue for basic Hazelcast auto-configuration? I mostly just want to use it with Spring Session and possibly as an in-memory data grid. This seems to be a more basic requirement than supporting Spring Integration. Then perhaps that could be included in 1.3 (I would be willing to work on a PR), while the SI parts wait until 1.4?

@snicoll
Copy link
Member Author

snicoll commented Aug 24, 2015

@shakuzen I've already started and this issue has no SI bits at all. The purpose was to allow SI to smoothly integrate with it. In other words, this issue is the "basic" requirement you're mentioning.

It would be nice if you could try it once it's done so that we get a chance to improve it if necessary.

@snicoll snicoll modified the milestones: 1.3.0.RC1, 1.4.0 Aug 25, 2015
snicoll added a commit to snicoll/spring-boot that referenced this issue Aug 26, 2015
Provide a general purpose Hazelcast integration (i.e. not tied to caching).

Auto-configure a `HazelcastInstance` either based on the presence of a
`Config` bean or a configuration file. Said configuration file can be
specified explicitly or automatically found from default locations.

The cache integration already supports Hazelcast so it has been reworked
to automatically reuse an existing `HazelcastInstance` if available.

Closes spring-projectsgh-2942
philwebb added a commit that referenced this issue Sep 3, 2015
Extract a HazelcastInstanceFactory class and cleanup some formatting.

See gh-2942
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

4 participants