private volatile static ConfigDataHandlerFactory cdhf;
private static final long DIAMOND_FIRST_DATA_TIMEOUT=15*1000;
public static Object subscribePersistentData(String subscriberName, String dataId, final DataListener listener) {
cdhf = new DefaultConfigDataHandlerFactory();
ConfigDataHandler matrixHandler = cdhf.getConfigDataHandler(dataId, null);
String datas = matrixHandler.getData(DIAMOND_FIRST_DATA_TIMEOUT, ConfigDataHandler.FIRST_CACHE_THEN_SERVER_STRATEGY); //ȡ������Ϣ��Ĭ�ϳ�ʱʱ��Ϊ30��
//����ȥ�����µı�������
log.warn(dataId + "'s firstData=" + datas);
if (datas != null) {
try {
listener.onDataReceiveAtRegister(datas);
} catch (Throwable t) {
//��֤��ʹ�״δ���dataId�����쳣��listenerҲһ���ᱻע�ᣬҵ����Ȼ���յ���������
log.error("onDataReceiveAtRegister�׳��쳣��dataId:" + dataId, t);
}
}
matrixHandler.addListener(new ConfigDataListener() {
@Override
public void onDataRecieved(String dataId, String data) {
log.info("recieve data,data id:"+dataId+" data:"+data);
listener.onDataReceive(data);
}