Commit 44b040f0 by Nepxion

提交discovery-plugin-actuator模块

parent b9698a8f
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<artifactId>discovery-plugin-actuator</artifactId>
<name>Nepxion Discovery Plugin Actuator</name>
<packaging>jar</packaging>
<modelVersion>4.0.0</modelVersion>
<description>Nepxion Discovery is an enhancement for Spring Cloud Discovery</description>
<url>http://www.nepxion.com</url>
<parent>
<groupId>com.nepxion</groupId>
<artifactId>discovery</artifactId>
<version>1.0.0</version>
</parent>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>discovery-plugin-core</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
</dependencies>
</project>
\ No newline at end of file
package com.nepxion.discovery.plugin.actuator.cache;
/**
* <p>Title: Nepxion Discovery</p>
* <p>Description: Nepxion Discovery</p>
* <p>Copyright: Copyright (c) 2017-2050</p>
* <p>Company: Nepxion</p>
* @author Haojun Ren
* @version 1.0
*/
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import org.apache.commons.lang3.StringUtils;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
public class ActuatorCache {
private static class LazyHolder {
private static final ActuatorCache INSTANCE = new ActuatorCache();
}
private static final LoadingCache<String, String> EUREKA_RULE_CACHE = CacheBuilder.newBuilder()
.concurrencyLevel(8)
.expireAfterWrite(1, TimeUnit.DAYS)
.initialCapacity(10)
.maximumSize(100)
.recordStats()
.build(new CacheLoader<String, String>() {
@Override
public String load(String key) throws Exception {
return StringUtils.EMPTY;
}
});
private ActuatorCache() {
}
public static final ActuatorCache getInstance() {
return LazyHolder.INSTANCE;
}
public boolean put(String serviceId, String rule) {
EUREKA_RULE_CACHE.put(serviceId, rule);
return Boolean.TRUE;
}
public String get(String serviceId) {
try {
return EUREKA_RULE_CACHE.get(serviceId);
} catch (ExecutionException e) {
return StringUtils.EMPTY;
}
}
public boolean clear(String serviceId) {
EUREKA_RULE_CACHE.invalidate(serviceId);
return Boolean.TRUE;
}
}
\ No newline at end of file
package com.nepxion.discovery.plugin.core.cache;
/**
* <p>Title: Nepxion Discovery</p>
* <p>Description: Nepxion Discovery</p>
* <p>Copyright: Copyright (c) 2017-2050</p>
* <p>Company: Nepxion</p>
* @author Haojun Ren
* @version 1.0
*/
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import org.apache.commons.lang3.StringUtils;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
public class PluginCache {
private LoadingCache<String, String> loadingCache;
public PluginCache() {
loadingCache = CacheBuilder.newBuilder()
.concurrencyLevel(8)
.expireAfterWrite(1, TimeUnit.DAYS)
.initialCapacity(10)
.maximumSize(100)
.recordStats()
.build(new CacheLoader<String, String>() {
@Override
public String load(String key) throws Exception {
return StringUtils.EMPTY;
}
});
}
public boolean put(String key, String value) {
loadingCache.put(key, value);
return Boolean.TRUE;
}
public String get(String key) {
try {
return loadingCache.get(key);
} catch (ExecutionException e) {
return StringUtils.EMPTY;
}
}
public boolean remove(String key) {
loadingCache.invalidate(key);
return Boolean.TRUE;
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment