欢迎访问悦橙教程(wld5.com),关注java教程。悦橙教程  java问答|  每日更新
页面导航 : > > 文章正文

BubbleHProcess onConnect 方法,,public void

来源: javaer 分享于  点击 36732 次 点评:25

BubbleHProcess onConnect 方法,,public void


public void onConnect(Process p, Simulation s) {        // do the business        List<BubbleHMessage> toSend = new LinkedList<BubbleHMessage>();        BubbleHProcess process = (BubbleHProcess) p;        // on N connected with encountered node P        // for each message M (for destination D) in buffer of N        // Identify bridging community (BC), smallest community containing N and        // D.        // IF P == D        // then pass the message        // ELSE IF P shares a community with D that is smaller than BC        // then pass the message.        // ELSE IF P is more central in BC than N        // then pass the message.        String hopcode = null;        // foreach message in my buffer        for (BubbleHMessage message : my_buffer) {            /**             * Identify smallest community that Self and Destination share =             * Bridging Community             * */            int my_bridge_community = my_oracle.bridgeCommunity(my_node.getID(), message.dest);            //int his_bridge_community = BubbleHeirarchyOracle.bridgeCommunity(process.getNode().getID(), message.dest, my_properties);            // if encountered node is destination            if (process.getNode().getID() == message.dest) {                // pass it on to them.                toSend.add(message);            } else {                int remote_bridge = my_oracle.bridgeCommunity(process.getNode().getID(), message.dest);                if (my_oracle.isBetter(remote_bridge, my_bridge_community)) {                    // if P is in community with message.dest, that is smaller                    // than BC                    // pass message                    toSend.add(message);                } else if (process.getCommunities().contains(my_bridge_community)) {// if both nodes are in the bridge community                    // if the rank of the encountered node is higher, pass the message                    if (process.getlocalRank(my_bridge_community) > getlocalRank(my_bridge_community)) {                        // pass message                        toSend.add(message);                        message.setHopCode("RANKBC-" + my_bridge_community);                        bridge_community_ranking_message_passed++;                    }                } else {                    // process is not destination, is not in a smaller community                    // with the destination, and is not in the bridge community,                    // therefore we do not pass the message to it                }            }        }        for (BubbleHMessage message : toSend) {            my_transmittedCount++;            message.hopCount++;            s.sendMessage(this, process, message);            my_buffer.remove(message); // not sure if this is strictly part of            // BubbleRap, however to get anything like            // the cost figures they quote, it seems            // like the only way!        }}
相关栏目:

用户点评