Search in sources :

Example 21 with BaseResponse

use of com.bonree.brfs.common.net.tcp.BaseResponse in project BRFS by zhangnianli.

the class TcpDiskNodeClient method recover.

@Override
public boolean recover(String path, long fileLength, List<String> fullstates) {
    try {
        FileRecoveryMessage recoveryMessage = new FileRecoveryMessage();
        recoveryMessage.setFilePath(path);
        recoveryMessage.setOffset(fileLength);
        String[] states = new String[fullstates.size()];
        recoveryMessage.setSources(fullstates.toArray(states));
        BaseMessage message = new BaseMessage(DataNodeBootStrap.TYPE_RECOVER_FILE);
        message.setBody(ProtoStuffUtils.serialize(recoveryMessage));
        CompletableFuture<BaseResponse> future = new CompletableFuture<BaseResponse>();
        client.sendMessage(message, new ResponseHandler<BaseResponse>() {

            @Override
            public void handle(BaseResponse response) {
                future.complete(response);
            }

            @Override
            public void error(Throwable e) {
                future.completeExceptionally(e);
            }
        });
        BaseResponse response = future.get();
        if (response != null && response.getCode() == ResponseCode.OK) {
            return true;
        }
    } catch (Exception e) {
        LOG.error("get meta data from file [{}] error", path, e);
    }
    return false;
}
Also used : BaseResponse(com.bonree.brfs.common.net.tcp.BaseResponse) CompletableFuture(java.util.concurrent.CompletableFuture) BaseMessage(com.bonree.brfs.common.net.tcp.BaseMessage) FileRecoveryMessage(com.bonree.brfs.disknode.server.tcp.handler.data.FileRecoveryMessage) IOException(java.io.IOException)

Example 22 with BaseResponse

use of com.bonree.brfs.common.net.tcp.BaseResponse in project BRFS by zhangnianli.

the class TcpDiskNodeClient method openFile.

@Override
public long openFile(String path, long capacity) {
    try {
        OpenFileMessage openFileMessage = new OpenFileMessage();
        openFileMessage.setFilePath(path);
        openFileMessage.setCapacity(capacity);
        BaseMessage message = new BaseMessage(DataNodeBootStrap.TYPE_OPEN_FILE);
        message.setBody(ProtoStuffUtils.serialize(openFileMessage));
        CompletableFuture<BaseResponse> future = new CompletableFuture<BaseResponse>();
        client.sendMessage(message, new ResponseHandler<BaseResponse>() {

            @Override
            public void handle(BaseResponse response) {
                future.complete(response);
            }

            @Override
            public void error(Throwable e) {
                future.completeExceptionally(e);
            }
        });
        BaseResponse response = future.get();
        if (response != null && response.getCode() == ResponseCode.OK) {
            return Longs.fromByteArray(response.getBody());
        }
    } catch (Exception e) {
        LOG.error("open file error", e);
    }
    return -1;
}
Also used : BaseResponse(com.bonree.brfs.common.net.tcp.BaseResponse) CompletableFuture(java.util.concurrent.CompletableFuture) BaseMessage(com.bonree.brfs.common.net.tcp.BaseMessage) OpenFileMessage(com.bonree.brfs.disknode.server.tcp.handler.data.OpenFileMessage) IOException(java.io.IOException)

Aggregations

BaseResponse (com.bonree.brfs.common.net.tcp.BaseResponse)22 BaseMessage (com.bonree.brfs.common.net.tcp.BaseMessage)13 IOException (java.io.IOException)13 CompletableFuture (java.util.concurrent.CompletableFuture)11 RecordFileWriter (com.bonree.brfs.disknode.data.write.RecordFileWriter)4 WriteWorker (com.bonree.brfs.disknode.data.write.worker.WriteWorker)4 WriteFileMessage (com.bonree.brfs.disknode.server.tcp.handler.data.WriteFileMessage)3 File (java.io.File)3 InetSocketAddress (java.net.InetSocketAddress)3 SocketAddress (java.net.SocketAddress)3 TcpClientConfig (com.bonree.brfs.common.net.tcp.client.TcpClientConfig)2 ReadObject (com.bonree.brfs.common.net.tcp.file.ReadObject)2 AsyncFileReaderCreateConfig (com.bonree.brfs.common.net.tcp.file.client.AsyncFileReaderCreateConfig)2 FileContentPart (com.bonree.brfs.common.net.tcp.file.client.FileContentPart)2 Service (com.bonree.brfs.common.service.Service)2 TcpDiskNodeClient (com.bonree.brfs.disknode.client.TcpDiskNodeClient)2 DeleteFileMessage (com.bonree.brfs.disknode.server.tcp.handler.data.DeleteFileMessage)2 FileRecoveryMessage (com.bonree.brfs.disknode.server.tcp.handler.data.FileRecoveryMessage)2 ListFileMessage (com.bonree.brfs.disknode.server.tcp.handler.data.ListFileMessage)2 OpenFileMessage (com.bonree.brfs.disknode.server.tcp.handler.data.OpenFileMessage)2