Commit 66015392 authored by uahhx's avatar uahhx

sync

TODO: make test case and go test
parent 9acad698
......@@ -6,6 +6,11 @@ public class MasterNode extends Node {
super(layerNumber, nodeNumber);
}
@Override
public void preTick() {
updateSubLines();
}
@Override
public void tick() {
// TODO Auto-generated method stub
......
......@@ -7,6 +7,12 @@ public class NetNode extends Node {
super(layerNumber, nodeNumber);
}
@Override
public void preTick() {
updateSuperLine();
updateSubLines();
}
@Override
public void tick() {
// TODO Auto-generated method stub
......
......@@ -61,24 +61,26 @@ public abstract class Node {
}
//handle incoming data. call all nodes pretick before tick to keep things "parallel"
public void preTick() {
DataPacket curPkt;
superIncoming = null;
for (int i = 0; i < superIncomingLine.size(); i++) {
curPkt = superIncomingLine.get(i);
if (curPkt.decrementLatencyCounter())
superIncoming = superIncomingLine.remove(i);
}
public abstract void preTick();
protected void updateSuperLine() {
superIncoming = updateLine(superIncomingLine);
}
for (int i = 0; i < subIncoming.length; i++) {
LinkedList<DataPacket> curLine = subIncomingLines.get(i);
subIncoming[i] = null;
for (int j = 0; j < curLine.size(); j++) {
curPkt = curLine.get(j);
if (curPkt.decrementLatencyCounter())
subIncoming[i] = curLine.remove(j);
protected void updateSubLines() {
for (int i = 0; i < subIncoming.length; i++)
subIncoming[i] = updateLine(subIncomingLines.get(i));
}
private DataPacket updateLine(LinkedList<DataPacket> line) {
DataPacket curPkt;
for (int i = 0; i < line.size(); i++)
if (line.get(i).decrementLatencyCounter()) {
if(i != line.size()-1)
System.out.println("Warning: Line holds Packets beyond the currently forwarded one!");
return line.remove(i);
}
}
return null;
}
public void tick() {
......@@ -195,7 +197,7 @@ public abstract class Node {
LinkedList<DataPacket> incomingLine = fromSub ? subIncomingLines.get(subNumber) : superIncomingLine;
message.resetLatencyCounter();
incomingLine.add(message);
incomingLine.addFirst(message);
}
public void setLayerNumber(int num) {
......
......@@ -9,6 +9,11 @@ public class SlaveNode extends Node {
super(layerNumber, nodeNumber);
}
@Override
public void preTick() {
updateSuperLine();
}
@Override
public void tick() {
// TODO Auto-generated method stub
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment