use of com.bonree.brfs.duplication.coordinator.FileNode in project BRFS by zhangnianli.
the class TestStorer method main.
public static void main(String[] args) throws Exception {
RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 3);
CuratorFramework client = CuratorFrameworkFactory.newClient("122.11.47.17:2181", 5 * 1000, 30 * 1000, retryPolicy);
client.start();
client.blockUntilConnected();
FileNodeStorer storer = new ZkFileNodeStorer(client.usingNamespace("test"));
FileNode node = new FileNode();
node.setName("file_node_1");
node.setServiceId("ser_1");
node.setStorageName("sn_1");
node.setDuplicates(new int[] { 1, 2, 3 });
storer.save(node);
FileNode node2 = storer.getFileNode("file_node_1");
System.out.println("node2--" + node2.getName());
node2.setServiceId("ser_2");
storer.update("file_node_1", node2);
List<FileNode> nodeList = storer.listFileNodes();
for (FileNode nd : nodeList) {
System.out.println("list--" + nd.getName() + ", " + nd.getServiceId());
storer.delete(nd.getName());
}
synchronized (client) {
client.wait();
}
}
use of com.bonree.brfs.duplication.coordinator.FileNode in project BRFS by zhangnianli.
the class DataDispatcher method write.
public void write(int storageId, byte[] datas, DataHandleCallback<DataWriteResult> callback) {
StorageNameNode storageNameNode = storageNameManager.findStorageName(storageId);
Set<FileNode> fileNodes = storageNameFiles.get(storageNameNode.getName());
if (fileNodes.isEmpty()) {
FileNode fileNode = new FileNode();
fileNode.setName(FileNameBuilder.createFile());
fileNode.setStorageName(storageNameNode.getName());
// TODO get service id
fileNode.setServiceId("");
fileNode.setDuplicates(duplicationSelector.getDuplication(storageNameNode.getReplicates()));
boolean published = fileCoordinator.publish(fileNode);
if (published) {
fileNodes.add(fileNode);
}
}
FileNode fileNode = fileNodes.iterator().next();
dataEmitter.emit(datas, fileNode, new EmitCallback(storageNameNode.getName(), fileNode, callback));
}
Aggregations