diff options
| author | Paul Buetow <paul@buetow.org> | 2008-05-17 21:50:44 +0000 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2008-05-17 21:50:44 +0000 |
| commit | 8602c18db94281afd5bc0ceb5930a3d99fbe7a38 (patch) | |
| tree | 6883d776ac6d2ead8df8711ed6dac4388680d181 /sources | |
| parent | dbb780b7295c0df60269ee6f3c85c3056d6262b8 (diff) | |
Manual crash/recover implemented.
Diffstat (limited to 'sources')
| -rw-r--r-- | sources/core/VSProcess.java | 36 | ||||
| -rw-r--r-- | sources/core/VSTask.java | 28 | ||||
| -rw-r--r-- | sources/core/VSTaskManager.java | 4 | ||||
| -rw-r--r-- | sources/simulator/VSSimulationPanel.java | 29 |
4 files changed, 76 insertions, 21 deletions
diff --git a/sources/core/VSProcess.java b/sources/core/VSProcess.java index e3d260e..d9fd0c5 100644 --- a/sources/core/VSProcess.java +++ b/sources/core/VSProcess.java @@ -12,15 +12,21 @@ import simulator.*; import utils.*; public final class VSProcess extends VSPrefs { - private VSTask randomCrashTask; + private ArrayList<Long> crashHistory; + private ArrayList<VSLamportTime> lamportTimeHistory; + private ArrayList<VSVectorTime> vectorTimeHistory; + private Color crashedColor;; private Color currentColor; private Color tmpColor; - private Color crashedColor;; private VSLogging logging; private VSPrefs prefs; private VSRandom random; private VSSimulationPanel simulationPanel; + private VSTask randomCrashTask; + private VSVectorTime vectorTime; + private boolean hasCrashed; private boolean hasStarted; + private boolean isCrashed; private boolean isHighlighted; private boolean isPaused; private boolean timeModified; @@ -28,13 +34,9 @@ public final class VSProcess extends VSPrefs { private float clockVariance; private int processID; private long globalTime; + private long lamportTime; private long localTime; private static int processCounter; - private boolean isCrashed; - private long lamportTime; - private ArrayList<VSLamportTime> lamportTimeHistory; - private VSVectorTime vectorTime; - private ArrayList<VSVectorTime> vectorTimeHistory; /* This array contains all Integer prefs of the process which should show * up in the prefs menu! All keys which dont start with "sim." only show @@ -115,6 +117,7 @@ public final class VSProcess extends VSPrefs { vectorTime = new VSVectorTime(0); vectorTimeHistory = new ArrayList<VSVectorTime>(); + crashHistory = new ArrayList<Long>(); final int numProcesses = simulationPanel.getNumProcesses(); for (int i = 0; i < numProcesses; ++i) @@ -127,6 +130,7 @@ public final class VSProcess extends VSPrefs { vectorTime = new VSVectorTime(0); vectorTimeHistory.clear(); + crashHistory.clear(); final int numProcesses = simulationPanel.getNumProcesses(); for (int i = numProcesses; i > 0; --i) @@ -199,6 +203,7 @@ public final class VSProcess extends VSPrefs { public synchronized void reset() { isPaused = true; isCrashed = false; + hasCrashed = false; localTime = 0; globalTime = 0; clockOffset = 0; @@ -292,8 +297,15 @@ public final class VSProcess extends VSPrefs { return isCrashed; } + public synchronized boolean hasCrashed() { + return hasCrashed; + } + public synchronized void isCrashed(boolean isCrashed) { this.isCrashed = isCrashed; + crashHistory.add(new Long(globalTime)); + if (!hasCrashed) + hasCrashed = true; } public synchronized Color getCrashedColor() { @@ -447,6 +459,16 @@ public final class VSProcess extends VSPrefs { return arr; } + public synchronized Long[] getCrashHistoryArray() { + final int size = crashHistory.size(); + final Long[] arr = new Long[size]; + + for (int i = 0; i < size; ++i) + arr[i] = crashHistory.get(i); + + return arr; + } + public void sendMessage(VSMessage message) { StringBuffer buffer = new StringBuffer(); buffer.append(prefs.getString("lang.message.sent")); diff --git a/sources/core/VSTask.java b/sources/core/VSTask.java index d481300..4fe7b37 100644 --- a/sources/core/VSTask.java +++ b/sources/core/VSTask.java @@ -1,12 +1,11 @@ package core; -import prefs.VSPrefs; import events.*; +import prefs.VSPrefs; import protocols.VSProtocol; import simulator.*; -public class VSTask { - //public final static int RUN_ON_CLIENT_START = 1; +public class VSTask implements Comparable { private long taskTime; private VSEvent event; private VSProcess process; @@ -32,6 +31,10 @@ public class VSTask { return event instanceof VSMessage; } + public boolean isProcessRecoverEvent() { + return event instanceof events.implementations.ProcessRecoverEvent; + } + public boolean isProtocol(VSProtocol protocol) { if (event instanceof VSProtocol) return ((VSProtocol) event).equals(protocol); @@ -51,8 +54,9 @@ public class VSTask { } public void run() { - if (process.isCrashed()) - return; + /* Process crash allready checked in VSTaskManager */ + //if (process.isCrashed() && !(event instanceof ProcessRecoverEvent)) + // return; if (event instanceof VSMessage) { onMessageRecv(); @@ -140,5 +144,19 @@ public class VSTask { return descr; } + + public int compareTo(Object object) { + if (object instanceof VSTask) { + final VSTask task = (VSTask) object; + + if (taskTime < task.getTaskTime()) + return -1; + + else if (taskTime > task.getTaskTime()) + return 1; + } + + return 0; + } } diff --git a/sources/core/VSTaskManager.java b/sources/core/VSTaskManager.java index 28f5a36..f8d3f63 100644 --- a/sources/core/VSTaskManager.java +++ b/sources/core/VSTaskManager.java @@ -63,7 +63,7 @@ public class VSTaskManager { globalTasks.poll(); redo = true; - if (process.isCrashed()) { + if (process.isCrashed() && !task.isProcessRecoverEvent()) { if (task.isProgrammed()) fullfilledProgrammedTasks.add(task); continue; @@ -117,7 +117,7 @@ public class VSTaskManager { tasks.poll(); redo = true; - if (process.isCrashed()) { + if (process.isCrashed() && !task.isProcessRecoverEvent()) { if (task.isProgrammed()) fullfilledProgrammedTasks.add(task); continue; diff --git a/sources/simulator/VSSimulationPanel.java b/sources/simulator/VSSimulationPanel.java index e750b0a..8d792a9 100644 --- a/sources/simulator/VSSimulationPanel.java +++ b/sources/simulator/VSSimulationPanel.java @@ -278,14 +278,29 @@ public class VSSimulationPanel extends JPanel implements Runnable, MouseMotionLi g.setColor(process.getColor()); g.fillPolygon(xPoints, yPoints, 5); - if (process.isCrashed()) { - final VSTask crashTask = process.getCrashTask(); - final int crashPos = (int) getTimeXPosition(crashTask.getTaskTime()); - final int xPointsCrashed[] = { crashPos, xoffset_plus_xpaintsize, xoffset_plus_xpaintsize, crashPos, crashPos }; + + if (process.hasCrashed()) { g.setColor(process.getCrashedColor()); - g.fillPolygon(xPointsCrashed, yPoints, 5); + final Long crashHistory[] = process.getCrashHistoryArray(); + final int length = crashHistory.length; + + for (int i = 0; i < length; i += 2) { + final int crashStartPos = (int) getTimeXPosition(crashHistory[i].longValue()); + int crashEndPos; + + if (i == length - 1) + crashEndPos = xoffset_plus_xpaintsize; + else + crashEndPos = (int) getTimeXPosition(crashHistory[i+1].longValue()); + + final int xPointsCrashed[] = { crashStartPos, crashEndPos, + crashEndPos, crashStartPos, crashStartPos + }; + g.fillPolygon(xPointsCrashed, yPoints, 5); + } } + g.setColor(process.getColor()); g.drawString("P" + process.getProcessID() + ":", XOFFSET - 30, yPoints[0] + LINE_WIDTH); final long tmp = localTime > untilTime ? untilTime : localTime; @@ -635,14 +650,14 @@ public class VSSimulationPanel extends JPanel implements Runnable, MouseMotionLi popup.add(item); item = new JMenuItem(prefs.getString("lang.crash")); - if (process.isCrashed() || isPaused || time == 0) + if (process.isCrashed() || isPaused || time == 0 || isFinished) item.setEnabled(false); else item.addActionListener(actionListener); popup.add(item); item = new JMenuItem(prefs.getString("lang.recover")); - if (!process.isCrashed() || isPaused || time == 0) + if (!process.isCrashed() || isPaused || time == 0 || isFinished) item.setEnabled(false); else item.addActionListener(actionListener); |
