-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix hazelcast configuration and documentation
- Loading branch information
1 parent
31c8236
commit 5cd554b
Showing
10 changed files
with
171 additions
and
61 deletions.
There are no files selected for viewing
This file contains 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,24 @@ | ||
# Contributing a new cache implementation | ||
|
||
How a cache implementation should be created depends on whether the caches can/should be declared ahead of time. For caches with predefined cache names, `SyncCache` beans should be created which will be ingested by the default cache manager. For caches that cannot or should not be defined ahead of time, a `DynamicCacheManager` bean should be registered to retrieve the cache. | ||
|
||
Any other beans created are not used by Micronaut. The only beans referenced are `SyncCache` and `DynamicCacheManager`. | ||
|
||
## Synchronous cache implementations | ||
|
||
For caches that using blocking IO, the `getExecutorService()` method should be overridden for each `SyncCache` to allow the offloading of the operations to a thread pool. Unless there is a reason to do otherwise, the `TaskManagers.IO` named thread pool should be used. | ||
|
||
## Asynchronous cache implementations | ||
|
||
If the cache provider has an asynchronous API, the `async()` method of `SyncCache` should be overridden to supply an `AsyncCache` that uses the native asynchronous API. See the Hazelcast implementation for an example. | ||
|
||
## Gradle build and setup | ||
|
||
To ensure consistency across implementations, copy the build of an existing implementation and alter the dependencies as needed. | ||
|
||
## Documentation | ||
|
||
All cache implementations should be documented by modifying the `src/main/docs/guide/toc.yml` to include your documentation. Documentation should describe how to install and configure the implementation. | ||
|
||
|
||
|
This file contains 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 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 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 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
20 changes: 20 additions & 0 deletions
20
...st/src/main/java/io/micronaut/cache/hazelcast/converters/MapToConcurrentMapConverter.java
This file contains 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,20 @@ | ||
package io.micronaut.cache.hazelcast.converters; | ||
|
||
|
||
import io.micronaut.core.convert.ConversionContext; | ||
import io.micronaut.core.convert.TypeConverter; | ||
|
||
import javax.inject.Singleton; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
import java.util.concurrent.ConcurrentMap; | ||
|
||
@Singleton | ||
public class MapToConcurrentMapConverter implements TypeConverter<Map, ConcurrentMap> { | ||
|
||
@Override | ||
public Optional<ConcurrentMap> convert(Map object, Class<ConcurrentMap> targetType, ConversionContext context) { | ||
return Optional.of(new ConcurrentHashMap(object)); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
cache-hazelcast/src/main/java/io/micronaut/cache/hazelcast/package-info.java
This file contains 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 |
---|---|---|
@@ -1 +1,27 @@ | ||
/* | ||
* Copyright 2017-2019 original 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. | ||
*/ | ||
|
||
/** | ||
* Classes related to the integration of Hazelcast caches into Micronaut's | ||
* cache manager. | ||
*/ | ||
@Configuration | ||
@Requires(property = "hazelcast.enabled", notEquals = StringUtils.FALSE) | ||
package io.micronaut.cache.hazelcast; | ||
|
||
import io.micronaut.context.annotation.Configuration; | ||
import io.micronaut.context.annotation.Requires; | ||
import io.micronaut.core.util.StringUtils; |
63 changes: 57 additions & 6 deletions
63
...cast/src/test/groovy/io/micronaut/cache/hazelcast/HazelcastClientConfigurationSpec.groovy
This file contains 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 |
---|---|---|
@@ -1,27 +1,78 @@ | ||
package io.micronaut.cache.hazelcast | ||
|
||
import com.hazelcast.client.config.ClientConfig | ||
import com.hazelcast.config.ListenerConfig | ||
import io.micronaut.context.ApplicationContext | ||
import io.micronaut.context.event.BeanCreatedEvent | ||
import io.micronaut.context.event.BeanCreatedEventListener | ||
import spock.lang.Specification | ||
|
||
import javax.inject.Singleton | ||
|
||
class HazelcastClientConfigurationSpec extends Specification { | ||
|
||
void "test nested network configuration"() { | ||
given: | ||
ApplicationContext ctx = ApplicationContext.run(ApplicationContext, [ | ||
"hazelcast.instanceName": 'myInstance', | ||
"hazelcast.network.connectionTimeout": 99, | ||
"hazelcast.network.addresses": ['127.0.0.1:5701', 'http://hazelcast:5702'], | ||
"hazelcast.network.redoOperation": true | ||
"hazelcast.client.network.smartRouting": false, | ||
"hazelcast.client.network.connectionAttemptPeriod": 1000, | ||
"hazelcast.client.network.connectionAttemptLimit": 5, | ||
"hazelcast.client.network.connectionTimeout": 1000, | ||
"hazelcast.client.network.addresses": ['127.0.0.1:5701', 'http://hazelcast:5702'], | ||
"hazelcast.client.network.redoOperation": true, | ||
"hazelcast.client.network.outboundPortDefinitions": ["a", "b"], | ||
"hazelcast.client.network.outboundPorts": [1, 2], | ||
"hazelcast.client.network.socket.tcpNoDelay": false, | ||
"hazelcast.client.network.socket.keepAlive": false, | ||
"hazelcast.client.network.socket.reuseAddress": false, | ||
"hazelcast.client.network.socket.lingerSeconds": 5, | ||
"hazelcast.client.network.socket.bufferSize": 64, | ||
"hazelcast.client.group.name": "Group", | ||
"hazelcast.client.properties": [x: "x", y: "y"], | ||
"hazelcast.client.executorPoolSize": 3, | ||
"hazelcast.client.licenseKey": "license key", | ||
"hazelcast.client.instanceName": "instance name", | ||
"hazelcast.client.labels": ["a", "b"], | ||
"hazelcast.client.userContext": [a: "a", b: "b"] | ||
]) | ||
|
||
when: | ||
HazelcastClientConfiguration hazelcastClientConfiguration = ctx.getBean(HazelcastClientConfiguration) | ||
|
||
then: | ||
hazelcastClientConfiguration.instanceName == "myInstance" | ||
hazelcastClientConfiguration.networkConfig.connectionTimeout == 99 | ||
!hazelcastClientConfiguration.networkConfig.smartRouting | ||
hazelcastClientConfiguration.networkConfig.connectionAttemptPeriod == 1000 | ||
hazelcastClientConfiguration.networkConfig.addresses[0] == "127.0.0.1:5701" | ||
hazelcastClientConfiguration.networkConfig.addresses[1] == "http://hazelcast:5702" | ||
hazelcastClientConfiguration.networkConfig.redoOperation | ||
hazelcastClientConfiguration.networkConfig.outboundPortDefinitions == ["a", "b"] | ||
hazelcastClientConfiguration.networkConfig.outboundPorts == [1, 2] | ||
!hazelcastClientConfiguration.networkConfig.socketOptions.tcpNoDelay | ||
!hazelcastClientConfiguration.networkConfig.socketOptions.keepAlive | ||
!hazelcastClientConfiguration.networkConfig.socketOptions.reuseAddress | ||
hazelcastClientConfiguration.networkConfig.socketOptions.lingerSeconds == 5 | ||
hazelcastClientConfiguration.networkConfig.socketOptions.bufferSize == 64 | ||
hazelcastClientConfiguration.groupConfig.name == "Group" | ||
hazelcastClientConfiguration.properties.get("x") == "x" | ||
hazelcastClientConfiguration.properties.get("y") == "y" | ||
hazelcastClientConfiguration.executorPoolSize == 3 | ||
hazelcastClientConfiguration.licenseKey == "license key" | ||
hazelcastClientConfiguration.instanceName == "instance name" | ||
hazelcastClientConfiguration.labels == ["a", "b"] as Set | ||
hazelcastClientConfiguration.userContext.get("a") == "a" | ||
hazelcastClientConfiguration.userContext.get("b") == "b" | ||
hazelcastClientConfiguration.listenerConfigs.size() == 1 | ||
} | ||
|
||
@Singleton | ||
static class CustomConfig implements BeanCreatedEventListener<ClientConfig> { | ||
|
||
@Override | ||
ClientConfig onCreated(BeanCreatedEvent<ClientConfig> event) { | ||
event.getBean().addListenerConfig(new ListenerConfig(new EventListener() { | ||
|
||
})) | ||
event.getBean() | ||
} | ||
} | ||
} |
This file contains 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 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 |
---|---|---|
@@ -1,11 +1,10 @@ | ||
This project brings cache support to Micronaut. | ||
This project brings additional cache implementations to Micronaut. | ||
|
||
To get started, you need to declare the following dependency: | ||
|
||
dependency:io.micronaut.cache:micronaut-cache-core:{version}[] | ||
dependency:io.micronaut:micronaut-runtime[] | ||
|
||
Note that this configuration module requires at least Micronaut 1.3. Since this version, caching support has been | ||
extracted out from core into this configuration library. | ||
NOTE: The configuration implementations in this module require at least Micronaut version 1.3.0. Each implementation is a separate dependency. | ||
|
||
To use the `BUILD-SNAPSHOT` version of this library, check the | ||
https://docs.micronaut.io/latest/guide/index.html#usingsnapshots[documentation to use snapshots]. |