多文件并发传输-------资源中心

mfct 资源中心

我们这个系统 由三大部分组成: 资源中心 发送方节点 接收方节点
资源中心与发送方、接收方采用的都是短链接
短链接的实现
因为他们需要注册 资源 注销节点 获取节点列表等在接收到对方传来的信息之后,我们便可以将双方的连接断开

资源的接收方、发送方之间要不停的发送当一个发送端我完成了他的发送之后,我们才可以关掉他们之间的 通信信道 但是当整个的发送工作结束之后就可以关闭接受端
他们之间采用的是长连接

在资源中心我们可以读取配置文件:如文件分割的最大长度、参与发送端的最大个数等进行配置

private void loadResourceAllocationStrategy() {
          String rasString =  PropertiesParser.value("ResourceAllocationStrategy");
          if (rasString != null) {
               try {
//                  利用配置 来进行设置
                    Class<?> klass =  Class.forName(rasString);
                    resourceAllocationStrategy =  (IResourceAllocationStrategy) klass.newInstance();
               } catch (Exception e) {
               }
          }
          String strMaxSectionLength =  PropertiesParser.value("maxSectionLength");
          if (strMaxSectionLength != null) {
               try {
                    int maxSectionLength = 0;
                    maxSectionLength =  Integer.valueOf(strMaxSectionLength);
                    resourceAllocationStrategy.setMaxSectionLength(maxSectionLength);
               } catch (Exception e) {
               }
          }
     }

资源中心我们提供的最重要的功能就是

  1. 进行资源的请求与发送
  2. 接收端对资源进行请求
  3. 我们可以先获取拥有资源的列表
  4. 然后进行资源分配策略的落实 最后进行发送
public int requestResource(ResourceBaseInfo1 rbi, INetNode1  receiveNode) {
          List<INetNode1>   senderList=nodeSelectStrategy.selectNodeList(rbi);
          int sendCount=senderList.size();
          ResourceAllocation resourceAllocation =
                    new ResourceAllocation(rbi, receiveNode,  senderList);
          resourceAllocationStrategy.
                    allocationResource(rbi, receiveNode,  senderList);
          waitting = true;
          rmiServer.getThreadPool().execute((Runnable)  resourceAllocation);
          
          return sendCount;
     }

resourceAllocation 类里面的方法:
// 使用了短连接的远程方法调用 并且启动了发送端

public void run() {
               
               /*
               // 为避免接收端异常掉线而造成while (waitting)的无限等待,
               // 有必要设置一个监视时钟,当超过最大等待时间后,放弃后续所有操作,
               // 并结束本线程。
               DidaDida dida = new DidaDida(20000);
               IDidaDidaAction didaAction = new  IDidaDidaAction() {
                    @Override
                    public void doSomething() {
                         dida.stop();
                         ok = false;
                         return;
                    }
               };
               dida.setAction(didaAction);
               dida.start();
               */
               List<SendSectionInfo1>   sendList=resourceAllocationStrategy.
                         allocationResource(rbi, receiver,  senderList);
//             得到了 发送的片段 发送节点、接收节点
               RMIClient client=new RMIClient();
               RMIClientProxy proxy=new RMIClientProxy();
               proxy.setRmiClient(client);
               IResourceSender  resourceSender=proxy.getProxy(IResourceSender.class);
               for(SendSectionInfo1 sendSection:sendList) {
                    INetNode1 sender =  sendSection.getSendNode();
                    client.setIp(sender.getIp());
                    client.setPort(sender.getPort());
                    resourceSender.sendSection(receiver,  sendSection.getRbi());
               }
          }
     }
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值