net.oschina.thrift.client.support.pool.PooledTServiceClient Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of thrift-client-support Show documentation
Show all versions of thrift-client-support Show documentation
thrift-client-support is an sdk for easy use thrift connect to the thrift server.
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