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

net.oschina.thrift.client.support.pool.PooledTServiceClient Maven / Gradle / Ivy

There is a newer version: 0.0.5
Show newest version
package net.oschina.thrift.client.support.pool;

import net.oschina.thrift.client.support.config.TSConfig;
import org.apache.thrift.TServiceClient;
import org.apache.thrift.transport.TSocket;
import org.apache.thrift.transport.TTransport;

/**
 * @author dw_xiajiqiu1
 * @time 2017/6/19 9:28
 */
public class PooledTServiceClient {

    protected final TServiceClient serviceClient;

    protected final TTransport transport;

    protected final TSConfig config;

    /** 是否是有效的连接 */
    protected volatile boolean discard = false;

    /** 最后一次访问时间 */
    protected volatile long lastAccessTime;

    /** 创建时间 */
    protected final long createTime;

    protected TSocket socket;

    public PooledTServiceClient(TServiceClient serviceClient, TTransport transport, TSConfig config) {
        this.serviceClient = serviceClient;
        this.transport = transport;
        this.config = config;
        this.createTime = System.currentTimeMillis();
    }

    public PooledTServiceClient(TServiceClient serviceClient, TTransport transport, TSConfig config, TSocket socket) {
        this.serviceClient = serviceClient;
        this.transport = transport;
        this.config = config;
        this.socket = socket;
        this.createTime = System.currentTimeMillis();
    }

    public TServiceClient getServiceClient() {
        return serviceClient;
    }

    public TTransport getTransport() {
        return transport;
    }

    public TSConfig getConfig() {
        return config;
    }

    public TSocket getTSocket() {
        return socket;
    }

    public void setTSocket(TSocket tSocket) {
        this.socket = tSocket;
    }

    public TSocket getSocket() {
        return socket;
    }

    public void setSocket(TSocket socket) {
        this.socket = socket;
    }

    public boolean isDiscard() {
        return discard;
    }

    public void discard() {
        this.discard = true;
    }

    public long getLastAccessTime() {
        return lastAccessTime;
    }

    public void setLastAccessTime(long lastAccessTime) {
        this.lastAccessTime = lastAccessTime;
    }

    public long getCreateTime() {
        return createTime;
    }

    @Override
    public String toString() {
        return config.getHost() + ":" + config.getPort() + ":" + config.getTimeout();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy