use of com.alibaba.nacos.config.server.model.event.LocalDataChangeEvent in project nacos by alibaba.
the class ConfigCacheService method removeTag.
/**
* Delete tag config file, and delete cache.
*
* @param dataId dataId string value.
* @param group group string value.
* @param tenant tenant string value.
* @param tag tag string value.
* @return remove success or not.
*/
public static boolean removeTag(String dataId, String group, String tenant, String tag) {
final String groupKey = GroupKey2.getKey(dataId, group, tenant);
final int lockResult = tryWriteLock(groupKey);
// If data is non-existent.
if (0 == lockResult) {
DUMP_LOG.info("[remove-ok] {} not exist.", groupKey);
return true;
}
// try to lock failed
if (lockResult < 0) {
DUMP_LOG.warn("[remove-error] write lock failed. {}", groupKey);
return false;
}
try {
if (!PropertyUtil.isDirectRead()) {
DiskUtil.removeConfigInfo4Tag(dataId, group, tenant, tag);
}
CacheItem ci = CACHE.get(groupKey);
ci.tagMd5.remove(tag);
ci.tagLastModifiedTs.remove(tag);
NotifyCenter.publishEvent(new LocalDataChangeEvent(groupKey, false, null, tag));
return true;
} finally {
releaseWriteLock(groupKey);
}
}
use of com.alibaba.nacos.config.server.model.event.LocalDataChangeEvent in project nacos by alibaba.
the class ConfigCacheService method updateMd5.
/**
* Update md5 value.
*
* @param groupKey groupKey string value.
* @param md5 md5 string value.
* @param lastModifiedTs lastModifiedTs long value.
*/
public static void updateMd5(String groupKey, String md5, long lastModifiedTs, String encryptedDataKey) {
CacheItem cache = makeSure(groupKey, encryptedDataKey, false);
if (cache.md5 == null || !cache.md5.equals(md5)) {
cache.md5 = md5;
cache.lastModifiedTs = lastModifiedTs;
NotifyCenter.publishEvent(new LocalDataChangeEvent(groupKey));
}
}
use of com.alibaba.nacos.config.server.model.event.LocalDataChangeEvent in project nacos by alibaba.
the class RpcConfigChangeNotifierTest method testOnEvent.
@Test
public void testOnEvent() {
final String groupKey = GroupKey2.getKey("nacos.internal.tps.control_rule_1", "nacos", "tenant");
final String limitGroupKey = GroupKey2.getKey("nacos.internal.tps.nacos.internal.connection.limit.rule", "nacos", "tenant");
List<String> betaIps = new ArrayList<>();
betaIps.add("1.1.1.1");
rpcConfigChangeNotifier.onEvent(new LocalDataChangeEvent(groupKey, true, betaIps));
rpcConfigChangeNotifier.onEvent(new LocalDataChangeEvent(limitGroupKey));
}
use of com.alibaba.nacos.config.server.model.event.LocalDataChangeEvent in project nacos by alibaba.
the class InternalConfigChangeNotifierTest method testOnEvent.
@Test
public void testOnEvent() {
final String groupKey = GroupKey2.getKey("nacos.internal.tps.control_rule_1", "nacos", "tenant");
final String limitGroupKey = GroupKey2.getKey("nacos.internal.tps.nacos.internal.connection.limit.rule", "nacos", "tenant");
NotifyCenter.registerSubscriber(new Subscriber() {
@Override
public void onEvent(Event event) {
ConnectionLimitRuleChangeEvent connectionLimitRuleChangeEvent = (ConnectionLimitRuleChangeEvent) event;
Assert.assertEquals("content", connectionLimitRuleChangeEvent.getLimitRule());
}
@Override
public Class<? extends Event> subscribeType() {
return ConnectionLimitRuleChangeEvent.class;
}
});
NotifyCenter.registerSubscriber(new Subscriber() {
@Override
public void onEvent(Event event) {
TpsControlRuleChangeEvent tpsControlRuleChangeEvent = (TpsControlRuleChangeEvent) event;
Assert.assertEquals("content", tpsControlRuleChangeEvent.getRuleContent());
}
@Override
public Class<? extends Event> subscribeType() {
return TpsControlRuleChangeEvent.class;
}
});
internalConfigChangeNotifier.onEvent(new LocalDataChangeEvent(groupKey));
internalConfigChangeNotifier.onEvent(new LocalDataChangeEvent(limitGroupKey));
try {
Thread.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
use of com.alibaba.nacos.config.server.model.event.LocalDataChangeEvent in project nacos by alibaba.
the class ConfigCacheService method removeBeta.
/**
* Delete beta config file, and delete cache.
*
* @param dataId dataId string value.
* @param group group string value.
* @param tenant tenant string value.
* @return remove success or not.
*/
public static boolean removeBeta(String dataId, String group, String tenant) {
final String groupKey = GroupKey2.getKey(dataId, group, tenant);
final int lockResult = tryWriteLock(groupKey);
// If data is non-existent.
if (0 == lockResult) {
DUMP_LOG.info("[remove-ok] {} not exist.", groupKey);
return true;
}
// try to lock failed
if (lockResult < 0) {
DUMP_LOG.warn("[remove-error] write lock failed. {}", groupKey);
return false;
}
try {
if (!PropertyUtil.isDirectRead()) {
DiskUtil.removeConfigInfo4Beta(dataId, group, tenant);
}
NotifyCenter.publishEvent(new LocalDataChangeEvent(groupKey, true, CACHE.get(groupKey).getIps4Beta()));
CACHE.get(groupKey).setBeta(false);
CACHE.get(groupKey).setIps4Beta(null);
CACHE.get(groupKey).setMd54Beta(Constants.NULL);
return true;
} finally {
releaseWriteLock(groupKey);
}
}
Aggregations