Search in sources :

Example 6 with LocalDataChangeEvent

use of com.alibaba.nacos.config.server.model.event.LocalDataChangeEvent in project nacos by alibaba.

the class ConfigCacheService method updateBetaMd5.

/**
 * Update Beta md5 value.
 *
 * @param groupKey       groupKey string value.
 * @param md5            md5 string value.
 * @param ips4Beta       ips4Beta List.
 * @param lastModifiedTs lastModifiedTs long value.
 */
public static void updateBetaMd5(String groupKey, String md5, List<String> ips4Beta, long lastModifiedTs, String encryptedDataKey) {
    CacheItem cache = makeSure(groupKey, encryptedDataKey, true);
    if (cache.md54Beta == null || !cache.md54Beta.equals(md5)) {
        cache.isBeta = true;
        cache.md54Beta = md5;
        cache.lastModifiedTs4Beta = lastModifiedTs;
        cache.ips4Beta = ips4Beta;
        NotifyCenter.publishEvent(new LocalDataChangeEvent(groupKey, true, ips4Beta));
    }
}
Also used : LocalDataChangeEvent(com.alibaba.nacos.config.server.model.event.LocalDataChangeEvent) CacheItem(com.alibaba.nacos.config.server.model.CacheItem)

Example 7 with LocalDataChangeEvent

use of com.alibaba.nacos.config.server.model.event.LocalDataChangeEvent in project nacos by alibaba.

the class ConfigCacheService method updateTagMd5.

/**
 * Update tag md5 value.
 *
 * @param groupKey       groupKey string value.
 * @param tag            tag string value.
 * @param md5            md5 string value.
 * @param lastModifiedTs lastModifiedTs long value.
 */
public static void updateTagMd5(String groupKey, String tag, String md5, long lastModifiedTs, String encryptedDataKey) {
    CacheItem cache = makeSure(groupKey, encryptedDataKey, false);
    if (cache.tagMd5 == null) {
        Map<String, String> tagMd5Tmp = new HashMap<>(1);
        tagMd5Tmp.put(tag, md5);
        cache.tagMd5 = tagMd5Tmp;
        if (cache.tagLastModifiedTs == null) {
            Map<String, Long> tagLastModifiedTsTmp = new HashMap<>(1);
            tagLastModifiedTsTmp.put(tag, lastModifiedTs);
            cache.tagLastModifiedTs = tagLastModifiedTsTmp;
        } else {
            cache.tagLastModifiedTs.put(tag, lastModifiedTs);
        }
        NotifyCenter.publishEvent(new LocalDataChangeEvent(groupKey, false, null, tag));
        return;
    }
    if (cache.tagMd5.get(tag) == null || !cache.tagMd5.get(tag).equals(md5)) {
        cache.tagMd5.put(tag, md5);
        cache.tagLastModifiedTs.put(tag, lastModifiedTs);
        NotifyCenter.publishEvent(new LocalDataChangeEvent(groupKey, false, null, tag));
    }
}
Also used : HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) LocalDataChangeEvent(com.alibaba.nacos.config.server.model.event.LocalDataChangeEvent) CacheItem(com.alibaba.nacos.config.server.model.CacheItem)

Example 8 with LocalDataChangeEvent

use of com.alibaba.nacos.config.server.model.event.LocalDataChangeEvent in project nacos by alibaba.

the class ConfigCacheService method remove.

/**
 * Delete 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 remove(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.removeConfigInfo(dataId, group, tenant);
        }
        CACHE.remove(groupKey);
        NotifyCenter.publishEvent(new LocalDataChangeEvent(groupKey));
        return true;
    } finally {
        releaseWriteLock(groupKey);
    }
}
Also used : LocalDataChangeEvent(com.alibaba.nacos.config.server.model.event.LocalDataChangeEvent)

Aggregations

LocalDataChangeEvent (com.alibaba.nacos.config.server.model.event.LocalDataChangeEvent)8 CacheItem (com.alibaba.nacos.config.server.model.CacheItem)4 Test (org.junit.Test)2 Event (com.alibaba.nacos.common.notify.Event)1 Subscriber (com.alibaba.nacos.common.notify.listener.Subscriber)1 TpsControlRuleChangeEvent (com.alibaba.nacos.core.remote.control.TpsControlRuleChangeEvent)1 ConnectionLimitRuleChangeEvent (com.alibaba.nacos.core.remote.event.ConnectionLimitRuleChangeEvent)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1