summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2008-05-18 23:20:08 +0000
committerPaul Buetow <paul@buetow.org>2008-05-18 23:20:08 +0000
commit36f74586cc61f5899c16b6f84a04be37688cc719 (patch)
tree3ce0df2cf2dc18b2bdd27b546305c4a73598c457
parent34b16d2ffc7b40df933ba85ddb8e414121116ca5 (diff)
TaskManager bugfixes.
-rw-r--r--sources/core/VSProcess.java28
-rw-r--r--sources/events/implementations/ProtocolEvent.java13
-rw-r--r--sources/prefs/editors/VSProcessEditor.java19
-rw-r--r--sources/prefs/editors/VSProtocolEditor.java274
-rw-r--r--sources/protocols/VSProtocol.java2
-rw-r--r--sources/simulator/VSSimulation.java46
6 files changed, 75 insertions, 307 deletions
diff --git a/sources/core/VSProcess.java b/sources/core/VSProcess.java
index 467ee46..d2fe934 100644
--- a/sources/core/VSProcess.java
+++ b/sources/core/VSProcess.java
@@ -12,6 +12,7 @@ import simulator.*;
import utils.*;
public final class VSProcess extends VSPrefs {
+ private ArrayList<VSProtocol> protocolsToReset;
private ArrayList<Long> crashHistory;
private ArrayList<VSLamportTime> lamportTimeHistory;
private ArrayList<VSVectorTime> vectorTimeHistory;
@@ -84,13 +85,13 @@ public final class VSProcess extends VSPrefs {
};
public VSProcess(VSPrefs prefs, VSSimulationPanel simulationPanel, VSLogging logging) {
+ this.protocolsToReset = new ArrayList<VSProtocol>();
this.prefs = prefs;
this.simulationPanel = simulationPanel;
this.logging = logging;
random = new VSRandom(processID+processCounter);
initTimeFormats();
- setObject("protocols", new ArrayList<VSProtocol>());
isPaused = true;
processID = ++processCounter;
@@ -208,14 +209,8 @@ public final class VSProcess extends VSPrefs {
globalTime = 0;
clockOffset = 0;
- if (objectExists("protocols.registered")) {
- Object protocolsObj = getObject("protocols.registered");
- if (protocolsObj instanceof Vector) {
- Vector<VSProtocol> protocols = (Vector<VSProtocol>) protocolsObj;
- for (VSProtocol protocol : protocols)
- protocol.reset();
- }
- }
+ for (VSProtocol protocol : protocolsToReset)
+ protocol.reset();
setCurrentColor(getColor("process.default"));
createRandomCrashTask();
@@ -542,4 +537,19 @@ public final class VSProcess extends VSPrefs {
public static void resetProcessCounter() {
processCounter = 0;
}
+
+ public VSProtocol getProtocolObject(String protocolClassname) {
+ VSProtocol protocol = null;
+
+ if (!objectExists(protocolClassname)) {
+ protocol = (VSProtocol) VSRegisteredEvents.createEventInstanceByClassname(protocolClassname, this);
+ setObject(protocolClassname, protocol);
+ protocolsToReset.add(protocol);
+
+ } else {
+ protocol = (VSProtocol) getObject(protocolClassname);
+ }
+
+ return protocol;
+ }
}
diff --git a/sources/events/implementations/ProtocolEvent.java b/sources/events/implementations/ProtocolEvent.java
index d753978..6b21d8c 100644
--- a/sources/events/implementations/ProtocolEvent.java
+++ b/sources/events/implementations/ProtocolEvent.java
@@ -34,18 +34,7 @@ public class ProtocolEvent extends VSEvent {
}
public void onStart() {
- //String type = isClientProtocol ? " Client!" : " Server!";
- //process.setBoolean(protocolClassname + type, isProtocolActivation);
-
- VSProtocol protocol;
-
- if (!process.objectExists(protocolClassname)) {
- protocol = (VSProtocol) VSRegisteredEvents.createEventInstanceByClassname(protocolClassname, process);
- process.setObject(protocolClassname, protocol);
-
- } else {
- protocol = (VSProtocol) process.getObject(protocolClassname);
- }
+ VSProtocol protocol = process.getProtocolObject(protocolClassname);
if (isClientProtocol)
protocol.isClient(isProtocolActivation);
diff --git a/sources/prefs/editors/VSProcessEditor.java b/sources/prefs/editors/VSProcessEditor.java
index dcbe376..4103624 100644
--- a/sources/prefs/editors/VSProcessEditor.java
+++ b/sources/prefs/editors/VSProcessEditor.java
@@ -66,7 +66,17 @@ public class VSProcessEditor extends VSEditorFrame {
private JPanel createProtocolSelector() {
JPanel panel = new JPanel(new GridBagLayout());
panel.setBorder(BorderFactory.createLineBorder(Color.black));
- Vector<String> registeredProtocols = VSRegisteredEvents.getProtocolNames();
+
+ Vector<String> registeredProtocolsNames = VSRegisteredEvents.getProtocolNames();
+ Vector<String> registeredProtocolsShortnames = new Vector<String>();
+ final HashMap<String,String> eventNames = new HashMap<String,String>();
+
+ for (String protocolName : registeredProtocolsNames) {
+ String protocolClassname = VSRegisteredEvents.getClassname(protocolName);
+ String protocolShortname = VSRegisteredEvents.getShortname(protocolClassname);
+ registeredProtocolsShortnames.add(protocolShortname);
+ eventNames.put(protocolShortname, protocolName);
+ }
GridBagConstraints constraints = new GridBagConstraints();
constraints.fill = GridBagConstraints.HORIZONTAL;
@@ -75,7 +85,8 @@ public class VSProcessEditor extends VSEditorFrame {
constraints.insets = new Insets(5, 0, 5, 0);
constraints.ipadx = 10;
constraints.ipady = 10;
- final JComboBox comboBox = new JComboBox(registeredProtocols);
+
+ final JComboBox comboBox = new JComboBox(registeredProtocolsShortnames);
comboBox.setBackground(Color.WHITE);
panel.add(comboBox, constraints);
constraints.gridy = 1;
@@ -83,7 +94,8 @@ public class VSProcessEditor extends VSEditorFrame {
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
if (ae.getActionCommand().equals(prefs.getString("lang.edit"))) {
- String eventName = (String) comboBox.getSelectedItem();
+ String eventShortname = (String) comboBox.getSelectedItem();
+ String eventName = eventNames.get(eventShortname);
String eventClassname = VSRegisteredEvents.getClassname(eventName);
VSProtocol protocol = null;
if (process.objectExists(eventClassname)) {
@@ -96,6 +108,7 @@ public class VSProcessEditor extends VSEditorFrame {
protocol = (VSProtocol) VSRegisteredEvents.createEventInstanceByName(eventName, process);
process.setObject(eventClassname, protocol);
}
+
new VSProtocolEditor(prefs, frame, protocol);
}
}
diff --git a/sources/prefs/editors/VSProtocolEditor.java b/sources/prefs/editors/VSProtocolEditor.java
index d0762a3..60d4d0c 100644
--- a/sources/prefs/editors/VSProtocolEditor.java
+++ b/sources/prefs/editors/VSProtocolEditor.java
@@ -15,14 +15,7 @@ import core.*;
import prefs.VSPrefs;
public class VSProtocolEditor extends VSEditorFrame {
- private JCheckBox clientCheckBox;
- private JCheckBox serverCheckBox;
- private JComboBox clientComboBox;
private VSProtocol protocol;
- private VSTaskManager taskManager;
- private JPanel clientTaskManagerEditorPanel;
- private JButton takeOverButton;
- private JButton deleteButton;
private JTextField textField;
public VSProtocolEditor(VSPrefs prefs, Component relativeTo, VSProtocol protocol) {
@@ -30,16 +23,12 @@ public class VSProtocolEditor extends VSEditorFrame {
+ protocol.getName() + " " + prefs.getString("lang.editor"), ALL_PREFERENCES);
this.protocol = protocol;
- this.taskManager = protocol.getProcess().getSimulationPanel().getTaskManager();
-
init();
}
private void init() {
super.getFrame().disposeWithParent();
super.infoArea.setText(prefs.getString("lang.prefs.protocol.info!"));
- initTaskManagerEditor(clientTaskManagerEditorPanel);
- initClientServerCheckboxes();
createButtonPanel();
}
@@ -55,269 +44,6 @@ public class VSProtocolEditor extends VSEditorFrame {
return buttonPanel;
}
- protected void addToEditPanelFront(JPanel editPanel) {
- super.addToEditPanelFront(editPanel);;
-
- editPanelConstraints.gridy = editPanelRow++;
- editPanel.add(new JLabel(prefs.getString("lang.protocol.tasks.activation")), editPanelConstraints);
-
- editPanelConstraints.insets = insets;
- editPanelConstraints.gridy = editPanelRow++;
- editPanel.add(createClientServerCheckboxes(), editPanelConstraints);
-
- editPanelConstraints.insets = insetsTopSpaceing;
- editPanelConstraints.gridy = editPanelRow++;
- editPanel.add(new JLabel(prefs.getString("lang.protocol.tasks.client")), editPanelConstraints);
- clientComboBox = new JComboBox();
- clientTaskManagerEditorPanel = new JPanel(new GridBagLayout());
- editPanelConstraints.insets = insets;
- editPanelConstraints.gridy = editPanelRow++;
- editPanel.add(clientTaskManagerEditorPanel, editPanelConstraints);
-
- editPanelConstraints.insets = insetsTopSpaceing;
- editPanelConstraints.gridy = editPanelRow++;
- }
-
- private JPanel createClientServerCheckboxes() {
- final String activated = prefs.getString("lang.activate");
- final String client = prefs.getString("lang.protocol.client") + " " + activated;
- final String server = prefs.getString("lang.protocol.server") + " " + activated;
-
- final JPanel panel = new JPanel(new GridBagLayout());
- panel.setBorder(BorderFactory.createLineBorder(Color.black));
-
- int row = 0;
- GridBagConstraints constraints = new GridBagConstraints();
- constraints.fill = GridBagConstraints.HORIZONTAL;
- constraints.ipady = 10;
- constraints.ipadx = 10;
- constraints.insets = new Insets(5, 0, 5, 0);
- constraints.gridy = row++;
- constraints.gridx = 0;
- panel.add(new JLabel(client), constraints);
-
- constraints.gridx = 1;
- clientCheckBox = new JCheckBox();
- clientCheckBox.addChangeListener(new ChangeListener() {
- public void stateChanged(ChangeEvent ce) {
- if (takeOverButton != null && textField != null) {
- AbstractButton abstractButton = (AbstractButton) ce.getSource();
- ButtonModel buttonModel = abstractButton.getModel();
- takeOverButton.setEnabled(buttonModel.isSelected());
- textField.setEnabled(buttonModel.isSelected());
- if (!buttonModel.isSelected()) {
- clientComboBox.setEnabled(false);
- deleteButton.setEnabled(false);
- } else if (clientComboBox.getItemCount() > 0) {
- clientComboBox.setEnabled(true);
- deleteButton.setEnabled(true);
- }
- }
- }
- });
-
- panel.add(clientCheckBox, constraints);
-
- constraints.gridy = row++;
- constraints.gridx = 0;
- panel.add(new JLabel(server), constraints);
-
- constraints.gridx = 1;
- serverCheckBox = new JCheckBox();
- panel.add(serverCheckBox, constraints);
-
- return panel;
- }
-
- private void initClientServerCheckboxes() {
- final String eventName = protocol.getName();
- final VSProcess process = protocol.getProcess();
-
- String protocolKey = "sim."+eventName.toLowerCase()+".client.enabled!";
- clientCheckBox.setSelected(process.getBoolean(protocolKey));
- protocolKey = "sim."+eventName.toLowerCase()+".server.enabled!";
- serverCheckBox.setSelected(process.getBoolean(protocolKey));
-
- }
-
- private void initTaskManagerEditor(JPanel panel) {
- clientComboBox = new JComboBox();
- deleteButton = new JButton(prefs.getString("lang.remove"));
- takeOverButton = new JButton(prefs.getString("lang.takeover"));
- textField = new JTextField();
-
- panel.setBorder(BorderFactory.createLineBorder(Color.black));
-
- int row = 0;
- GridBagConstraints constraints = new GridBagConstraints();
- constraints.fill = GridBagConstraints.HORIZONTAL;
- constraints.ipady = 10;
- constraints.ipadx = 10;
- constraints.insets = new Insets(5, 5, 5, 5);
-
- textField.setText("0000");
- textField.setColumns(10);
- constraints.gridy = row++;
- constraints.gridx = 0;
- panel.add(textField, constraints);
-
- Insets insetsBackup = constraints.insets;
- constraints.insets = new Insets(0, 0, 0, 0);
- constraints.gridx = 1;
- panel.add(new JLabel("ms"), constraints);
-
- constraints.insets = insetsBackup;
- constraints.gridx = 2;
- panel.add(takeOverButton, constraints);
-
- constraints.gridy = row++;
- constraints.gridx = 0;
- resetTaskManager();
- clientComboBox.setBackground(Color.WHITE);
- panel.add(clientComboBox, constraints);
-
- constraints.gridx = 2;
- panel.add(deleteButton, constraints);
-
- ActionListener actionListener = new ActionListener() {
- private boolean isRed;
- public void actionPerformed(ActionEvent ae) {
- if (ae.getActionCommand().equals(prefs.getString("lang.takeover"))) {
- String textValue = textField.getText();
- try {
- Long longValue = Long.valueOf(textValue);
-
- if (longValue.longValue() < 0) {
- textField.setBackground(Color.RED);
- isRed = true;
- return;
- }
-
- clientComboBox.addItem(VSTools.getTimeString(longValue.longValue()));
- clientComboBox.setSelectedIndex(clientComboBox.getItemCount()-1);
- clientComboBox.setEnabled(true);
- sortComboBox(clientComboBox);
- deleteButton.setEnabled(true);
-
- if (isRed) {
- textField.setBackground(Color.WHITE);
- isRed = false;
- }
- } catch (NumberFormatException e) {
- textField.setBackground(Color.RED);
- isRed = true;
- }
-
- } else if (ae.getActionCommand().equals(prefs.getString("lang.remove"))) {
- Object[] objects = clientComboBox.getSelectedObjects();
- for (Object object : objects)
- clientComboBox.removeItem(object);
- if (clientComboBox.getItemCount() == 0) {
- clientComboBox.setEnabled(false);
- deleteButton.setEnabled(false);
- }
- }
- }
- };
-
- takeOverButton.addActionListener(actionListener);
- deleteButton.addActionListener(actionListener);
-
- clientComboBox.setEnabled(false);
- deleteButton.setEnabled(false);
- takeOverButton.setEnabled(false);
- textField.setEnabled(false);
- }
-
- protected void resetEditPanel() {
- super.resetEditPanel();
-
- resetTaskManager();
-
- final VSProcess process = protocol.getProcess();
- final String eventName = protocol.getName();
- String protocolKey = "sim."+eventName.toLowerCase()+".client.enabled!";
- clientCheckBox.setSelected(process.getBoolean(protocolKey));
- protocolKey = "sim."+eventName.toLowerCase()+".server.enabled!";
- serverCheckBox.setSelected(process.getBoolean(protocolKey));
-
- takeOverButton.setEnabled(clientCheckBox.isSelected());
- textField.setEnabled(clientCheckBox.isSelected());
- if (!clientCheckBox.isSelected()) {
- clientComboBox.setEnabled(false);
- deleteButton.setEnabled(false);
- }
- }
-
- protected void savePrefs() {
- super.savePrefs();
- saveTasks();
- }
-
- private void resetTaskManager() {
- clientComboBox.removeAllItems();
- LinkedList<VSTask> protocolVSTasks = taskManager.getProtocolTasks(protocol);
-
- for (VSTask task : protocolVSTasks)
- clientComboBox.addItem(VSTools.getTimeString(task.getTaskTime()));
- }
-
- private void saveTasks() {
- LinkedList<VSTask> tasks = new LinkedList<VSTask>();
- int numItems;
-
- numItems = clientComboBox.getItemCount();
- for (int i = 0; i < numItems; ++i) {
- long taskTime = VSTools.getStringTime((String) clientComboBox.getItemAt(i));
- VSTask task = new VSTask(taskTime, protocol.getProcess(), protocol, VSTask.LOCAL);
- task.isProgrammed(true);
- tasks.addLast(task);
- }
-
- taskManager.modifyProtocolTasks(protocol, tasks);
-
- final VSProcess process = protocol.getProcess();
- final String eventName = protocol.getName();
- String protocolKey = "sim."+eventName.toLowerCase()+".client.enabled!";
- process.setBoolean(protocolKey, clientCheckBox.isSelected());
- protocol.isClient(clientCheckBox.isSelected());
-
- protocolKey = "sim."+eventName.toLowerCase()+".server.enabled!";
- process.setBoolean(protocolKey, serverCheckBox.isSelected());
- protocol.isServer(serverCheckBox.isSelected());
-
- Object protocolsObj = null;
- if (process.objectExists("protocols.registered")) {
- protocolsObj = process.getObject("protocols.registered");
- } else {
- protocolsObj = new Vector<VSProtocol>();
- process.setObject("protocols.registered", protocolsObj);
- }
-
- if (protocolsObj instanceof Vector) {
- Vector<VSProtocol> protocols = (Vector<VSProtocol>) protocolsObj;
- if (!protocols.contains(protocol))
- protocols.add(protocol);
- }
- }
-
- private void sortComboBox(JComboBox comboBox) {
- Object selected = comboBox.getSelectedItem();
- int numItems = comboBox.getItemCount();
- Vector<String> vector = new Vector<String>();
-
- for (int i = 0; i < numItems; ++i) {
- String value = (String) comboBox.getItemAt(i);
- vector.add(value);
- }
-
- Collections.sort(vector);
- comboBox.removeAllItems();
- for (String value : vector)
- comboBox.addItem(value);
- comboBox.setSelectedItem(selected);
- }
-
public void actionPerformed(ActionEvent e) {
String actionCommand = e.getActionCommand();
diff --git a/sources/protocols/VSProtocol.java b/sources/protocols/VSProtocol.java
index 6888d95..9ff1512 100644
--- a/sources/protocols/VSProtocol.java
+++ b/sources/protocols/VSProtocol.java
@@ -53,11 +53,13 @@ abstract public class VSProtocol extends VSEvent {
public void reset() {
if (isServer) {
currentContextIsServer = true;
+ isServer = false;
onServerReset();
}
if (isClient) {
currentContextIsServer = false;
+ isClient = false;
onClientReset();
}
}
diff --git a/sources/simulator/VSSimulation.java b/sources/simulator/VSSimulation.java
index 4b5350d..0748e75 100644
--- a/sources/simulator/VSSimulation.java
+++ b/sources/simulator/VSSimulation.java
@@ -21,6 +21,11 @@ public class VSSimulation extends VSFrame implements ActionListener {
private JCheckBox lamportActiveCheckBox;
private JCheckBox vectorTimeActiveCheckBox;
private JComboBox processesComboBox;
+ private int lastSelectedProcessNum;
+ private ArrayList<String> localTextFields;
+ private ArrayList<String> globalTextFields;
+ private JTextField localTextField;
+ private JTextField globalTextField;
private ArrayList<VSCreateTask> createTasks;
private JMenuItem pauseItem;
private JMenuItem replayItem;
@@ -53,6 +58,16 @@ public class VSSimulation extends VSFrame implements ActionListener {
thread = new Thread(simulationPanel);
//logging.start();
logging.logg(prefs.getString("lang.simulation.new"));
+
+ this.localTextFields = new ArrayList<String>();
+ this.globalTextFields = new ArrayList<String>();
+ int numProcesses = simulationPanel.getNumProcesses();
+
+ for (int i = 0; i < numProcesses; ++i) {
+ localTextFields.add("0000");
+ globalTextFields.add("0000");
+ }
+
}
private JMenuBar createJMenuBar() {
@@ -294,6 +309,7 @@ public class VSSimulation extends VSFrame implements ActionListener {
editPanel.setLayout(new BoxLayout(editPanel, BoxLayout.Y_AXIS));
processesComboBox = new JComboBox();
+ lastSelectedProcessNum = 0;
int numProcesses = simulationPanel.getNumProcesses();
String processString = prefs.getString("lang.process");
for (int i = 1; i <= numProcesses; ++i)
@@ -316,7 +332,16 @@ public class VSSimulation extends VSFrame implements ActionListener {
processesComboBox.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
+ localTextFields.set(lastSelectedProcessNum, localTextField.getText());
+ globalTextFields.set(lastSelectedProcessNum, globalTextField.getText());
updateTaskManagerTable();
+
+ int processNum = getSelectedProcessNum();
+ localTextField.setText(localTextFields.get(processNum));
+ globalTextField.setText(globalTextFields.get(processNum));
+ localTextField.setBackground(Color.WHITE);
+ globalTextField.setBackground(Color.WHITE);
+ lastSelectedProcessNum = processNum;
}
});
@@ -399,12 +424,8 @@ public class VSSimulation extends VSFrame implements ActionListener {
VSEvent event = null;
if (isClientRequest) {
- if (process.objectExists(eventClassname)) {
- event = (VSEvent) process.getObject(eventClassname);
- } else {
- event = VSRegisteredEvents.createEventInstanceByClassname(eventClassname, process);
- process.setObject(eventClassname, event);
- }
+ event = process.getProtocolObject(eventClassname);
+
} else {
event = VSRegisteredEvents.createEventInstanceByClassname(eventClassname, process);
}
@@ -547,6 +568,11 @@ public class VSSimulation extends VSFrame implements ActionListener {
panel1.setLayout(new BoxLayout(panel1, BoxLayout.X_AXIS));
final JTextField textField = new JTextField();
+ if (localTasks)
+ localTextField = textField;
+ else
+ globalTextField = textField;
+
textField.setText("0000");
textField.setBackground(Color.WHITE);
panel1.add(textField);
@@ -787,13 +813,15 @@ public class VSSimulation extends VSFrame implements ActionListener {
}
}
- private VSProcess getSelectedProcess() {
+ private int getSelectedProcessNum() {
String string = (String) processesComboBox.getSelectedItem();
int cutLen = prefs.getString("lang.process").length() + 1;
string = string.substring(cutLen);
- int processNum = Integer.parseInt(string) - 1;
+ return Integer.parseInt(string) - 1;
+ }
- return simulationPanel.getProcess(processNum);
+ private VSProcess getSelectedProcess() {
+ return simulationPanel.getProcess(getSelectedProcessNum());
}
public void updateTaskManagerTable() {