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);
}
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);
}
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));
}
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);
}
Aggregations