public MediaSubscribeManager(){
// 注册一下事件处理
ComputeFunction function = new ComputeFunction<String, String>() {
public String apply(final String key, String oldValue) {
FindMediaEvent event = new FindMediaEvent();
event.setDataId(key);
try {
Object obj = arbitrateCommmunicationClient.callManager(event);
if (obj != null && obj instanceof String) {
final String value = (String) obj;
if (!StringUtils.equalsIgnoreCase(oldValue, value)) {
// 触发一下变化
executor.submit(new Runnable() {
public void run() {
Set<SubscribeCallback> callbacks = getCallbacks(key, null);
for (SubscribeCallback callback : callbacks) {
callback.callback(value);
}
}
});
}
return value;
} else {
throw new ConfigException("No Such dataId[" + key + "]");
}
} catch (Exception e) {
logger.error("call_manager_error", event.toString(), e);
}
// 其他情况直接返回内存中的旧值
return oldValue;
}