fix协议介绍6-重发消息

35 篇文章 0 订阅
34 篇文章 16 订阅

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.


Added  FIX.2.7

Expand Components | Collapse Components

  Field or Component Field Name FIXML name Req'd Comments Depr.
Component StandardHeader BaseHeader

MsgType = 2

 
7 BeginSeqNo      
16 EndSeqNo      
Component StandardTrailer      

重发消息实现:

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;
	}

}

处理逻辑:略


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

hxpjava1

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值