Compare commits

..

1 Commits

Author SHA1 Message Date
tomsun28
17838a74d2 [collector]add snmp dependency 2022-03-13 09:11:24 +08:00
4 changed files with 9 additions and 7 deletions

View File

@@ -103,6 +103,12 @@
<artifactId>sshd-core</artifactId>
<version>2.8.0</version>
</dependency>
<!-- snmp mib -->
<dependency>
<groupId>org.snmp4j</groupId>
<artifactId>snmp4j</artifactId>
<version>2.8.9</version>
</dependency>
</dependencies>
</project>

View File

@@ -2,7 +2,6 @@ package com.usthe.collector.collect.common.cache;
import lombok.Builder;
import lombok.Data;
import lombok.ToString;
/**
* 缓存key唯一标识符
@@ -11,7 +10,6 @@ import lombok.ToString;
*/
@Data
@Builder
@ToString
public class CacheIdentifier {
private String ip;

View File

@@ -21,9 +21,9 @@ import java.util.concurrent.TimeUnit;
public class CommonCache {
/**
* 默认缓存时间 800s
* 默认缓存时间 10minute
*/
private static final long DEFAULT_CACHE_TIMEOUT = 800 * 1000L;
private static final long DEFAULT_CACHE_TIMEOUT = 10 * 60 * 1000L;
/**
* 默认最大缓存数量
@@ -173,11 +173,9 @@ public class CommonCache {
public Optional<Object> getCache(Object key, boolean refreshCache) {
Long[] cacheTime = timeoutMap.get(key);
if (cacheTime == null || cacheTime.length != CACHE_TIME_LENGTH) {
log.warn("[cache] not hit the cache, key {}.", key);
return Optional.empty();
}
if (cacheTime[0] + cacheTime[1] < System.currentTimeMillis()) {
log.warn("[cache] is timeout, key {}.", key);
timeoutMap.remove(key);
cacheMap.remove(key);
return Optional.empty();

View File

@@ -134,7 +134,7 @@ public class JdbcCommonCollect extends AbstractCollect {
// 设置查询最大行数1000行
statement.setMaxRows(1000);
JdbcConnect jdbcConnect = new JdbcConnect(connection);
CommonCache.getInstance().addCache(identifier, jdbcConnect);
CommonCache.getInstance().addCache(identifier, jdbcConnect, 10000L);
return statement;
}