All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cn.teleinfo.idpointer.sdk.transport.TransportOnTcpAsync Maven / Gradle / Ivy

Go to download

基于Java语言开发的工业互联网标识解析体系客户端软件开发工具包,应用通过集成 id-pointer-sdk,快速对接标识解析、标识注册、标识维护等功能服务。

The newest version!
package cn.teleinfo.idpointer.sdk.transport;

import cn.teleinfo.idpointer.sdk.core.AbstractRequest;
import cn.teleinfo.idpointer.sdk.exception.IDException;
import io.netty.channel.Channel;
import io.netty.channel.pool.ChannelPool;
import io.netty.channel.pool.ChannelPoolMap;
import io.netty.util.concurrent.Future;

import java.net.InetSocketAddress;
import java.util.concurrent.ExecutionException;

public class TransportOnTcpAsync extends TransportOnTcp {
    public TransportOnTcpAsync(ChannelPoolMap idChannelPoolMap, MessageManager messageManager) {
        super(idChannelPoolMap, messageManager);
    }

    @Override
    public ResponsePromise process(AbstractRequest request, InetSocketAddress inetSocketAddress) throws IDException {
        ChannelPool fixedChannelPool = getIdChannelPoolMap().get(inetSocketAddress);
        Future channelFuture = fixedChannelPool.acquire();
        Channel channel = null;
        try {
            channel = channelFuture.get();
            return getMessageManager().process(request, channel);
        } catch (ExecutionException | InterruptedException e) {
            throw new IDException(IDException.CHANNEL_GET_ERROR, "channel get error", e);
        } finally {
            if (channel != null) {
                fixedChannelPool.release(channel);
            }
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy