目录
4.0 逻辑树
4.1 数据加载器 -> 启动类
4.2 实体类 -> 要操作的数据库表
4.3 mappers -> l
4.4 查询数据库中未被成交的委托单 -> service 和 serviceimpl 合在一起
4.5 使用disruptor 把数据分配给cpu 处理 -> for 循环 entrustOrders
4.6 数据转换 -> 多属性实体类 解耦 转成只用使用的属性的实体类
4.7 为 配置类 加载 依赖
4.8 yml文件配置
4.9 nacos-server:8848/nacos/#/login 文件配置
4.10 初始化数据启动类完整代码
4.11 数据初始化 最终分配处理
1. ringbuffer 构建完成
2. disraptor 构建完成
3. 数据初始化 -> 调用 ringbuffer , disraptor
@Overridepublic void args) throws Exception { // 表示 match 一启动 就会执行这个
}
match-service -> domain -> EntrustOrder
match-service -> resources -> mappers -> EntrustOrderMapper
List<EntrustOrder> entrustOrders = entrustOrderMapper.selectList(new LambdaQueryWrapper<EntrustOrder>().eq(EntrustOrder::getStatus, 0).orderByAsc(EntrustOrder::getCreated));
StopWatch stopWatch = new StopWatch() ;stopWatch.start();for (EntrustOrder entrustOrder : entrustOrders) {ustOrder2Order(entrustOrder)); // 往ringbuffer 中放 // ustOrder2Order 数据转换} // ustOrder2Order(entrustOrder) 是数据转换 就是从entrustOrder 筛选出 Order 需要的属性数据stopWatch.stop();long lastTaskTimeMillis = LastTaskTimeMillis();
ample.domain.EntrustOrder;
ums.OrderDirection;
del.Order;public class BeanUtils {/*** 将EntrustOrder 转化为我们的Order* @param entrustOrder* @return*/public static Order entrustOrder2Order(EntrustOrder entrustOrder) {Order order = new Order();order.Id().toString());order.Price());order.Volume().Deal())); // 交易的数量= 总数量- 已经成交的数量order.Symbol());order.Type().intValue()));order.Created().getTime());return order ;}
}
ps: @ConfigurationProperties(prefix = "spring.match") 这种配置类
<!-- 在common 中 配置文件处理--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-configuration-processor</artifactId></dependency>
spring:match: symbols: # 根据 MatchEngineProperties 配置类 写相应参数BTCGCN:coinScale: 8baseCoinScale: 8ETHGCN:coinScale: 8baseCoinScale: 8
import ditions.query.LambdaQueryWrapper;
ample.disruptor.DisruptorTemplate;
ample.domain.EntrustOrder;
ample.mapper.EntrustOrderMapper;
ample.util.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StopWatch;import java.util.List;@Component // 放在容器里面
public class DataLoaderCmdRunner implements CommandLineRunner {@Autowiredprivate EntrustOrderMapper entrustOrderMapper ;// 查询委托单@Autowiredprivate DisruptorTemplate disruptorTemplate ; // 查询到的委托单 往ringbuffer 中放/*** 项目启动完毕后会执行该方法* @param args* @throws Exception*/@Overridepublic void args) throws Exception { // 表示 match 一启动 就会执行这个List<EntrustOrder> entrustOrders = entrustOrderMapper.selectList(new LambdaQueryWrapper<EntrustOrder>().eq(EntrustOrder::getStatus, 0).orderByAsc(EntrustOrder::getCreated));if(CollectionUtils.isEmpty(entrustOrders)){return;}StopWatch stopWatch = new StopWatch() ;stopWatch.start();for (EntrustOrder entrustOrder : entrustOrders) {ustOrder2Order(entrustOrder)); // 往ringbuffer 中放 // ustOrder2Order 数据转换} // ustOrder2Order(entrustOrder) 是数据转换 就是从entrustOrder 筛选出 Order 需要的属性数据stopWatch.stop();long lastTaskTimeMillis = LastTaskTimeMillis();System.out.println("总条数:+"+entrustOrders.size()+" ,总共耗时:"+lastTaskTimeMillis+"ms");}}
@Overridepublic void onEvent(OrderEvent event, long sequence, boolean endOfBatch) throws Exception {// 从ringbuffer 里面接收了某个数据Order order = (Source(); // 强制转换成orderif(!Symbol().equals(symbol)){ // symbol 是 上定义的 , 接收到的交易对 和 cpu交易对匹配return;}log.info("开始接收订单事件============>{}", event);MatchService(MatchStrategy.LIMIT_PRICE).match(orderBooks ,order);log.info("处理完成我们的订单事件===================>{}", event);}
本文发布于:2024-01-28 02:58:15,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/17063818994283.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |