FIX.5.0SP2 Message
ResendRequest [type '2']
The resend request is sent by the receiving application to initiate the retransmission of messages. This function is utilized if a sequence number gap is detected, if the receiving application lost a message, or as a function of the initialization process.
重发消息实现:
package cs.mina.codec.msg;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import cs.mina.exception.InValidDataException;
/*
*@author(huangxiaoping)
*@date 2013-11-28
*/
public class ResendRequestMsg extends BaseMsg {
private Tag beginSeqNo = new Tag("7", "SeqNum", true);
private Tag endSeqNo = new Tag("16", "SeqNum", true);
private Set<String> tagIdsSet = new HashSet<String>();
public ResendRequestMsg() {
this.getHeadEntity().getMsgType().setTagValue("2");
tagIdsSet.add("7");
tagIdsSet.add("16");
this.getBodyEntity().getBodyTagList().add(beginSeqNo);
this.getBodyEntity().getBodyTagList().add(endSeqNo);
}
@Override
public void decodeBody() {
Set<String> already=new HashSet<String>();
String[] bodyItems=this.body.split(BaseMsg.SOH);
if(bodyItems.length==1&&bodyItems[0].equals("")){
return;
}
for(int i=0;i<bodyItems.length;i++){
String[]tagItems=bodyItems[i].split("=");
if(tagItems.length!=2){
throw new InValidDataException("消息格式错误");
}
String tagId=tagItems[0];
if(already.contains(tagId)){
throw new InValidDataException("消息格式错误");
}
already.add(tagId);
if(this.tagIdsSet.contains(tagId)){
List<Tag> tagList=this.bodyEntity.getBodyTagList();
for(int j=0;j<tagList.size();j++){
Tag tag=tagList.get(j);
if(tag.getTagId().equals(tagId)){
tag.setTagValue(tagItems[1]);
break;
}
}
}else{
throw new InValidDataException("消息格式错误,"+tagId+"不在消息体内");
}
}
}
@Override
public void validate() {
this.headEntity.validate();
List<Tag> bodyTagList=this.bodyEntity.getBodyTagList();
for(int i=0;i<bodyTagList.size();i++){
bodyTagList.get(i).validate();
}
this.tailerEntity.validate();
}
public Tag getBeginSeqNo() {
return beginSeqNo;
}
public void setBeginSeqNo(Tag beginSeqNo) {
this.beginSeqNo = beginSeqNo;
}
public Tag getEndSeqNo() {
return endSeqNo;
}
public void setEndSeqNo(Tag endSeqNo) {
this.endSeqNo = endSeqNo;
}
public Set<String> getTagIdsSet() {
return tagIdsSet;
}
public void setTagIdsSet(Set<String> tagIdsSet) {
this.tagIdsSet = tagIdsSet;
}
}
处理逻辑:略