All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cn.foxtech.common.entity.manager.EntityPublishManager Maven / Gradle / Ivy

The newest version!
/* ----------------------------------------------------------------------------
 * Copyright (c) Guangzhou Fox-Tech Co., Ltd. 2020-2024. All rights reserved.
 * --------------------------------------------------------------------------- */

package cn.foxtech.common.entity.manager;

import cn.foxtech.common.domain.constant.RedisStatusConstant;
import cn.foxtech.common.entity.constant.EntityPublishConstant;
import cn.foxtech.common.status.ServiceStatus;
import cn.foxtech.common.utils.redis.status.RedisStatusConsumerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * 发布配置管理
 * 很多服务需要通知ProxyCloud服务,把自己的数据发布到Fox-Cloud侧,此时可以通过该模块将自己的信息
 * 通知到ProxyCloud服务。
 * 该模块会将数据写入指定的redis缓存中,ProxyCloud会到指定的redis缓冲去读取这些配置数据
 */
@Component
public class EntityPublishManager {
    @Autowired
    private ServiceStatus serviceStatus;

    public void setPublishEntityUpdateTime(String entityType, String publishMode, String sourceType, String sourceName) {
        Map publishEntity = (Map) this.serviceStatus.getProducerData().computeIfAbsent(RedisStatusConstant.field_publish_entity, k -> new HashMap<>());
        Map entity = (Map) publishEntity.computeIfAbsent(entityType, k -> new HashMap<>());
        entity.put(EntityPublishConstant.field_publish_mode, publishMode);
        entity.put(EntityPublishConstant.field_source_type, sourceType);
        entity.put(EntityPublishConstant.field_source_name, sourceName);
    }

    public void setPublishEntityUpdateTime(String entityType, Long updateTime) {
        Map publishEntity = (Map) this.serviceStatus.getProducerData().computeIfAbsent(RedisStatusConstant.field_publish_entity, k -> new HashMap<>());
        Map entity = (Map) publishEntity.computeIfAbsent(entityType, k -> new HashMap<>());
        entity.put(EntityPublishConstant.field_update_time, updateTime);
    }

    public Object getPublishEntityUpdateTime(String entityType) {
        Map entity = this.getPublishEntity(entityType);
        if (entity == null) {
            return null;
        }

        return entity.get(EntityPublishConstant.field_update_time);
    }

    public Map getPublishEntity(String entityType) {
        for (Object statusValue : this.serviceStatus.getConsumerData().values()) {
            Map value = (Map)  statusValue;
            if (value == null) {
                continue;
            }

            Map publishEntity = (Map) value.get(RedisStatusConstant.field_publish_entity);
            if (publishEntity == null) {
                continue;
            }
            Map entity = (Map) publishEntity.get(entityType);
            if (entity == null) {
                continue;
            }

            return entity;
        }

        return null;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy