diff options
| author | Paul Buetow <paul@buetow.org> | 2008-05-18 15:13:30 +0000 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2008-05-18 15:13:30 +0000 |
| commit | c46ed2242876bfb267ed0b6823c8a3e99ac62dd6 (patch) | |
| tree | 279f9dfd1a9fcc8f91ced6b80ba7e8878ee13b92 | |
| parent | 34595bc248660a6cd9c51f2b7a18ed33ae31cce4 (diff) | |
TaskManager better.
| -rw-r--r-- | ROADMAP | 1 | ||||
| -rw-r--r-- | sources/core/VSTask.java | 60 | ||||
| -rw-r--r-- | sources/core/VSTaskManager.java | 30 | ||||
| -rw-r--r-- | sources/prefs/VSDefaultPrefs.java | 3 | ||||
| -rw-r--r-- | sources/simulator/VSSimulation.java | 130 | ||||
| -rw-r--r-- | sources/simulator/VSSimulationPanel.java | 6 |
6 files changed, 193 insertions, 37 deletions
@@ -3,6 +3,7 @@ TODO: Prozess Quick Panel: Uhrabweichung / Geschwindigkeit direkt einstellen koennen Event Manager (Prozessabstuerze genau vorprogrammieren) "Himmelobjekt" +KeyEvent Manager Ganze simulationseinstellungen abspeichern/laden koennen Systemschnitte? diff --git a/sources/core/VSTask.java b/sources/core/VSTask.java index 7ebf4d5..7787373 100644 --- a/sources/core/VSTask.java +++ b/sources/core/VSTask.java @@ -1,6 +1,7 @@ package core; import events.*; +import events.implementations.*; import prefs.VSPrefs; import protocols.VSProtocol; import simulator.*; @@ -42,6 +43,10 @@ public class VSTask implements Comparable { return false; } + public boolean isProcess(VSProcess process) { + return this.process.equals(process); + } + public boolean isGlobalTimed() { if (event instanceof VSProtocol) return false; @@ -94,16 +99,23 @@ public class VSTask implements Comparable { else protocolObj = null; - String loggVSMessage = prefs.getString("lang.message.recv") - + "; " + prefs.getString("lang.protocol") + ": " + protocolName - + "; " + prefs.getString("lang.message") + " " + message; + StringBuffer buffer = new StringBuffer(); + buffer.append(prefs.getString("lang.message.recv")); + buffer.append("; "); + buffer.append(prefs.getString("lang.protocol")); + buffer.append(": " ); + buffer.append(protocolName); + buffer.append("; "); + buffer.append(prefs.getString("lang.message")); + buffer.append(" "); + buffer.append(message);; if (protocolObj == null) { - logg(loggVSMessage); + logg(buffer.toString()); } else { final VSProtocol protocol = (VSProtocol) protocolObj; - logg(loggVSMessage); + logg(buffer.toString()); protocol.onMessageRecv(message); } } @@ -129,16 +141,42 @@ public class VSTask implements Comparable { process.logg(message); } + public String toStringBrief() { + StringBuffer buffer = new StringBuffer(); + if (event instanceof ProcessCrashEvent) { + buffer.append(prefs.getString("process.crash")); + + } else if (event instanceof ProcessRecoverEvent) { + buffer.append(prefs.getString("process.recover")); + + } else if (event instanceof VSProtocol) { + buffer.append(((VSProtocol) event).getProtocolShortname()); + buffer.append(" "); + buffer.append(prefs.getString("lang.clientrequest.start")); + + } else { + buffer.append("null"); + } + + return buffer.toString(); + } + public String toString() { - String descr = "VSTask: " + getTaskTime(); + StringBuffer buffer = new StringBuffer(); + buffer.append(prefs.getString("lang.task")); + buffer.append(" "); + buffer.append(getTaskTime()); - if (event instanceof VSMessage) - descr += (VSMessage) event; + if (event instanceof VSMessage) { + buffer.append("; "); + buffer.append(((VSMessage)event).toString()); - else if (event instanceof VSProtocol) - descr += (VSProtocol) event; + } else if (event instanceof VSProtocol) { + buffer.append("; "); + buffer.append(((VSProtocol)event).toString()); + } - return descr; + return buffer.toString(); } public int compareTo(Object object) { diff --git a/sources/core/VSTaskManager.java b/sources/core/VSTaskManager.java index 474bc45..19935df 100644 --- a/sources/core/VSTaskManager.java +++ b/sources/core/VSTaskManager.java @@ -35,7 +35,7 @@ public class VSTaskManager { }; } - public synchronized void runVSTasks(final long step, final long offset, final long lastGlobalTime) { + public synchronized void runTasks(final long step, final long offset, final long lastGlobalTime) { VSTask task = null; VSProcess process = null; long localTime; @@ -265,6 +265,34 @@ public class VSTaskManager { } } + public synchronized ArrayList<VSTask> getProcessLocalTasks(VSProcess process) { + ArrayList<VSTask> processTasks = new ArrayList<VSTask>(); + + for (VSTask task : fullfilledProgrammedTasks) + if (!task.isGlobalTimed() && task.isProcess(process)) + processTasks.add(task); + + for (VSTask task : tasks) + if (task.isProcess(process)) + processTasks.add(task); + + return processTasks; + } + + public synchronized ArrayList<VSTask> getProcessGlobalTasks(VSProcess process) { + ArrayList<VSTask> processTasks = new ArrayList<VSTask>(); + + for (VSTask task : fullfilledProgrammedTasks) + if (task.isGlobalTimed() && task.isProcess(process)) + processTasks.add(task); + + for (VSTask task : globalTasks) + if (task.isProcess(process)) + processTasks.add(task); + + return processTasks; + } + public String toString() { StringBuffer buffer = new StringBuffer(); diff --git a/sources/prefs/VSDefaultPrefs.java b/sources/prefs/VSDefaultPrefs.java index 1ffe175..42c429e 100644 --- a/sources/prefs/VSDefaultPrefs.java +++ b/sources/prefs/VSDefaultPrefs.java @@ -110,6 +110,7 @@ public class VSDefaultPrefs extends VSPrefs { initString("lang.start", "Starten"); initString("lang.stop", "Stoppen"); initString("lang.takeover", "Übernehmen"); + initString("lang.task", "Aufgabe"); initString("lang.task.manager", "Aufgabenmanager"); initString("lang.tasks.fullfilled", "Abgelaufene Aufgaben"); initString("lang.tasks.global", "Globale Aufgaben"); @@ -155,7 +156,7 @@ public class VSDefaultPrefs extends VSPrefs { initIntegerUnit("window.prefs.xsize", 350, "X-Grösse des Einstellungsfensters", 550, 3200, "px"); initIntegerUnit("window.prefs.ysize", 600, "Y-Grösse des Einstellungsfensters", 640, 2400, "px"); initIntegerUnit("window.loggsize", 300, "Y-Grösse des Loggingfensters", 100, 1000, "px"); - initIntegerUnit("window.splitsize", 285, null, 100, 1000, "px"); + initIntegerUnit("window.splitsize", 300, null, 100, 1000, "px"); initIntegerUnit("window.xsize", 1024, "X-Grösse des Hauptfensters", 800, 3200, "px"); initIntegerUnit("window.ysize", 768, "Y-Grösse des Hauptfensters", 600, 2400, "px"); } diff --git a/sources/simulator/VSSimulation.java b/sources/simulator/VSSimulation.java index 0b84685..d3547e3 100644 --- a/sources/simulator/VSSimulation.java +++ b/sources/simulator/VSSimulation.java @@ -4,8 +4,9 @@ import java.awt.*; import java.awt.event.*; import java.util.*; import javax.swing.*; -import javax.swing.event.*; import javax.swing.border.*; +import javax.swing.event.*; +import javax.swing.table.*; import core.*; import prefs.*; @@ -17,6 +18,7 @@ public class VSSimulation extends VSFrame implements ActionListener { private JCheckBox filterActiveCheckBox; private JCheckBox lamportActiveCheckBox; private JCheckBox vectorTimeActiveCheckBox; + private JComboBox processesComboBox; private JMenuItem pauseItem; private JMenuItem replayItem; private JMenuItem resetItem; @@ -28,6 +30,8 @@ public class VSSimulation extends VSFrame implements ActionListener { private VSPrefs prefs; private VSSimulationPanel simulationPanel; private boolean hasStarted = false; + private VSTaskManagerTableModel taskManagerLocalModel; + private VSTaskManagerTableModel taskManagerGlobalModel; public VSSimulation (VSPrefs prefs, Component relativeTo) { super(prefs.getString("name"), relativeTo); @@ -284,14 +288,14 @@ public class VSSimulation extends VSFrame implements ActionListener { JPanel editPanel = new JPanel(new GridBagLayout()); editPanel.setLayout(new BoxLayout(editPanel, BoxLayout.Y_AXIS)); - JComboBox comboBox = new JComboBox(); + processesComboBox = new JComboBox(); int numProcesses = simulationPanel.getNumProcesses(); String processString = prefs.getString("lang.process"); for (int i = 1; i <= numProcesses; ++i) - comboBox.addItem(processString + " " + i); + processesComboBox.addItem(processString + " " + i); - JPanel localPanel = createTaskLabel(true); - JPanel globalPanel = createTaskLabel(false); + JPanel localPanel = createTaskLabel(VSTaskManagerTableModel.LOCAL); + JPanel globalPanel = createTaskLabel(VSTaskManagerTableModel.GLOBAL); JSplitPane splitPane1 = new JSplitPane(); splitPane1.setOrientation(JSplitPane.VERTICAL_SPLIT); @@ -302,9 +306,15 @@ public class VSSimulation extends VSFrame implements ActionListener { JSplitPane splitPane2 = new JSplitPane(); splitPane2.setOrientation(JSplitPane.VERTICAL_SPLIT); - splitPane2.setTopComponent(comboBox); + splitPane2.setTopComponent(processesComboBox); splitPane2.setBottomComponent(splitPane1); + processesComboBox.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent ae) { + updateTaskManagerTable(); + } + }); + return splitPane2; } @@ -333,19 +343,77 @@ public class VSSimulation extends VSFrame implements ActionListener { return panel; } + private class VSTaskManagerTableModel extends AbstractTableModel { + public static final boolean LOCAL = true; + public static final boolean GLOBAL = false; + private VSTaskManager taskManager; + private ArrayList<VSTask> tasks; + private String columnNames[]; + private VSProcess process; + + public VSTaskManagerTableModel(VSProcess process, boolean localTask) { + taskManager = simulationPanel.getTaskManager(); + set(process, localTask); + columnNames = new String[2]; + columnNames[0]= prefs.getString("lang.time") + " (ms)"; + columnNames[1] = prefs.getString("lang.event"); + } + + public void set(VSProcess process, boolean localTasks) { + this.process = process; + this.tasks = localTasks + ? taskManager.getProcessLocalTasks(process) + : taskManager.getProcessGlobalTasks(process); + + fireTableDataChanged(); + } + + public String getColumnName(int col) { + if (col == 0) + return columnNames[0]; + return columnNames[1]; + } + + public int getRowCount() { + return tasks.size(); + } + + public int getColumnCount() { + return 2; + } + + public Object getValueAt(int row, int col) { + VSTask task = tasks.get(row); + + if (col == 0) + return task.getTaskTime(); + + return task.toStringBrief(); + } + + public boolean isCellEditable(int row, int col) { + return false; + } + + public void setValueAt(Object value, int row, int col) { + } + } + private JTable createTaskTable(boolean localTasks) { - String[] columnNames = { prefs.getString("lang.time"), prefs.getString("lang.event") }; - Object[][] data = { - {"foo", "bar" }, - {"foo", "bar" }, - {"foo", "bar" }, - {"foo", "bar" }, - {"foo", "bar" }, - { "baz", "bay" } - }; - - JTable table = new JTable(data, columnNames); - table.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN); + VSProcess process = getSelectedProcess(); + VSTaskManagerTableModel model = new VSTaskManagerTableModel(process, localTasks); + + if (localTasks) + taskManagerLocalModel = model; + else + taskManagerGlobalModel = model; + + JTable table = new JTable(model); + TableColumn col = table.getColumnModel().getColumn(0); + col.setMaxWidth(75); + col.setResizable(false); + col = table.getColumnModel().getColumn(1); + col.sizeWidthToFit(); table.setBackground(Color.WHITE); return table; @@ -361,9 +429,10 @@ public class VSSimulation extends VSFrame implements ActionListener { panel1.add(takeoverButton); JComboBox comboBox = new JComboBox(); + comboBox.setMaximumRowCount(15); comboBox.addItem("-- " + prefs.getString("lang.events.process") + " --"); - comboBox.addItem("Prozessabsturz"); - comboBox.addItem("Prozesswiederbelebung"); + comboBox.addItem(prefs.getString("lang.crash")); + comboBox.addItem(prefs.getString("lang.recover")); comboBox.addItem("-- " + prefs.getString("lang.events.protocol") + " --"); @@ -426,7 +495,7 @@ public class VSSimulation extends VSFrame implements ActionListener { pauseItem.setEnabled(true); resetItem.setEnabled(false); replayItem.setEnabled(true); - runThread(); + registeredProhread(); } else if (source.getText().equals(prefs.getString("lang.pause"))) { startItem.setEnabled(true); @@ -448,11 +517,11 @@ public class VSSimulation extends VSFrame implements ActionListener { resetItem.setEnabled(false); replayItem.setEnabled(true); simulationPanel.reset(); - runThread(); + registeredProhread(); } } - private void runThread() { + private void registeredProhread() { if (hasStarted) { simulationPanel.play(); @@ -463,6 +532,21 @@ public class VSSimulation extends VSFrame implements ActionListener { } } + private VSProcess getSelectedProcess() { + String string = (String) processesComboBox.getSelectedItem(); + int cutLen = prefs.getString("lang.process").length() + 1; + string = string.substring(cutLen); + int processNum = Integer.parseInt(string) - 1; + + return simulationPanel.getProcess(processNum); + } + + public void updateTaskManagerTable() { + VSProcess process = getSelectedProcess(); + taskManagerLocalModel.set(process, VSTaskManagerTableModel.LOCAL); + taskManagerGlobalModel.set(process, VSTaskManagerTableModel.GLOBAL); + } + public void finish() { startItem.setEnabled(false); pauseItem.setEnabled(false); diff --git a/sources/simulator/VSSimulationPanel.java b/sources/simulator/VSSimulationPanel.java index ede5d3b..6514963 100644 --- a/sources/simulator/VSSimulationPanel.java +++ b/sources/simulator/VSSimulationPanel.java @@ -240,7 +240,7 @@ public class VSSimulationPanel extends JPanel implements Runnable, MouseMotionLi private void updateSimulation(final long globalTime, final long lastGlobalTime) { final long offset = globalTime - lastGlobalTime; for (long l = 0; l < offset; ++l) - taskManager.runVSTasks(l, offset, lastGlobalTime); + taskManager.runTasks(l, offset, lastGlobalTime); for (VSProcess process : processes) process.syncTime(globalTime); @@ -447,6 +447,10 @@ public class VSSimulationPanel extends JPanel implements Runnable, MouseMotionLi return numProcesses; } + public VSProcess getProcess(int processNum) { + return processes.get(processNum); + } + public void run() { play(); |
