Search in sources :

Example 1 with StorageNameNode

use of com.bonree.brfs.duplication.storagename.StorageNameNode in project BRFS by zhangnianli.

the class OpenStorageNameMessageHandler method handle.

@Override
public void handle(StorageNameMessage msg, HandleResultCallback callback) {
    StorageNameNode node = storageNameManager.findStorageName(msg.getName());
    HandleResult result = new HandleResult();
    if (node == null) {
        result.setSuccess(false);
        result.setData(StringUtils.toUtf8Bytes("errorCode:225"));
    } else {
        result.setSuccess(true);
        byte[] nodeBytes = null;
        try {
            nodeBytes = ProtoStuffUtils.serialize(node);
        } catch (IOException e) {
            e.printStackTrace();
        }
        result.setData(nodeBytes);
    }
    callback.completed(result);
}
Also used : StorageNameNode(com.bonree.brfs.duplication.storagename.StorageNameNode) HandleResult(com.bonree.brfs.duplication.server.handler.HandleResult) IOException(java.io.IOException)

Example 2 with StorageNameNode

use of com.bonree.brfs.duplication.storagename.StorageNameNode in project BRFS by zhangnianli.

the class DataDispatcher method addFileNode.

public void addFileNode(FileNode fileNode) {
    StorageNameNode storageNameNode = storageNameManager.findStorageName(fileNode.getStorageName());
    storageNameFiles.put(storageNameNode.getName(), fileNode);
}
Also used : StorageNameNode(com.bonree.brfs.duplication.storagename.StorageNameNode)

Example 3 with StorageNameNode

use of com.bonree.brfs.duplication.storagename.StorageNameNode 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)

Example 4 with StorageNameNode

use of com.bonree.brfs.duplication.storagename.StorageNameNode in project BRFS by zhangnianli.

the class CreateStorageNameMessageHandler method handle.

@Override
public void handle(StorageNameMessage msg, HandleResultCallback callback) {
    StorageNameNode node = storageNameManager.createStorageName(msg.getName(), msg.getReplicas(), msg.getTtl());
    HandleResult result = new HandleResult();
    if (node == null) {
        result.setSuccess(false);
        result.setData(StringUtils.toUtf8Bytes("errorCode:222"));
    } else {
        result.setSuccess(true);
        byte[] nodeBytes = null;
        try {
            nodeBytes = ProtoStuffUtils.serialize(node);
        } catch (IOException e) {
            e.printStackTrace();
        }
        result.setData(nodeBytes);
    }
    callback.completed(result);
}
Also used : StorageNameNode(com.bonree.brfs.duplication.storagename.StorageNameNode) HandleResult(com.bonree.brfs.duplication.server.handler.HandleResult) IOException(java.io.IOException)

Aggregations

StorageNameNode (com.bonree.brfs.duplication.storagename.StorageNameNode)4 HandleResult (com.bonree.brfs.duplication.server.handler.HandleResult)2 IOException (java.io.IOException)2 FileNode (com.bonree.brfs.duplication.coordinator.FileNode)1