Search in sources :

Example 1 with WriteResult

use of com.bonree.brfs.disknode.client.WriteResult in project BRFS by zhangnianli.

the class WriteMessageHandler method handle.

@Override
public void handle(DiskMessage msg, HandleResultCallback callback) {
    HandleResult handleResult = new HandleResult();
    try {
        LOG.debug("WRITE [{}], data length[{}]", msg.getFilePath(), msg.getData().length);
        nodeManager.writeAsync(msg.getFilePath(), msg.getData(), new InputEventCallback() {

            @Override
            public void completeError(Throwable t) {
                handleResult.setSuccess(false);
                handleResult.setCause(t);
                callback.completed(handleResult);
            }

            @Override
            public void complete(InputResult result) {
                handleResult.setSuccess(true);
                WriteResult writeResult = new WriteResult();
                writeResult.setOffset(result.getOffset());
                writeResult.setSize(result.getSize());
                try {
                    handleResult.setData(ProtoStuffUtils.serialize(writeResult));
                } catch (IOException e) {
                    e.printStackTrace();
                }
                callback.completed(handleResult);
            }
        });
    } catch (Exception e) {
        handleResult.setSuccess(false);
        handleResult.setCause(e);
        callback.completed(handleResult);
    }
}
Also used : InputResult(com.bonree.brfs.disknode.InputResult) WriteResult(com.bonree.brfs.disknode.client.WriteResult) InputEventCallback(com.bonree.brfs.disknode.InputEventCallback) HandleResult(com.bonree.brfs.disknode.server.handler.HandleResult) IOException(java.io.IOException) IOException(java.io.IOException)

Example 2 with WriteResult

use of com.bonree.brfs.disknode.client.WriteResult in project BRFS by zhangnianli.

the class DataEmitter method emit.

public void emit(byte[] data, FileNode fileNode, WriteCallback callback) {
    int[] duplicates = fileNode.getDuplicates();
    DiskNodeClient[] clients = new DiskNodeClient[duplicates.length];
    for (int i = 0; i < duplicates.length; i++) {
        if (!clientCaches.containsKey(duplicates[i])) {
            DiskNodeClient client = new HttpDiskNodeClient("localhost", 8080);
            clientCaches.put(duplicates[i], client);
        }
        clients[i] = clientCaches.get(duplicates[i]);
    }
    for (DiskNodeClient client : clients) {
        ResultGather gather = new ResultGather(clients.length, callback);
        ListenableFuture<WriteResult> f = execs.submit(new WriteTask(client, fileNode, data));
        Futures.addCallback(f, gather, execs);
    }
}
Also used : DiskNodeClient(com.bonree.brfs.disknode.client.DiskNodeClient) HttpDiskNodeClient(com.bonree.brfs.disknode.client.HttpDiskNodeClient) HttpDiskNodeClient(com.bonree.brfs.disknode.client.HttpDiskNodeClient) WriteResult(com.bonree.brfs.disknode.client.WriteResult)

Aggregations

WriteResult (com.bonree.brfs.disknode.client.WriteResult)2 InputEventCallback (com.bonree.brfs.disknode.InputEventCallback)1 InputResult (com.bonree.brfs.disknode.InputResult)1 DiskNodeClient (com.bonree.brfs.disknode.client.DiskNodeClient)1 HttpDiskNodeClient (com.bonree.brfs.disknode.client.HttpDiskNodeClient)1 HandleResult (com.bonree.brfs.disknode.server.handler.HandleResult)1 IOException (java.io.IOException)1