コード例 #1
0
ファイル: BisonContext.java プロジェクト: hefei1986/Bison
  private int send_message_now(BisonObject obj) {
    int ret = 0;
    int idx = getManagerIdx(obj.getKey());
    NodeGroup objGroup = (NodeGroup) this.groupMaps.get(obj.getGroupID());
    if (objGroup != null) {
      MinaNode objNode = objGroup.getNode();
      if ((objNode != null) && (objNode.isConnected())) {
        this.amanager[idx].addObjectToManager(obj.getKey(), obj);
        if (obj.isAsync()) {
          this.amanager[idx].addToTimeOutMonitor(obj.getKey());
        }
        ret = sendObject(obj, objNode.getSession());
      } else {
        if (objNode == null) {
          try {
            System.out.println("等待和服务端建立连接 ");
            Thread.sleep(2000);
            send_message(obj);
            System.out.println("msg obj:重新 进入发送队列");
          } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
          }
        } else {

        }
        System.out.println("没有可以用的接受node");
        ret = -7;
      }
    } else {
      System.out.println("没有可以用的接受服务端");
      ret = -6;
    }
    return ret;
  }
コード例 #2
0
ファイル: BisonContext.java プロジェクト: hefei1986/Bison
 public void run() {
   while (true) {
     MinaNode node = (MinaNode) BisonContext.this.connectQueue.poll();
     if ((node == null) && (BisonContext.this.connectQueue.size() == 0)) {
       BisonContext.this.processor = null;
       break;
     }
     ConnectFuture cf = BisonContext.this.connector.connect(node.getRemoteAddress());
     cf.awaitUninterruptibly();
     if (!cf.isConnected()) {
       BisonContext.this.logger.info("建立连接失败 " + node.toString());
       try {
         if (BisonContext.this.connectQueue.size() == 0) Thread.sleep(5000L);
         else Thread.sleep(1000L);
       } catch (Exception localException) {
       }
       BisonContext.this.connectQueue.offer(node);
       continue;
     }
     cf.getSession().setAttribute(SESSION_NODE_KEY, node);
     node.setSession(cf.getSession());
     node.setConnected(true);
     BisonContext.this.logger.info("建立连接成功 " + node.toString());
   }
 }
コード例 #3
0
ファイル: BisonContext.java プロジェクト: hefei1986/Bison
  private void load_config() {
    JXmlWapper xml = JXmlWapper.parse(new File(this.configFile));
    int gcount = xml.countXmlNodes("group");
    for (int i = 0; i < gcount; i++) {
      JXmlWapper gnode = xml.getXmlNode("group[" + i + "]");
      String gid = gnode.getStringValue("@id");
      String gName = gnode.getStringValue("@name");

      NodeGroup objGroup = new NodeGroup();
      objGroup.setGroupID(gid);
      objGroup.setGroupName(gName);

      int ncount = gnode.countXmlNodes("node");
      for (int j = 0; j < ncount; j++) {
        JXmlWapper node = gnode.getXmlNode("node[" + j + "]");
        String nid = node.getStringValue("@id");
        String nip = node.getStringValue("@ip");
        String name = node.getStringValue("@name");
        int port = Integer.parseInt(node.getStringValue("@port"));

        MinaNode objNode = new MinaNode();
        objNode.setNodeID(nid);
        objNode.setNodeIp(nip);
        objNode.setPort(port);
        objNode.setNodeName(name);

        SocketAddress address = new InetSocketAddress(nip, port);
        objNode.setRemoteAddress(address);

        this.connectQueue.offer(objNode);
        objGroup.addNode(objNode);
        this.logger.info("加载节点 --->  " + objNode.toString());
      }
      this.groupMaps.put(gid, objGroup);
    }
    startProcessor();
  }