// test async create
List<String> createPaths =
Arrays.asList("/test/child1/child1", "/test/child2/child2");
List<ZNRecord> createRecords =
Arrays.asList(new ZNRecord("child1"), new ZNRecord("child2"));
boolean[] needCreate = new boolean[createPaths.size()];
Arrays.fill(needCreate, true);
List<List<String>> pathsCreated =
new ArrayList<List<String>>(Collections.<List<String>> nCopies(createPaths.size(),
null));
accessor.create(createPaths,
createRecords,
needCreate,
pathsCreated,
AccessOption.PERSISTENT);
System.out.println("pathsCreated: " + pathsCreated);
// test async set
List<String> setPaths =
Arrays.asList("/test/setChild1/setChild1", "/test/setChild2/setChild2");
List<ZNRecord> setRecords =
Arrays.asList(new ZNRecord("setChild1"), new ZNRecord("setChild2"));
pathsCreated =
new ArrayList<List<String>>(Collections.<List<String>> nCopies(setPaths.size(),
null));
boolean[] success =
accessor.set(setPaths, setRecords, pathsCreated, null, AccessOption.PERSISTENT);
System.out.println("pathsCreated: " + pathsCreated);
System.out.println("setSuccess: " + Arrays.toString(success));
// test async update
List<String> updatePaths =
Arrays.asList("/test/updateChild1/updateChild1", "/test/setChild2/setChild2");
class TestUpdater implements DataUpdater<ZNRecord>
{
final ZNRecord _newData;
public TestUpdater(ZNRecord newData)
{
_newData = newData;
}
@Override
public ZNRecord update(ZNRecord currentData)
{
return _newData;
}
}
List<DataUpdater<ZNRecord>> updaters =
Arrays.asList((DataUpdater<ZNRecord>) new TestUpdater(new ZNRecord("updateChild1")),
(DataUpdater<ZNRecord>) new TestUpdater(new ZNRecord("updateChild2")));
pathsCreated =
new ArrayList<List<String>>(Collections.<List<String>> nCopies(updatePaths.size(),
null));