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());
}
}
});
}
Aggregations