org.I0Itec.zkclient.IZkDataListener Java Examples

The following examples show how to use org.I0Itec.zkclient.IZkDataListener. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ZkClientProxy.java    From jeesuite-config with Apache License 2.0 6 votes vote down vote up
public void subscribeDataChanges(ConfigcenterContext context,String dataPath) {
	zkClient.subscribeDataChanges(dataPath, new IZkDataListener() {
		@Override
		public void handleDataDeleted(String arg0) throws Exception {}
		
		@Override
		public void handleDataChange(String path, Object data) throws Exception {
			if(data == null || StringUtils.isBlank(data.toString()))return;
			try {						
				Map<String, Object> changeDatas = JsonUtils.toObject(data.toString(),Map.class);
				context.updateConfig(changeDatas);
			} catch (Exception e) {
				logger.error("updateConfig error",e);
			}
		}
	});
}
 
Example #2
Source File: ZkImpl.java    From strimzi-kafka-operator with Apache License 2.0 6 votes vote down vote up
@Override
public Future<Zk> watchData(String path, Handler<AsyncResult<byte[]>> watcher) {
    Promise<Zk> result = Promise.promise();
    workerPool().executeBlocking(
        future -> {
            try {
                IZkDataListener listener = new DataWatchAdapter(watcher);
                dataWatches.put(path, listener);
                zookeeper.subscribeDataChanges(path, listener);
                future.complete();
            } catch (Throwable t) {
                future.fail(t);
            }
        },
        ar -> {
            log("watchData").handle(ar);
            if (ar.succeeded()) {
                result.complete(this);
            } else {
                result.fail(ar.cause());
            }
        });
    return result.future();
}
 
Example #3
Source File: ZkImpl.java    From strimzi-kafka-operator with Apache License 2.0 6 votes vote down vote up
@Override
public Zk unwatchData(String path) {
    workerPool().executeBlocking(
        future -> {
            try {
                IZkDataListener listener = dataWatches.remove(path);
                if (listener != null) {
                    zookeeper.unsubscribeDataChanges(path, listener);
                }
                future.complete();
            } catch (Throwable t) {
                future.fail(t);
            }
        },
        log("unwatchData"));
    return this;
}
 
Example #4
Source File: ZKConfigHandler.java    From sumk with Apache License 2.0 5 votes vote down vote up
public static NamePairs readAndListen(String zkUrl, String path, IZkDataListener listener) {
	ZkClient client = ZkClientHelper.getZkClient(zkUrl);
	if (!client.exists(path)) {
		return null;
	}
	String data = ZkClientHelper.data2String(client.readData(path));
	if (listener != null) {
		client.subscribeDataChanges(path, listener);
	}
	return new NamePairs(data);
}
 
Example #5
Source File: ZkLeaderElector.java    From samza with Apache License 2.0 5 votes vote down vote up
@VisibleForTesting
public ZkLeaderElector(String processorIdStr,
                       ZkUtils zkUtils,
                       IZkDataListener previousProcessorChangeListener) {
  this.processorIdStr = processorIdStr;
  this.zkUtils = zkUtils;
  this.keyBuilder = zkUtils.getKeyBuilder();
  this.hostName = getHostName();
  this.previousProcessorChangeListener = previousProcessorChangeListener;
}
 
Example #6
Source File: ZooKeeperClientImpl.java    From light-4j with Apache License 2.0 4 votes vote down vote up
@Override
public void subscribeDataChanges(String path, IZkDataListener listener) {
    zkClient.subscribeDataChanges(path, listener);
}
 
Example #7
Source File: ZooKeeperClientImpl.java    From light-4j with Apache License 2.0 4 votes vote down vote up
@Override
public void unsubscribeDataChanges(String path, IZkDataListener dataListener) {
    zkClient.unsubscribeDataChanges(path, dataListener);
}
 
Example #8
Source File: ZkUtils.java    From samza with Apache License 2.0 4 votes vote down vote up
public void unsubscribeDataChanges(String path, IZkDataListener dataListener) {
  zkClient.unsubscribeDataChanges(path, dataListener);
}
 
Example #9
Source File: ZkUtils.java    From samza with Apache License 2.0 4 votes vote down vote up
public void subscribeDataChanges(String path, IZkDataListener dataListener) {
  zkClient.subscribeDataChanges(path, dataListener);
  metrics.subscriptions.inc();
}
 
Example #10
Source File: ZkClientZkClient.java    From light-task-scheduler with Apache License 2.0 4 votes vote down vote up
protected void addTargetDataListener(String path, IZkDataListener listener) {
    zkClient.subscribeDataChanges(path, listener);
}
 
Example #11
Source File: ZkClientZkClient.java    From light-task-scheduler with Apache License 2.0 4 votes vote down vote up
protected void removeTargetDataListener(String path, IZkDataListener listener) {
    zkClient.unsubscribeDataChanges(path, listener);
}
 
Example #12
Source File: FakePropertyStore.java    From incubator-pinot with Apache License 2.0 4 votes vote down vote up
@Override
public void subscribeDataChanges(String path, IZkDataListener listener) {
  _listener = listener;
}
 
Example #13
Source File: ZooKeeperClient.java    From light-4j with Apache License 2.0 votes vote down vote up
void subscribeDataChanges(String path, IZkDataListener listener); 
Example #14
Source File: ZooKeeperClient.java    From light-4j with Apache License 2.0 votes vote down vote up
void unsubscribeDataChanges(String path, IZkDataListener dataListener);