Search in sources :

Example 1 with ShadowHbaseDynamicEvent

use of com.pamirs.pradar.pressurement.agent.event.impl.ShadowHbaseDynamicEvent in project LinkAgent by shulieTech.

the class ShadowHbaseConfigs method compareIsChangeAndSet.

@Override
public Boolean compareIsChangeAndSet(ApplicationConfig currentValue, Map<String, ShadowHbaseConfig> newValue) {
    Map<String, ShadowHbaseConfig> old = GlobalConfig.getInstance().getShadowHbaseServerConfigs();
    boolean change = false;
    if (newValue.size() < 1) {
        GlobalConfig.getInstance().setShadowHbaseServer(false);
        for (Map.Entry<String, ShadowHbaseConfig> entry : old.entrySet()) {
            EventRouter.router().publish(new ShadowHbaseDisableEvent(entry.getKey()));
        }
        GlobalConfig.getInstance().getShadowHbaseServerConfigs().clear();
        return true;
    }
    for (Map.Entry<String, ShadowHbaseConfig> entry : old.entrySet()) {
        String key = entry.getKey();
        if (!newValue.containsKey(key)) {
            EventRouter.router().publish(new ShadowHbaseDisableEvent(key));
            change = true;
        } else {
            if (!newValue.get(key).equals(entry.getValue())) {
                EventRouter.router().publish(new ShadowHbaseDynamicEvent(entry.getValue()));
                change = true;
            }
        }
    }
    for (Map.Entry<String, ShadowHbaseConfig> entry : newValue.entrySet()) {
        String key = entry.getKey();
        if (old.containsKey(key)) {
            if (!old.get(key).equals(entry.getValue())) {
                EventRouter.router().publish(new ShadowHbaseDynamicEvent(entry.getValue()));
                change = true;
            }
        } else {
            change = true;
            EventRouter.router().publish(new ShadowHbaseDynamicEvent(entry.getValue()));
        }
    }
    GlobalConfig.getInstance().getShadowHbaseServerConfigs().clear();
    GlobalConfig.getInstance().setShadowHbaseServerConfigs(newValue);
    if (LOGGER.isInfoEnabled()) {
        LOGGER.info("publish shadow hbase config successful. config={}", newValue);
    }
    return change;
}
Also used : ShadowHbaseDynamicEvent(com.pamirs.pradar.pressurement.agent.event.impl.ShadowHbaseDynamicEvent) ShadowHbaseConfig(com.pamirs.pradar.internal.config.ShadowHbaseConfig) ShadowHbaseDisableEvent(com.pamirs.pradar.pressurement.agent.event.impl.ShadowHbaseDisableEvent) Map(java.util.Map)

Aggregations

ShadowHbaseConfig (com.pamirs.pradar.internal.config.ShadowHbaseConfig)1 ShadowHbaseDisableEvent (com.pamirs.pradar.pressurement.agent.event.impl.ShadowHbaseDisableEvent)1 ShadowHbaseDynamicEvent (com.pamirs.pradar.pressurement.agent.event.impl.ShadowHbaseDynamicEvent)1 Map (java.util.Map)1