Search in sources :

Example 1 with IRedisCommandResponse

use of com.akaxin.common.netty.IRedisCommandResponse in project openzaly by akaxincom.

the class WritePackage method syncWrite.

public byte[] syncWrite(String action, byte[] byteData) {
    try {
        CoreProto.TransportPackageData.Builder packageDataBuilder = CoreProto.TransportPackageData.newBuilder();
        Map<Integer, String> header = new HashMap<Integer, String>();
        header.put(CoreProto.HeaderKey.SITE_SERVER_VERSION_VALUE, CommandConst.SITE_VERSION);
        packageDataBuilder.putAllHeader(header);
        packageDataBuilder.setData(ByteString.copyFrom(byteData));
        NettyClient2 nettyClient = new NettyClient2();
        nettyClient.connect(AKAXIN_PUSH_ADDRESS, AKAXIN_PUSH_PORT);
        Future<IRedisCommandResponse> future = nettyClient.sendRedisCommand(new RedisCommand().add(CommandConst.PROTOCOL_VERSION).add(action).add(packageDataBuilder.build().toByteArray()));
        IRedisCommandResponse response = future.get(5, TimeUnit.SECONDS);
        nettyClient.disconnect();
        if (response != null && response.isSuccess()) {
            return getPackageBytes(response.getRedisCommand());
        }
        logger.debug("write push to platform finish response={}", response);
    } catch (Exception e) {
        logger.error("sync send package error ", e);
    }
    return null;
}
Also used : NettyClient2(com.akaxin.common.netty.NettyClient2) HashMap(java.util.HashMap) RedisCommand(com.akaxin.common.command.RedisCommand) IRedisCommandResponse(com.akaxin.common.netty.IRedisCommandResponse) ByteString(com.google.protobuf.ByteString)

Example 2 with IRedisCommandResponse

use of com.akaxin.common.netty.IRedisCommandResponse in project openzaly by akaxincom.

the class WritePackage method asyncWrite.

public void asyncWrite(String action, byte[] byteData) {
    try {
        CoreProto.TransportPackageData.Builder packageDataBuilder = CoreProto.TransportPackageData.newBuilder();
        Map<Integer, String> header = new HashMap<Integer, String>();
        header.put(CoreProto.HeaderKey.SITE_SERVER_VERSION_VALUE, CommandConst.SITE_VERSION);
        packageDataBuilder.putAllHeader(header);
        packageDataBuilder.setData(ByteString.copyFrom(byteData));
        NettyClient2 nettyClient = new NettyClient2();
        nettyClient.connect(AKAXIN_PUSH_ADDRESS, AKAXIN_PUSH_PORT);
        Future<IRedisCommandResponse> future = nettyClient.sendRedisCommand(new RedisCommand().add(CommandConst.PROTOCOL_VERSION).add(action).add(packageDataBuilder.build().toByteArray()));
        IRedisCommandResponse response = future.get(5, TimeUnit.SECONDS);
        logger.debug("write push to platform finish response={}", response);
        nettyClient.disconnect();
    } catch (Exception e) {
        logger.error("async send package to platform error", e);
    }
}
Also used : NettyClient2(com.akaxin.common.netty.NettyClient2) HashMap(java.util.HashMap) RedisCommand(com.akaxin.common.command.RedisCommand) IRedisCommandResponse(com.akaxin.common.netty.IRedisCommandResponse) ByteString(com.google.protobuf.ByteString)

Aggregations

RedisCommand (com.akaxin.common.command.RedisCommand)2 IRedisCommandResponse (com.akaxin.common.netty.IRedisCommandResponse)2 NettyClient2 (com.akaxin.common.netty.NettyClient2)2 ByteString (com.google.protobuf.ByteString)2 HashMap (java.util.HashMap)2