Search in sources :

Example 1 with DefaultCluster

use of com.ctrip.framework.dal.cluster.client.cluster.DefaultCluster in project dal by ctripcorp.

the class DynamicCluster method doSwitch.

public void doSwitch(ClusterConfig current) throws Exception {
    String logName = String.format(CAT_LOG_NAME_FORMAT, getClusterName());
    LOGGER.logTransaction(CAT_LOG_TYPE, logName, "", () -> {
        Cluster curr = clusterConfig.generate();
        Cluster prev = innerCluster.getAndSet(curr);
        ((DefaultCluster) curr).setLastLocalizationConfig(prev.getLocalizationConfig());
        try {
            if (prev.getClusterType() != ClusterType.DRC && curr.getClusterType() == ClusterType.DRC)
                LOGGER.logEvent(CAT_LOG_TYPE, String.format(CAT_EVENT_NAME_NORMAL_TO_DRC, getClusterName()), "");
            else if (prev.getClusterType() == ClusterType.DRC && curr.getClusterType() != ClusterType.DRC)
                LOGGER.logEvent(CAT_LOG_TYPE, String.format(CAT_EVENT_NAME_DRC_TO_NORMAL, getClusterName()), "");
        } catch (Throwable t) {
        // ignore
        }
        // TODO: TO BE REFACTORED
        ClusterSwitchedEvent event = new ClusterSwitchedEvent(curr, prev);
        for (Listener<ClusterSwitchedEvent> listener : getListeners()) {
            try {
                listener.onChanged(event);
            } catch (Throwable t) {
                LOGGER.logEvent(CAT_LOG_TYPE, logName, "ListenerError: " + listener.toString());
            }
        }
    });
}
Also used : DefaultCluster(com.ctrip.framework.dal.cluster.client.cluster.DefaultCluster) Cluster(com.ctrip.framework.dal.cluster.client.Cluster) ClusterSwitchedEvent(com.ctrip.framework.dal.cluster.client.cluster.ClusterSwitchedEvent) DefaultCluster(com.ctrip.framework.dal.cluster.client.cluster.DefaultCluster)

Aggregations

Cluster (com.ctrip.framework.dal.cluster.client.Cluster)1 ClusterSwitchedEvent (com.ctrip.framework.dal.cluster.client.cluster.ClusterSwitchedEvent)1 DefaultCluster (com.ctrip.framework.dal.cluster.client.cluster.DefaultCluster)1