提交 748554e3 编写于 作者: 如梦技术's avatar 如梦技术 🐛

添加 mica-jetcache 待完善。

上级 c8efa2c1
......@@ -18,6 +18,7 @@ ext {
findbugsVersion = "3.0.2"
logstashVersion = "6.6"
zxingVersion = "3.4.1"
jetCacheVersion = "2.6.0"
}
configure(subprojects) {
......
......@@ -31,6 +31,7 @@ dependencyManagement {
dependency "net.dreamlu:mica-caffeine:${VERSION}"
dependency "net.dreamlu:mica-logging:${VERSION}"
dependency "net.dreamlu:mica-qrcode:${VERSION}"
dependency "net.dreamlu:mica-jetcache:${VERSION}"
dependency "net.dreamlu:mica-lite:${VERSION}"
// commons
dependency "com.google.code.findbugs:jsr305:${findbugsVersion}"
......
# mica-jetcache
## 功能扩展
- 扩展 metrics 打通 micrometer
- jackson KeyConvertorParser
- 添加 spring-configuration-metadata.json
## 使用
### maven
```xml
<dependency>
<groupId>net.dreamlu</groupId>
<artifactId>mica-jetcache</artifactId>
<version>${version}</version>
</dependency>
```
### gradle
```groovy
compile("net.dreamlu:mica-jetcache:${version}")
```
dependencies {
api project(":mica-core")
api("com.alicp.jetcache:jetcache-autoconfigure:${jetCacheVersion}") {
exclude group: "com.alibaba", module: "fastjson"
}
implementation "io.micrometer:micrometer-core"
annotationProcessor "net.dreamlu:mica-auto:${micaAutoVersion}"
}
/*
* Copyright (c) 2019-2029, Dreamlu 卢春梦 (596392912@qq.com & www.dreamlu.net).
* <p>
* Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0;
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.gnu.org/licenses/lgpl.html
* <p>
* 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 net.dreamlu.mica.jetcache.config;
import com.alicp.jetcache.anno.support.GlobalCacheConfig;
import com.alicp.jetcache.support.StatInfo;
import com.alicp.jetcache.support.StatInfoLogger;
import net.dreamlu.mica.jetcache.jackson.JacksonKeyConvertor;
import net.dreamlu.mica.jetcache.metrics.JetCacheMonitorManager;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.util.function.Consumer;
/**
* jetcache 配置
*
* @author L.cm
*/
@Configuration(proxyBeanMethods = false)
public class JetCacheConfiguration {
@Bean
public JacksonKeyConvertor jacksonKeyConvertor() {
return new JacksonKeyConvertor();
}
@Bean
public JetCacheMonitorManager jetCacheMonitorManager(GlobalCacheConfig globalCacheConfig,
ObjectProvider<Consumer<StatInfo>> metricsProvide) {
Consumer<StatInfo> metricsCallback = metricsProvide.getIfAvailable(() -> new StatInfoLogger(false));
return new JetCacheMonitorManager(globalCacheConfig, metricsCallback);
}
}
/*
* Copyright (c) 2019-2029, Dreamlu 卢春梦 (596392912@qq.com & www.dreamlu.net).
* <p>
* Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0;
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.gnu.org/licenses/lgpl.html
* <p>
* 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 net.dreamlu.mica.jetcache.jackson;
import net.dreamlu.mica.core.utils.JsonUtil;
import java.util.function.Function;
/**
* JacksonKey Convertor
*
* @author L.cm
*/
public class JacksonKeyConvertor implements Function<Object, Object> {
@Override
public Object apply(Object originalKey) {
if (originalKey == null) {
return null;
}
if (originalKey instanceof String) {
return originalKey;
}
return JsonUtil.toJson(originalKey);
}
}
/*
* Copyright (c) 2019-2029, Dreamlu 卢春梦 (596392912@qq.com & www.dreamlu.net).
* <p>
* Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0;
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.gnu.org/licenses/lgpl.html
* <p>
* 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 net.dreamlu.mica.jetcache.metrics;
import com.alicp.jetcache.support.DefaultCacheMonitor;
import com.alicp.jetcache.support.DefaultMetricsManager;
import com.alicp.jetcache.support.StatInfo;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;
/**
* JetCache MetricsManager
*
* @author L.cm
*/
public class JetCacheMetricsManager extends DefaultMetricsManager {
public JetCacheMetricsManager(int resetTime, TimeUnit resetTimeUnit, Consumer<StatInfo> metricsCallback) {
super(resetTime, resetTimeUnit, metricsCallback);
}
/**
* 获取监控数据
*
* @return DefaultCacheMonitor 集合
*/
public List<DefaultCacheMonitor> getMonitorList() {
return new ArrayList<>(monitorList);
}
}
/*
* Copyright (c) 2019-2029, Dreamlu 卢春梦 (596392912@qq.com & www.dreamlu.net).
* <p>
* Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0;
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.gnu.org/licenses/lgpl.html
* <p>
* 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 net.dreamlu.mica.jetcache.metrics;
import com.alicp.jetcache.Cache;
import com.alicp.jetcache.CacheUtil;
import com.alicp.jetcache.MultiLevelCache;
import com.alicp.jetcache.anno.support.CacheMonitorManager;
import com.alicp.jetcache.anno.support.GlobalCacheConfig;
import com.alicp.jetcache.support.DefaultCacheMonitor;
import com.alicp.jetcache.support.DefaultMetricsManager;
import com.alicp.jetcache.support.StatInfo;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;
/**
* JetCache CacheMonitorManager
*
* @author L.cm
*/
public class JetCacheMonitorManager implements CacheMonitorManager, InitializingBean, DisposableBean {
private final DefaultMetricsManager defaultMetricsManager;
public JetCacheMonitorManager(GlobalCacheConfig globalCacheConfig,
Consumer<StatInfo> metricsCallback) {
this.defaultMetricsManager = new JetCacheMetricsManager(globalCacheConfig.getStatIntervalMinutes(), TimeUnit.MINUTES, metricsCallback);
}
@Override
public void addMonitors(String area, String cacheName, Cache cache) {
cache = CacheUtil.getAbstractCache(cache);
if (cache instanceof MultiLevelCache) {
MultiLevelCache mc = (MultiLevelCache) cache;
if (mc.caches().length == 2) {
Cache local = mc.caches()[0];
Cache remote = mc.caches()[1];
DefaultCacheMonitor localMonitor = new DefaultCacheMonitor(cacheName + "_local");
local.config().getMonitors().add(localMonitor);
DefaultCacheMonitor remoteMonitor = new DefaultCacheMonitor(cacheName + "_remote");
remote.config().getMonitors().add(remoteMonitor);
defaultMetricsManager.add(localMonitor, remoteMonitor);
}
}
DefaultCacheMonitor monitor = new DefaultCacheMonitor(cacheName);
cache.config().getMonitors().add(monitor);
defaultMetricsManager.add(monitor);
}
@Override
public void destroy() throws Exception {
defaultMetricsManager.stop();
}
@Override
public void afterPropertiesSet() throws Exception {
defaultMetricsManager.start();
}
}
{
"groups": [
{
"name": "jetcache",
"type": "com.alicp.jetcache.autoconfigure.JetCacheProperties",
"sourceType": "com.alicp.jetcache.autoconfigure.JetCacheProperties"
}
],
"properties": [
{
"name": "jetcache.area-in-cache-name",
"type": "java.lang.Boolean",
"sourceType": "com.alicp.jetcache.autoconfigure.JetCacheProperties",
"defaultValue": true
},
{
"name": "jetcache.enable-method-cache",
"type": "java.lang.Boolean",
"sourceType": "com.alicp.jetcache.autoconfigure.JetCacheProperties",
"defaultValue": true
},
{
"name": "jetcache.hidden-packages",
"type": "java.lang.String[]",
"sourceType": "com.alicp.jetcache.autoconfigure.JetCacheProperties"
},
{
"name": "jetcache.local",
"type": "java.util.Map<java.lang.String,java.util.Map<java.lang.String,java.lang.Object>>",
"sourceType": "com.alicp.jetcache.autoconfigure.JetCacheProperties"
},
{
"name": "jetcache.penetration-protect",
"type": "java.lang.Boolean",
"sourceType": "com.alicp.jetcache.autoconfigure.JetCacheProperties",
"defaultValue": false
},
{
"name": "jetcache.remote",
"type": "java.util.Map<java.lang.String,java.util.Map<java.lang.String,java.lang.Object>>",
"sourceType": "com.alicp.jetcache.autoconfigure.JetCacheProperties"
},
{
"name": "jetcache.stat-interval-minutes",
"type": "java.lang.Integer",
"sourceType": "com.alicp.jetcache.autoconfigure.JetCacheProperties",
"defaultValue": 0
}
],
"hints": []
}
\ No newline at end of file
......@@ -15,4 +15,5 @@ include "mica-metrics"
include "mica-caffeine"
include "mica-logging"
include "mica-qrcode"
include "mica-jetcache"
include "mica-lite"
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册