com.gateway.connector.tcp.client.ProtoReq Maven / Gradle / Ivy
package com.gateway.connector.tcp.client;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.gateway.connector.proto.Proto;
import com.gateway.connector.tcp.client.GateWayApi.PRspCallBack;
public class ProtoReq {
private Proto reqProto;
private Proto rspProto;
public Proto getReqProto() {
return reqProto;
}
public void setReqProto(Proto reqProto) {
this.reqProto = reqProto;
}
public Proto getRspProto() {
return rspProto;
}
public void setRspProto(Proto rspProto) {
this.rspProto = rspProto;
}
private CountDownLatch cdl = new CountDownLatch(1);
private final Logger logger = LoggerFactory.getLogger(this.getClass());
public boolean cwait(long timeout) {
try {
this.timeOut=timeout;
syncFlag=true;
return cdl.await(timeout, TimeUnit.MILLISECONDS);
} catch (Exception e) {
logger.error("seq:{},cwait exception",reqProto.getSeq());
}
return false;
}
public void cnotify() {
cdl.countDown();
}
private PRspCallBack rspCallBack;
public PRspCallBack getRspCallBack() {
return rspCallBack;
}
public void setRspCallBack(PRspCallBack rspCallBack) {
this.rspCallBack = rspCallBack;
}
public long getBeginTime() {
return beginTime;
}
public void setBeginTime(long beginTime) {
this.beginTime = beginTime;
}
public long getTimeOut() {
return timeOut;
}
public void setTimeOut(long timeOut) {
this.timeOut = timeOut;
}
public void notifyRspCallBack()
{
if (rspCallBack != null) {
rspCallBack.onRspMessage(rspProto);
}
}
private boolean syncFlag = false;
public boolean isSyncFlag() {
return syncFlag;
}
public long beginTime;
public long timeOut ;
}