// Path: trpc-core/src/main/java/com/github/sofn/trpc/core/config/ThriftServerInfo.java
// @Data
// @AllArgsConstructor
// @EqualsAndHashCode
// public class ThriftServerInfo {
//     private String ip;
//     private int port;
// 
//     public ThriftServerInfo(String ipPort) {
//         checkNotNull(ipPort);
//         String[] splits = ipPort.split(":");
//         checkArgument(splits.length == 2, "ipPort format error");
//         this.ip = splits[0];
//         this.port = NumberUtils.toInt(splits[1]);
//     }
// 
//     @Override
//     public String toString() {
//         return ip + ":" + port;
//     }
// 
//     public static ThriftServerInfo parse(String info) {
//         String[] splits = StringUtils.split(info, ":");
//         if (splits == null || splits.length != 2) {
//             return null;
//         }
//         return new ThriftServerInfo(splits[0], NumberUtils.toInt(splits[1]));
//     }
// }
// 
// Path: trpc-core/src/main/java/com/github/sofn/trpc/core/exception/TRpcException.java
// public class TRpcException extends RuntimeException {
// 
//     public TRpcException(Exception e) {
//         super(e);
//     }
// 
//     public TRpcException(String s, Exception e) {
//         super(s, e);
//     }
// }
// 
// Path: trpc-core/src/main/java/com/github/sofn/trpc/core/utils/ClassNameUtils.java
// public class ClassNameUtils {
// 
//     public static String getClassName(Class clazz) {
//         return clazz.getName();
//     }
// 
//     public static String getOuterClassName(Class clazz) {
//         int spliterIndex = clazz.getName().lastIndexOf("$");
//         return spliterIndex > 0 ? clazz.getName().substring(0, spliterIndex) : clazz.getName();
//     }
// }


import com.github.sofn.trpc.core.config.ThriftServerInfo;
import com.github.sofn.trpc.core.exception.TRpcException;
import com.github.sofn.trpc.core.utils.ClassNameUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.thrift.async.TAsyncClient;
import org.apache.thrift.async.TAsyncClientManager;
import org.apache.thrift.protocol.TBinaryProtocol;
import org.apache.thrift.protocol.TMultiplexedProtocol;
import org.apache.thrift.protocol.TProtocol;
import org.apache.thrift.protocol.TProtocolFactory;
import org.apache.thrift.transport.TNonblockingSocket;
import org.apache.thrift.transport.TNonblockingTransport;
import java.nio.channels.UnresolvedAddressException;
package com.github.sofn.trpc.client.client;



/**
 * @author sofn
 * @version 1.0 Created at: 2016-09-24 19:32
 */
@Slf4j
public class AsyncTrpcClient extends AbstractTrpcClient<TAsyncClient> {
    private TNonblockingTransport transport;
    private TAsyncClientManager clientManager;
    private volatile boolean isOpen = true;

    public AsyncTrpcClient(ThriftServerInfo serverInfo) {
        super(serverInfo);
    }

    @Override
    public void open() {
        try {
            //异步调用管理器
            this.clientManager = new TAsyncClientManager();
            //设置传输通道，调用非阻塞IO。
// Path: trpc-core/src/main/java/com/github/sofn/trpc/core/config/ThriftServerInfo.java
// @Data
// @AllArgsConstructor
// @EqualsAndHashCode
// public class ThriftServerInfo {
//     private String ip;
//     private int port;
// 
//     public ThriftServerInfo(String ipPort) {
//         checkNotNull(ipPort);
//         String[] splits = ipPort.split(":");
//         checkArgument(splits.length == 2, "ipPort format error");
//         this.ip = splits[0];
//         this.port = NumberUtils.toInt(splits[1]);
//     }
// 
//     @Override
//     public String toString() {
//         return ip + ":" + port;
//     }
// 
//     public static ThriftServerInfo parse(String info) {
//         String[] splits = StringUtils.split(info, ":");
//         if (splits == null || splits.length != 2) {
//             return null;
//         }
//         return new ThriftServerInfo(splits[0], NumberUtils.toInt(splits[1]));
//     }
// }
// 
// Path: trpc-core/src/main/java/com/github/sofn/trpc/core/exception/TRpcException.java
// public class TRpcException extends RuntimeException {
// 
//     public TRpcException(Exception e) {
//         super(e);
//     }
// 
//     public TRpcException(String s, Exception e) {
//         super(s, e);
//     }
// }
// 
// Path: trpc-core/src/main/java/com/github/sofn/trpc/core/utils/ClassNameUtils.java
// public class ClassNameUtils {
// 
//     public static String getClassName(Class clazz) {
//         return clazz.getName();
//     }
// 
//     public static String getOuterClassName(Class clazz) {
//         int spliterIndex = clazz.getName().lastIndexOf("$");
//         return spliterIndex > 0 ? clazz.getName().substring(0, spliterIndex) : clazz.getName();
//     }
// }


// Path: trpc-client/src/main/java/com/github/sofn/trpc/client/client/AsyncTrpcClient.java
import com.github.sofn.trpc.core.config.ThriftServerInfo;
import com.github.sofn.trpc.core.exception.TRpcException;
import com.github.sofn.trpc.core.utils.ClassNameUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.thrift.async.TAsyncClient;
import org.apache.thrift.async.TAsyncClientManager;
import org.apache.thrift.protocol.TBinaryProtocol;
import org.apache.thrift.protocol.TMultiplexedProtocol;
import org.apache.thrift.protocol.TProtocol;
import org.apache.thrift.protocol.TProtocolFactory;
import org.apache.thrift.transport.TNonblockingSocket;
import org.apache.thrift.transport.TNonblockingTransport;
import java.nio.channels.UnresolvedAddressException;

package com.github.sofn.trpc.client.client;



/**
 * @author sofn
 * @version 1.0 Created at: 2016-09-24 19:32
 */
@Slf4j
public class AsyncTrpcClient extends AbstractTrpcClient<TAsyncClient> {
    private TNonblockingTransport transport;
    private TAsyncClientManager clientManager;
    private volatile boolean isOpen = true;

    public AsyncTrpcClient(ThriftServerInfo serverInfo) {
        super(serverInfo);
    }

    @Override
    public void open() {
        try {
            //异步调用管理器
            this.clientManager = new TAsyncClientManager();
            //设置传输通道，调用非阻塞IO。
            this.transport = new TNonblockingSocket(this.serverInfo.getIp(), this.serverInfo.getPort(), 1000);