分布式计算ECHO算法(IT部落格)
来源:互联网 发布:vb程序设计课后答案 编辑:程序博客网 时间:2024/06/07 01:31
package org.ustc.scst.dc.simulation.algorithms.echo; import java.awt.Color; import org.ustc.scst.dc.simulation.algorithms.echo.IntMessage;import org.ustc.scst.dc.simulation.model.Message;import org.ustc.scst.dc.simulation.model.Node; /** * This special type of node is performing the Echo Algorithm. Fill in your code * here * * @author Thomas Weise */public class EchoNode extends Node { /** the serial version uid */ private static final long serialVersionUID = 1L; // you may add some fields /** * */private int size=0;/** * */private Node father; /** * The node * * @param x * the x-coordinate * @param y * the y-coordinate */ public EchoNode(final int x, final int y) { super(x, y); //String s="dfsdfsd"; //$NON-NLS-1$ 在这里进行属性设置 //this.setText(s); } /** Reset this model base to the initial state. */ @Override public synchronized void reset() { // add some code here super.reset(); } /** * This method can directly be called from somewhere in order to start * something. Currently it does nothing, so fill it with life!!! */ @Override public synchronized void trigger() { // add some code here this.setColor(Color.BLUE); this.broadcast(new IntMessage(0)); super.trigger(); } /** * This method is invoked whenever a message arrives at this node. * * @param msg * the message just received */ @Override public synchronized void onMessageReceived(final Message msg) { // add some code here //非叶节点 往外发送消息 如果是白色 if(this.getColor()==Color.WHITE) { this.father=msg.getSource(); this.setColor(Color.RED); this.broadcastExcept(new IntMessage(0), this.father); } //如果是叶节点 则返回绿色数据 if(this.getNeighborCount()==1 && this.getColor()!=Color.GREEN && this.getColor()!=Color.BLUE) { this.setColor(Color.GREEN); this.broadcast(new IntMessage(1)); } //如果是非叶节点 收到所有的反馈消息 if(msg.getColor()==Color.GREEN) { this.size++; } //收到所有的绿色消息 if(this.getNeighborCount()==(this.size+1) && this.getColor()!=Color.GREEN && this.getColor()!=Color.BLUE) { this.setColor(Color.GREEN); this.sendTo(new IntMessage(1), this.father); } //如果是头节点 if(this.getNeighborCount()==this.size && this.getColor()==Color.BLUE) { this.setColor(Color.GREEN); } super.onMessageReceived(msg); }}
其中模拟视频如连接所示:
http://v.youku.com/v_show/id_XNjc4MDE1NjE2.html
来自IT部落格
0 0
- 分布式计算ECHO算法(IT部落格)
- IT部落格网页设计图
- IT部落格新版上线(http://www.itbuluoge.com/)
- ZooKeeper云计算集群echo伪分布式
- 这里是数学和算法爱好者的部落格
- 分布式计算(一)
- 分布式计算(三)分布式的昨天
- 网格计算、集群计算、云计算、分布式计算(一)
- 新部落格开张
- 开通部落格
- 自己的部落格~~~
- 我的部落格
- 开通部落格
- 分布式计算(Map/Reduce)
- Memcached客户端分布式计算算法--一致性hash算法
- 分布式计算
- 分布式计算
- 分布式计算
- [转自David_Lin]Oracle DBA每天每周每月应该做的工作,很规范
- selectSort
- sql,JS,C#的时间间隔或者时间加上某个数
- 赋值运算符/拷贝构造/构造/析构函数
- linux ln命令详解
- 分布式计算ECHO算法(IT部落格)
- StarlingMVC 几个标签的含义
- 滚动条自绘
- list转DataTable
- 01 - 搭建开发环境&helloworld
- 如何成为Python高手(转)
- java基础---JNI原理
- 嵌入式 C语言实现进度条以及实现带进度条的CP命令等编程示例收集一
- CryptAPI和openssl交互使用