Search in sources :

Example 1 with FileNode

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();
    }
}
Also used : FileNodeStorer(com.bonree.brfs.duplication.coordinator.FileNodeStorer) CuratorFramework(org.apache.curator.framework.CuratorFramework) ExponentialBackoffRetry(org.apache.curator.retry.ExponentialBackoffRetry) RetryPolicy(org.apache.curator.RetryPolicy) FileNode(com.bonree.brfs.duplication.coordinator.FileNode)

Example 2 with FileNode

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));
}
Also used : StorageNameNode(com.bonree.brfs.duplication.storagename.StorageNameNode) FileNode(com.bonree.brfs.duplication.coordinator.FileNode)

Aggregations

FileNode (com.bonree.brfs.duplication.coordinator.FileNode)2 FileNodeStorer (com.bonree.brfs.duplication.coordinator.FileNodeStorer)1 StorageNameNode (com.bonree.brfs.duplication.storagename.StorageNameNode)1 RetryPolicy (org.apache.curator.RetryPolicy)1 CuratorFramework (org.apache.curator.framework.CuratorFramework)1 ExponentialBackoffRetry (org.apache.curator.retry.ExponentialBackoffRetry)1