use of com.continuuity.weave.zookeeper.NodeData in project weave by continuuity.
the class ZKDiscoveryService method createServiceLoader.
/**
* Creates a CacheLoader for creating live Iterable for watching instances changes for a given service.
*/
private CacheLoader<String, ServiceDiscovered> createServiceLoader() {
return new CacheLoader<String, ServiceDiscovered>() {
@Override
public ServiceDiscovered load(String service) throws Exception {
final DefaultServiceDiscovered serviceDiscovered = new DefaultServiceDiscovered(service);
final String serviceBase = "/" + service;
// Watch for children changes in /service
ZKOperations.watchChildren(zkClient, serviceBase, new ZKOperations.ChildrenCallback() {
@Override
public void updated(NodeChildren nodeChildren) {
// Fetch data of all children nodes in parallel.
List<String> children = nodeChildren.getChildren();
List<OperationFuture<NodeData>> dataFutures = Lists.newArrayListWithCapacity(children.size());
for (String child : children) {
dataFutures.add(zkClient.getData(serviceBase + "/" + child));
}
// Update the service map when all fetching are done.
final ListenableFuture<List<NodeData>> fetchFuture = Futures.successfulAsList(dataFutures);
fetchFuture.addListener(new Runnable() {
@Override
public void run() {
ImmutableSet.Builder<Discoverable> builder = ImmutableSet.builder();
for (NodeData nodeData : Futures.getUnchecked(fetchFuture)) {
// For successful fetch, decode the content.
if (nodeData != null) {
Discoverable discoverable = DiscoverableAdapter.decode(nodeData.getData());
if (discoverable != null) {
builder.add(discoverable);
}
}
}
serviceDiscovered.setDiscoverables(builder.build());
}
}, Threads.SAME_THREAD_EXECUTOR);
}
});
return serviceDiscovered;
}
};
}
use of com.continuuity.weave.zookeeper.NodeData in project weave by continuuity.
the class ControllerTest method getController.
private WeaveController getController(ZKClient zkClient, RunId runId) {
WeaveController controller = new AbstractWeaveController(runId, zkClient, ImmutableList.<LogHandler>of()) {
@Override
public void kill() {
// No-op
}
@Override
protected void instanceNodeUpdated(NodeData nodeData) {
// No-op
}
@Override
protected void stateNodeUpdated(StateNode stateNode) {
// No-op
}
@Override
public ResourceReport getResourceReport() {
return null;
}
};
controller.startAndWait();
return controller;
}
Aggregations