SlideShare a Scribd company logo
You are to simulate a dispatcher using a priority queue system in C++. New processes are to be
entered using a GUI with priority included (numbering should be automatic). Processes are also
to be terminated by GUI command. Context switches are to be by command with the cause of the
switch being either a blocking call, time slice exceeded or termination. Assume only one CPU.
Priorities and numbers of processes can be kept small, just big enough to demonstrate the
required functionality. You may pre-populate the queues initially from a data file. I am looking
at the mechanism as you are NOT creating actual processes, just simulating them. Functionality
to be provided by you: 1. Priority based Ready Queue(s). 2. Blocked list. 3. Output of complete
system status after every context switch showing ready, blocked, and running processes.
Sample Output: A3 Antrian WAKTU TUN... TA1Telah diEksekusi Ambil No Antrian
Solution
//dispatcherSim.java
public class dispatcherSim {
public static void main(String[] args)
{
simulator sim=new simulator(1000);
sim.addProcessReady(1); //test data
sim.addProcessReady(3);
sim.addProcessReady(2);
sim.addProcessReady(7);
sim.addProcessReady(4);
sim.addProcessBlocked(1);
sim.addProcessBlocked(3);
sim.addProcessBlocked(2);
sim.addProcessBlocked(7);
sim.addProcessBlocked(4);
GUI gui=new GUI(sim);
gui.setVisible(true);
}
}
=====================================================================
=========
//GUI.java
import java.awt.BorderLayout;
import java.awt.Dialog.ModalityType;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
public class GUI extends JFrame {
private JPanel panel;
private JMenuBar menuBar;
private JMenu menu;
private JMenuItem addNew;
private JMenuItem unBlock;
private JMenuItem terminate;
private JMenuItem readMe;
private JMenuItem exit;
private JButton cSwitch;
private JTextArea info;
private JScrollPane scroll;
private simulator sim;
private final String CS = "CONTEXT SWITCH: ";
private int count = 1;
public GUI(simulator disSim) {
sim = disSim;
initComponents();
}
private void addNewBox() {
final JDialog addDialog = new JDialog();
JPanel miniPanel = new JPanel(new BorderLayout());
miniPanel.setPreferredSize(new Dimension(175, 100));
ButtonGroup radioGroup = new ButtonGroup();
final JRadioButton blocked = new JRadioButton("Blocked List");
final JRadioButton ready = new JRadioButton("Ready Queue");
ready.setSelected(true);
radioGroup.add(ready);
radioGroup.add(blocked);
JPanel radios = new JPanel();
radios.setPreferredSize(new Dimension(50, 50));
radios.add(ready);
radios.add(blocked);
final JTextField text = new JTextField(10);
JButton addButton = new JButton("Add");
addButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
int temp = Integer.parseInt(text.getText());
if (blocked.isSelected()) {
sim.addProcessBlocked(temp);
info.setText(info.getText()
+ " Added Process to the Blocked List "
+ sim.getStatus());
} else {
sim.addProcessReady(temp);
info.setText(info.getText()
+ " Added Process to the Ready Queue "
+ sim.getStatus());
}
addDialog.dispose();
} catch (NumberFormatException n) {
GUI.errorMessage("Please Enter a Number");
}
}
});
JLabel title = new JLabel(" Type in priority");
miniPanel.add(title, BorderLayout.NORTH);
miniPanel.add(addButton, BorderLayout.WEST);
miniPanel.add(text, BorderLayout.EAST);
miniPanel.add(radios, BorderLayout.SOUTH);
addDialog.setTitle("Add New Process");
addDialog.add(miniPanel);
addDialog.setResizable(false);
addDialog.pack();
addDialog.setLocationRelativeTo(null);
addDialog.setModal(true);
addDialog.setAlwaysOnTop(true);
addDialog.setModalityType(ModalityType.APPLICATION_MODAL);
addDialog.setVisible(true);
}
private void blockerBox() {
final JDialog addDialog = new JDialog();
JPanel miniPanel = new JPanel(new BorderLayout());
miniPanel.setPreferredSize(new Dimension(220, 100));
JLabel title = new JLabel(" Select Process ID");
JPanel leftPanel = new JPanel();
leftPanel.setPreferredSize(new Dimension(110, 75));
JPanel rightPanel = new JPanel();
rightPanel.setPreferredSize(new Dimension(110, 75));
final JComboBox blockBox = new JComboBox();
Object[] tempP = sim.getReadyQueue().toArray();
for (int i = 0; i < tempP.length; i++) {
blockBox.addItem(((Process) tempP[i]).getID());
}
blockBox.setEditable(false);
JButton block = new JButton("Block");
block.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Object[] tempArray = sim.getReadyQueue().toArray();
for (int i = 0; i < tempArray.length; i++) {
if (((Process) tempArray[i]).getID().equals(
(String) blockBox.getSelectedItem())) {
sim.getReadyQueue().remove(((Process) tempArray[i]));
sim.getBlockedList().add(((Process) tempArray[i]));
}
}
info.setText(info.getText() + " Blocked Process "
+ (String) blockBox.getSelectedItem() + " "
+ sim.getStatus());
addDialog.dispose();
}
});
leftPanel.add(block, BorderLayout.NORTH);
leftPanel.add(blockBox, BorderLayout.SOUTH);
final JComboBox unBlockBox = new JComboBox();
for (int i = 0; i < sim.getBlockedList().size(); i++) {
unBlockBox.addItem(sim.getBlockedList().get(i).getID());
}
unBlockBox.setEditable(false);
JButton unBlock = new JButton("UnBlock");
unBlock.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
for(int i=0; i termBox = new JComboBox();
kill.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Object[] tempArray = sim.getReadyQueue().toArray();
for (int i = 0; i < tempArray.length; i++) {
if (((Process) tempArray[i]).getID().equals(
(String) termBox.getSelectedItem()))
sim.getReadyQueue().remove(((Process) tempArray[i]));
}
for (int i = 0; i < sim.getBlockedList().size(); i++) {
if (sim.getBlockedList().get(i).getID()
.equals((String) termBox.getSelectedItem()))
sim.getBlockedList().remove(i);
}
info.setText(info.getText() + " Terminated Process "
+ (String) termBox.getSelectedItem() + " "
+ sim.getStatus());
addDialog.dispose();
}
});
Object[] tempP = sim.getReadyQueue().toArray();
for (int i = 0; i < tempP.length; i++) {
termBox.addItem(((Process) tempP[i]).getID());
}
for (int i = 0; i < sim.getBlockedList().size(); i++) {
termBox.addItem(sim.getBlockedList().get(i).getID());
}
termBox.setEditable(false);
miniPanel.add(title, BorderLayout.NORTH);
miniPanel.add(kill, BorderLayout.CENTER);
miniPanel.add(termBox, BorderLayout.SOUTH);
addDialog.setTitle("Kill Process");
addDialog.add(miniPanel);
addDialog.setResizable(false);
addDialog.pack();
addDialog.setLocationRelativeTo(null);
addDialog.setModal(true);
addDialog.setAlwaysOnTop(true);
addDialog.setModalityType(ModalityType.APPLICATION_MODAL);
addDialog.setVisible(true);
}
private void initComponents() {
setTitle("CS 471 Dispatcher Simulator");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setResizable(false);
panel = new JPanel(new BorderLayout());
panel.setPreferredSize(new Dimension(550, 380));
add(panel);
menuBar = new JMenuBar();
menu = new JMenu("Options");
addNew = new JMenuItem("Add New");
addNew.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
addNewBox();
}
});
readMe = new JMenuItem("Readme");
readMe.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
readMe();
}
});
unBlock = new JMenuItem("(Un)Block");
unBlock.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
blockerBox();
}
});
terminate = new JMenuItem("Terminate");
terminate.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
terminationBox();
}
});
exit = new JMenuItem("Exit");
exit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
dispose();
}
});
menu.add(addNew);
menu.add(unBlock);
menu.add(terminate);
menu.add(readMe);
menu.add(exit);
menuBar.add(menu);
cSwitch = new JButton("Context Switch");
cSwitch.setPreferredSize(new Dimension(150, 50));
cSwitch.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
sim.contextSwitch();
info.setText(info.getText() + " " + CS + (count++) + " "
+ sim.getStatus());
}
});
info = new JTextArea();
info.setEditable(false);
scroll = new JScrollPane(info, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
scroll.setToolTipText("Output");
info.setText(sim.getStatus());
scroll.setPreferredSize(new Dimension(400, 300));
panel.add(scroll, BorderLayout.EAST);
panel.add(cSwitch, BorderLayout.WEST);
setJMenuBar(menuBar);
setLocation(650, 350);
setVisible(true);
pack();
}
private void readMe() {
String readMe = "CS471 Operating Systems Summer Session Term Project "
+ "Author: Matthew Redenius " + "UIN: 00773960 "
+ "Name: Dispatcher Simulator 1.0  "
+ "This program is intended to simulate a dispatcher "
+ "using a priority queue system. This program has a "
+ "fake priority queue, blocked list, and running "
+ "process. It allows the user to add and terminate "
+ "processes in the ready queue and blocked list. "
+ "It also allows the user to block processss in the "
+ "ready queue, and unblock processes in the blocked "
+ "list  "
+ "When adding a process, the user only needs to enter "
+ "the desired priority and the ID is automatically "
+ "generated.  "
+ "Once all desired processes are loaded, the user can "
+ "perform a context switch to load the next process in "
+ "the ready queue into execution. "
+ " In main, there is test data provided.";
JFrame frame = new JFrame("README");
JPanel panel = new JPanel();
JTextArea label = new JTextArea(readMe);
panel.add(label);
frame.add(panel);
frame.setResizable(false);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
public static void errorMessage(String message) {
JDialog addDialog = new JDialog();
JPanel miniPanel = new JPanel(new BorderLayout());
miniPanel.setPreferredSize(new Dimension(175, 100));
JLabel mess = new JLabel(message);
miniPanel.add(mess);
addDialog.add(miniPanel);
addDialog.setTitle("ERROR");
addDialog.setResizable(false);
addDialog.pack();
addDialog.setLocationRelativeTo(null);
addDialog.setModal(true);
addDialog.setAlwaysOnTop(true);
addDialog.setModalityType(ModalityType.APPLICATION_MODAL);
addDialog.setVisible(true);
}
}
=====================================================================
==
//Process.java
public class Process {
private int priority;
private String id;
private boolean executing;
private boolean blocked;
private boolean ready;
public Process(int p, String i)
{
id=i;
priority=p;
executing=false;
blocked=false;
ready=false;
}
public String getID()
{
return id;
}
public int getPriority()
{
return priority;
}
public boolean isExecuting()
{
return executing;
}
public boolean isReady()
{
return ready;
}
public boolean isBlocked()
{
return blocked;
}
public void setExec(boolean e)
{
executing=e;
}
public void setBlocked(boolean b)
{
blocked=b;
}
public void setReady(boolean r)
{
ready=r;
}
}
=====================================================================
===
//simulator.java
import java.util.ArrayList;
import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.Random;
public class simulator {
private PriorityQueue readyQueue;
private Process runningProcess;
private ArrayList blockedList;
private ArrayList allProcesses;
private Random generator;
public simulator(int queueSize) {
generator = new Random(9999);
Comparator comparator = new ProcessComparator();
readyQueue = new PriorityQueue(queueSize, comparator);
blockedList = new ArrayList(queueSize);
allProcesses = new ArrayList(queueSize);
}
public void start() {
runningProcess = removeProcess();
runningProcess.setReady(false);
runningProcess.setBlocked(false);
runningProcess.setExec(true);
}
public void print() {
while (readyQueue.size() != 0) {
System.out.println(removeProcess().getID());
}
}
public void addProcessReady(int pr) {
Process p = makeNewProcess(pr);
p.setReady(true);
p.setBlocked(false);
p.setExec(false);
readyQueue.add(p);
}
public void addProcessBlocked(int pr) {
Process p = makeNewProcess(pr);
p.setReady(false);
p.setBlocked(true);
p.setExec(false);
blockedList.add(p);
}
public Process makeNewProcess(int p) {
String ran = Integer.toString(generator.nextInt(9999));
Process i = new Process(p, ran);
return i;
}
public Process removeProcess() {
return readyQueue.remove();
}
public Process getRunningProcess() {
return runningProcess;
}
public ArrayList getBlockedList() {
return blockedList;
}
public ArrayList getAllProcesses() {
return allProcesses;
}
public PriorityQueue getReadyQueue() {
return readyQueue;
}
public String getStatus() {
String init = "Running ";
if (runningProcess != null) {
init = init + "tProcess ID: " + runningProcess.getID() + " "
+ "Priority: " + runningProcess.getPriority() + " ";
} else {
init = init + "tProcess ID: " + "NULL" + " " + "Priority: "
+ "NULL" + " ";
}
init = init + "Ready Queue ";
if (!readyQueue.isEmpty()) {
Object[] tempP = getReadyQueue().toArray();
for (int i = 0; i < tempP.length; i++) {
Process tempProc = readyQueue.remove();
init = init + "tProcess ID: " + tempProc.getID() + " "
+ "Priority: " + tempProc.getPriority() + " ";
}
for (int i = 0; i < tempP.length; i++) {
readyQueue.add((Process) tempP[i]);
}
} else {
init = init + "tEmpty ";
}
init = init + "BlockedList ";
if (!blockedList.isEmpty()) {
for (int i = 0; i < blockedList.size(); i++) {
init = init + "tProcess ID: " + blockedList.get(i).getID()
+ " " + "Priority: "
+ blockedList.get(i).getPriority() + " ";
}
} else {
init = init + "tEmpty ";
}
return init;
}
public void contextSwitch() {
if (!readyQueue.isEmpty()) {
runningProcess = readyQueue.remove();
} else {
runningProcess = null;
}
}
private class ProcessComparator implements Comparator {
public int compare(Process arg0, Process arg1) {
if (arg0.getPriority() < arg1.getPriority()) {
return -1;
}
if (arg0.getPriority() > arg1.getPriority()) {
return 1;
}
return 0;
}
}
}

More Related Content

Similar to You are to simulate a dispatcher using a priority queue system in C+.pdf

Working effectively with legacy code
Working effectively with legacy codeWorking effectively with legacy code
Working effectively with legacy codeShriKant Vashishtha
 
CodeZipButtonDemo.javaCodeZipButtonDemo.java Demonstrate a p.docx
CodeZipButtonDemo.javaCodeZipButtonDemo.java Demonstrate a p.docxCodeZipButtonDemo.javaCodeZipButtonDemo.java Demonstrate a p.docx
CodeZipButtonDemo.javaCodeZipButtonDemo.java Demonstrate a p.docx
mary772
 
CodeZipButtonDemo.javaCodeZipButtonDemo.java Demonstrate a p.docx
CodeZipButtonDemo.javaCodeZipButtonDemo.java Demonstrate a p.docxCodeZipButtonDemo.javaCodeZipButtonDemo.java Demonstrate a p.docx
CodeZipButtonDemo.javaCodeZipButtonDemo.java Demonstrate a p.docx
mccormicknadine86
 
code for quiz in my sql
code for quiz  in my sql code for quiz  in my sql
code for quiz in my sql
JOYITAKUNDU1
 
How do I make my JTable non editableimport java.awt.; import j.pdf
How do I make my JTable non editableimport java.awt.; import j.pdfHow do I make my JTable non editableimport java.awt.; import j.pdf
How do I make my JTable non editableimport java.awt.; import j.pdf
forwardcom41
 
Creating a Facebook Clone - Part XLVI - Transcript.pdf
Creating a Facebook Clone - Part XLVI - Transcript.pdfCreating a Facebook Clone - Part XLVI - Transcript.pdf
Creating a Facebook Clone - Part XLVI - Transcript.pdf
ShaiAlmog1
 
3. Section 3 � Complete functionality on listing screen (1.5 marks.pdf
3. Section 3 � Complete functionality on listing screen (1.5 marks.pdf3. Section 3 � Complete functionality on listing screen (1.5 marks.pdf
3. Section 3 � Complete functionality on listing screen (1.5 marks.pdf
alliedscorporation
 
Binary patching for fun and profit @ JUG.ru, 25.02.2012
Binary patching for fun and profit @ JUG.ru, 25.02.2012Binary patching for fun and profit @ JUG.ru, 25.02.2012
Binary patching for fun and profit @ JUG.ru, 25.02.2012Anton Arhipov
 
Griffon @ Svwjug
Griffon @ SvwjugGriffon @ Svwjug
Griffon @ Svwjug
Andres Almiray
 
How to write clean tests
How to write clean testsHow to write clean tests
How to write clean tests
Danylenko Max
 
help me Java projectI put problem and my own code in the linkmy .pdf
help me Java projectI put problem and my own code in the linkmy .pdfhelp me Java projectI put problem and my own code in the linkmy .pdf
help me Java projectI put problem and my own code in the linkmy .pdf
arihantmum
 
Jersey Guice AOP
Jersey Guice AOPJersey Guice AOP
Jersey Guice AOP
Domenico Briganti
 
Creating a Facebook Clone - Part XXIX - Transcript.pdf
Creating a Facebook Clone - Part XXIX - Transcript.pdfCreating a Facebook Clone - Part XXIX - Transcript.pdf
Creating a Facebook Clone - Part XXIX - Transcript.pdf
ShaiAlmog1
 
Advance Java Programs skeleton
Advance Java Programs skeletonAdvance Java Programs skeleton
Advance Java Programs skeleton
Iram Ramrajkar
 
Google App Engine Developer - Day3
Google App Engine Developer - Day3Google App Engine Developer - Day3
Google App Engine Developer - Day3
Simon Su
 
Tricks to Making a Realtime SurfaceView Actually Perform in Realtime - Maarte...
Tricks to Making a Realtime SurfaceView Actually Perform in Realtime - Maarte...Tricks to Making a Realtime SurfaceView Actually Perform in Realtime - Maarte...
Tricks to Making a Realtime SurfaceView Actually Perform in Realtime - Maarte...
DroidConTLV
 
Implement a queue using a linkedlist (java)SolutionLinkedQueue.pdf
Implement a queue using a linkedlist (java)SolutionLinkedQueue.pdfImplement a queue using a linkedlist (java)SolutionLinkedQueue.pdf
Implement a queue using a linkedlist (java)SolutionLinkedQueue.pdf
kostikjaylonshaewe47
 
Whats new in_csharp4
Whats new in_csharp4Whats new in_csharp4
Whats new in_csharp4Abed Bukhari
 
Assignment no39
Assignment no39Assignment no39
Assignment no39Jay Patel
 

Similar to You are to simulate a dispatcher using a priority queue system in C+.pdf (20)

Working effectively with legacy code
Working effectively with legacy codeWorking effectively with legacy code
Working effectively with legacy code
 
CodeZipButtonDemo.javaCodeZipButtonDemo.java Demonstrate a p.docx
CodeZipButtonDemo.javaCodeZipButtonDemo.java Demonstrate a p.docxCodeZipButtonDemo.javaCodeZipButtonDemo.java Demonstrate a p.docx
CodeZipButtonDemo.javaCodeZipButtonDemo.java Demonstrate a p.docx
 
CodeZipButtonDemo.javaCodeZipButtonDemo.java Demonstrate a p.docx
CodeZipButtonDemo.javaCodeZipButtonDemo.java Demonstrate a p.docxCodeZipButtonDemo.javaCodeZipButtonDemo.java Demonstrate a p.docx
CodeZipButtonDemo.javaCodeZipButtonDemo.java Demonstrate a p.docx
 
code for quiz in my sql
code for quiz  in my sql code for quiz  in my sql
code for quiz in my sql
 
How do I make my JTable non editableimport java.awt.; import j.pdf
How do I make my JTable non editableimport java.awt.; import j.pdfHow do I make my JTable non editableimport java.awt.; import j.pdf
How do I make my JTable non editableimport java.awt.; import j.pdf
 
Creating a Facebook Clone - Part XLVI - Transcript.pdf
Creating a Facebook Clone - Part XLVI - Transcript.pdfCreating a Facebook Clone - Part XLVI - Transcript.pdf
Creating a Facebook Clone - Part XLVI - Transcript.pdf
 
3. Section 3 � Complete functionality on listing screen (1.5 marks.pdf
3. Section 3 � Complete functionality on listing screen (1.5 marks.pdf3. Section 3 � Complete functionality on listing screen (1.5 marks.pdf
3. Section 3 � Complete functionality on listing screen (1.5 marks.pdf
 
Binary patching for fun and profit @ JUG.ru, 25.02.2012
Binary patching for fun and profit @ JUG.ru, 25.02.2012Binary patching for fun and profit @ JUG.ru, 25.02.2012
Binary patching for fun and profit @ JUG.ru, 25.02.2012
 
Griffon @ Svwjug
Griffon @ SvwjugGriffon @ Svwjug
Griffon @ Svwjug
 
How to write clean tests
How to write clean testsHow to write clean tests
How to write clean tests
 
help me Java projectI put problem and my own code in the linkmy .pdf
help me Java projectI put problem and my own code in the linkmy .pdfhelp me Java projectI put problem and my own code in the linkmy .pdf
help me Java projectI put problem and my own code in the linkmy .pdf
 
Jersey Guice AOP
Jersey Guice AOPJersey Guice AOP
Jersey Guice AOP
 
C# labprograms
C# labprogramsC# labprograms
C# labprograms
 
Creating a Facebook Clone - Part XXIX - Transcript.pdf
Creating a Facebook Clone - Part XXIX - Transcript.pdfCreating a Facebook Clone - Part XXIX - Transcript.pdf
Creating a Facebook Clone - Part XXIX - Transcript.pdf
 
Advance Java Programs skeleton
Advance Java Programs skeletonAdvance Java Programs skeleton
Advance Java Programs skeleton
 
Google App Engine Developer - Day3
Google App Engine Developer - Day3Google App Engine Developer - Day3
Google App Engine Developer - Day3
 
Tricks to Making a Realtime SurfaceView Actually Perform in Realtime - Maarte...
Tricks to Making a Realtime SurfaceView Actually Perform in Realtime - Maarte...Tricks to Making a Realtime SurfaceView Actually Perform in Realtime - Maarte...
Tricks to Making a Realtime SurfaceView Actually Perform in Realtime - Maarte...
 
Implement a queue using a linkedlist (java)SolutionLinkedQueue.pdf
Implement a queue using a linkedlist (java)SolutionLinkedQueue.pdfImplement a queue using a linkedlist (java)SolutionLinkedQueue.pdf
Implement a queue using a linkedlist (java)SolutionLinkedQueue.pdf
 
Whats new in_csharp4
Whats new in_csharp4Whats new in_csharp4
Whats new in_csharp4
 
Assignment no39
Assignment no39Assignment no39
Assignment no39
 

More from JUSTSTYLISH3B2MOHALI

In a business projects What material is typically contained in a pro.pdf
In a business projects What material is typically contained in a pro.pdfIn a business projects What material is typically contained in a pro.pdf
In a business projects What material is typically contained in a pro.pdf
JUSTSTYLISH3B2MOHALI
 
Implement the following flowchart in java. Start Request integer k f.pdf
Implement the following flowchart in java. Start Request integer k f.pdfImplement the following flowchart in java. Start Request integer k f.pdf
Implement the following flowchart in java. Start Request integer k f.pdf
JUSTSTYLISH3B2MOHALI
 
If no chiasma forms between homologous chromosomes, what happens Th.pdf
If no chiasma forms between homologous chromosomes, what happens  Th.pdfIf no chiasma forms between homologous chromosomes, what happens  Th.pdf
If no chiasma forms between homologous chromosomes, what happens Th.pdf
JUSTSTYLISH3B2MOHALI
 
If two organims form a symbiotic realtionship where they share t.pdf
If two organims form a symbiotic realtionship where they share t.pdfIf two organims form a symbiotic realtionship where they share t.pdf
If two organims form a symbiotic realtionship where they share t.pdf
JUSTSTYLISH3B2MOHALI
 
I would appreciate help with these 4 questions. Thank You.1) Expla.pdf
I would appreciate help with these 4 questions. Thank You.1) Expla.pdfI would appreciate help with these 4 questions. Thank You.1) Expla.pdf
I would appreciate help with these 4 questions. Thank You.1) Expla.pdf
JUSTSTYLISH3B2MOHALI
 
How do I know when to use the sin^2+cos^2=1 identity....12 angle id.pdf
How do I know when to use the sin^2+cos^2=1 identity....12 angle id.pdfHow do I know when to use the sin^2+cos^2=1 identity....12 angle id.pdf
How do I know when to use the sin^2+cos^2=1 identity....12 angle id.pdf
JUSTSTYLISH3B2MOHALI
 
I have a stack in Java populated with integers. Im trying to compa.pdf
I have a stack in Java populated with integers. Im trying to compa.pdfI have a stack in Java populated with integers. Im trying to compa.pdf
I have a stack in Java populated with integers. Im trying to compa.pdf
JUSTSTYLISH3B2MOHALI
 
Hint List of commands to read and use use of wild card characters .pdf
Hint List of commands to read and use use of wild card characters .pdfHint List of commands to read and use use of wild card characters .pdf
Hint List of commands to read and use use of wild card characters .pdf
JUSTSTYLISH3B2MOHALI
 
Explain in Detail DTE-DCE TransmissionSolutionFirstly the DTE-.pdf
Explain in Detail DTE-DCE TransmissionSolutionFirstly the DTE-.pdfExplain in Detail DTE-DCE TransmissionSolutionFirstly the DTE-.pdf
Explain in Detail DTE-DCE TransmissionSolutionFirstly the DTE-.pdf
JUSTSTYLISH3B2MOHALI
 
Explain the data component of social media information systems (SMIS).pdf
Explain the data component of social media information systems (SMIS).pdfExplain the data component of social media information systems (SMIS).pdf
Explain the data component of social media information systems (SMIS).pdf
JUSTSTYLISH3B2MOHALI
 
Figure CWhich structure in the cell shown in Figure C above stores.pdf
Figure CWhich structure in the cell shown in Figure C above stores.pdfFigure CWhich structure in the cell shown in Figure C above stores.pdf
Figure CWhich structure in the cell shown in Figure C above stores.pdf
JUSTSTYLISH3B2MOHALI
 
Coral reefs. How sensitive to changes in water temperature are coral .pdf
Coral reefs. How sensitive to changes in water temperature are coral .pdfCoral reefs. How sensitive to changes in water temperature are coral .pdf
Coral reefs. How sensitive to changes in water temperature are coral .pdf
JUSTSTYLISH3B2MOHALI
 
•0.336 moles of a weak, monoproticacid added to a final volume of 2..pdf
•0.336 moles of a weak, monoproticacid added to a final volume of 2..pdf•0.336 moles of a weak, monoproticacid added to a final volume of 2..pdf
•0.336 moles of a weak, monoproticacid added to a final volume of 2..pdf
JUSTSTYLISH3B2MOHALI
 
Write a program that accepts an arithmetic expression of unsigned in.pdf
Write a program that accepts an arithmetic expression of unsigned in.pdfWrite a program that accepts an arithmetic expression of unsigned in.pdf
Write a program that accepts an arithmetic expression of unsigned in.pdf
JUSTSTYLISH3B2MOHALI
 
Why was the knowledge of macromolecules “structure” very important i.pdf
Why was the knowledge of macromolecules “structure” very important i.pdfWhy was the knowledge of macromolecules “structure” very important i.pdf
Why was the knowledge of macromolecules “structure” very important i.pdf
JUSTSTYLISH3B2MOHALI
 
Why did the sovereign debt problem of Greece a country that accounts.pdf
Why did the sovereign debt problem of Greece a country that accounts.pdfWhy did the sovereign debt problem of Greece a country that accounts.pdf
Why did the sovereign debt problem of Greece a country that accounts.pdf
JUSTSTYLISH3B2MOHALI
 
Which of the following could be the most likely cause of a superi.pdf
Which of the following could be the most likely cause of a superi.pdfWhich of the following could be the most likely cause of a superi.pdf
Which of the following could be the most likely cause of a superi.pdf
JUSTSTYLISH3B2MOHALI
 
What is the theory of public debt managementSolution1. Sove.pdf
What is the theory of public debt managementSolution1. Sove.pdfWhat is the theory of public debt managementSolution1. Sove.pdf
What is the theory of public debt managementSolution1. Sove.pdf
JUSTSTYLISH3B2MOHALI
 
This is a three part question. For each part the answer requires ide.pdf
This is a three part question. For each part the answer requires ide.pdfThis is a three part question. For each part the answer requires ide.pdf
This is a three part question. For each part the answer requires ide.pdf
JUSTSTYLISH3B2MOHALI
 
Complete a personal SWOT analysis evaluating your understanding and .pdf
Complete a personal SWOT analysis evaluating your understanding and .pdfComplete a personal SWOT analysis evaluating your understanding and .pdf
Complete a personal SWOT analysis evaluating your understanding and .pdf
JUSTSTYLISH3B2MOHALI
 

More from JUSTSTYLISH3B2MOHALI (20)

In a business projects What material is typically contained in a pro.pdf
In a business projects What material is typically contained in a pro.pdfIn a business projects What material is typically contained in a pro.pdf
In a business projects What material is typically contained in a pro.pdf
 
Implement the following flowchart in java. Start Request integer k f.pdf
Implement the following flowchart in java. Start Request integer k f.pdfImplement the following flowchart in java. Start Request integer k f.pdf
Implement the following flowchart in java. Start Request integer k f.pdf
 
If no chiasma forms between homologous chromosomes, what happens Th.pdf
If no chiasma forms between homologous chromosomes, what happens  Th.pdfIf no chiasma forms between homologous chromosomes, what happens  Th.pdf
If no chiasma forms between homologous chromosomes, what happens Th.pdf
 
If two organims form a symbiotic realtionship where they share t.pdf
If two organims form a symbiotic realtionship where they share t.pdfIf two organims form a symbiotic realtionship where they share t.pdf
If two organims form a symbiotic realtionship where they share t.pdf
 
I would appreciate help with these 4 questions. Thank You.1) Expla.pdf
I would appreciate help with these 4 questions. Thank You.1) Expla.pdfI would appreciate help with these 4 questions. Thank You.1) Expla.pdf
I would appreciate help with these 4 questions. Thank You.1) Expla.pdf
 
How do I know when to use the sin^2+cos^2=1 identity....12 angle id.pdf
How do I know when to use the sin^2+cos^2=1 identity....12 angle id.pdfHow do I know when to use the sin^2+cos^2=1 identity....12 angle id.pdf
How do I know when to use the sin^2+cos^2=1 identity....12 angle id.pdf
 
I have a stack in Java populated with integers. Im trying to compa.pdf
I have a stack in Java populated with integers. Im trying to compa.pdfI have a stack in Java populated with integers. Im trying to compa.pdf
I have a stack in Java populated with integers. Im trying to compa.pdf
 
Hint List of commands to read and use use of wild card characters .pdf
Hint List of commands to read and use use of wild card characters .pdfHint List of commands to read and use use of wild card characters .pdf
Hint List of commands to read and use use of wild card characters .pdf
 
Explain in Detail DTE-DCE TransmissionSolutionFirstly the DTE-.pdf
Explain in Detail DTE-DCE TransmissionSolutionFirstly the DTE-.pdfExplain in Detail DTE-DCE TransmissionSolutionFirstly the DTE-.pdf
Explain in Detail DTE-DCE TransmissionSolutionFirstly the DTE-.pdf
 
Explain the data component of social media information systems (SMIS).pdf
Explain the data component of social media information systems (SMIS).pdfExplain the data component of social media information systems (SMIS).pdf
Explain the data component of social media information systems (SMIS).pdf
 
Figure CWhich structure in the cell shown in Figure C above stores.pdf
Figure CWhich structure in the cell shown in Figure C above stores.pdfFigure CWhich structure in the cell shown in Figure C above stores.pdf
Figure CWhich structure in the cell shown in Figure C above stores.pdf
 
Coral reefs. How sensitive to changes in water temperature are coral .pdf
Coral reefs. How sensitive to changes in water temperature are coral .pdfCoral reefs. How sensitive to changes in water temperature are coral .pdf
Coral reefs. How sensitive to changes in water temperature are coral .pdf
 
•0.336 moles of a weak, monoproticacid added to a final volume of 2..pdf
•0.336 moles of a weak, monoproticacid added to a final volume of 2..pdf•0.336 moles of a weak, monoproticacid added to a final volume of 2..pdf
•0.336 moles of a weak, monoproticacid added to a final volume of 2..pdf
 
Write a program that accepts an arithmetic expression of unsigned in.pdf
Write a program that accepts an arithmetic expression of unsigned in.pdfWrite a program that accepts an arithmetic expression of unsigned in.pdf
Write a program that accepts an arithmetic expression of unsigned in.pdf
 
Why was the knowledge of macromolecules “structure” very important i.pdf
Why was the knowledge of macromolecules “structure” very important i.pdfWhy was the knowledge of macromolecules “structure” very important i.pdf
Why was the knowledge of macromolecules “structure” very important i.pdf
 
Why did the sovereign debt problem of Greece a country that accounts.pdf
Why did the sovereign debt problem of Greece a country that accounts.pdfWhy did the sovereign debt problem of Greece a country that accounts.pdf
Why did the sovereign debt problem of Greece a country that accounts.pdf
 
Which of the following could be the most likely cause of a superi.pdf
Which of the following could be the most likely cause of a superi.pdfWhich of the following could be the most likely cause of a superi.pdf
Which of the following could be the most likely cause of a superi.pdf
 
What is the theory of public debt managementSolution1. Sove.pdf
What is the theory of public debt managementSolution1. Sove.pdfWhat is the theory of public debt managementSolution1. Sove.pdf
What is the theory of public debt managementSolution1. Sove.pdf
 
This is a three part question. For each part the answer requires ide.pdf
This is a three part question. For each part the answer requires ide.pdfThis is a three part question. For each part the answer requires ide.pdf
This is a three part question. For each part the answer requires ide.pdf
 
Complete a personal SWOT analysis evaluating your understanding and .pdf
Complete a personal SWOT analysis evaluating your understanding and .pdfComplete a personal SWOT analysis evaluating your understanding and .pdf
Complete a personal SWOT analysis evaluating your understanding and .pdf
 

Recently uploaded

How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
MysoreMuleSoftMeetup
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
SACHIN R KONDAGURI
 
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat  Leveraging AI for Diversity, Equity, and InclusionExecutive Directors Chat  Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
TechSoup
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBCSTRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
kimdan468
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Dr. Vinod Kumar Kanvaria
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
vaibhavrinwa19
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
Israel Genealogy Research Association
 
Multithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race conditionMultithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race condition
Mohammed Sikander
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
TechSoup
 
Digital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion DesignsDigital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion Designs
chanes7
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 

Recently uploaded (20)

How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
 
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat  Leveraging AI for Diversity, Equity, and InclusionExecutive Directors Chat  Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBCSTRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
 
Multithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race conditionMultithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race condition
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
 
Digital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion DesignsDigital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion Designs
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 

You are to simulate a dispatcher using a priority queue system in C+.pdf

  • 1. You are to simulate a dispatcher using a priority queue system in C++. New processes are to be entered using a GUI with priority included (numbering should be automatic). Processes are also to be terminated by GUI command. Context switches are to be by command with the cause of the switch being either a blocking call, time slice exceeded or termination. Assume only one CPU. Priorities and numbers of processes can be kept small, just big enough to demonstrate the required functionality. You may pre-populate the queues initially from a data file. I am looking at the mechanism as you are NOT creating actual processes, just simulating them. Functionality to be provided by you: 1. Priority based Ready Queue(s). 2. Blocked list. 3. Output of complete system status after every context switch showing ready, blocked, and running processes. Sample Output: A3 Antrian WAKTU TUN... TA1Telah diEksekusi Ambil No Antrian Solution //dispatcherSim.java public class dispatcherSim { public static void main(String[] args) { simulator sim=new simulator(1000); sim.addProcessReady(1); //test data sim.addProcessReady(3); sim.addProcessReady(2); sim.addProcessReady(7); sim.addProcessReady(4); sim.addProcessBlocked(1); sim.addProcessBlocked(3); sim.addProcessBlocked(2); sim.addProcessBlocked(7); sim.addProcessBlocked(4); GUI gui=new GUI(sim); gui.setVisible(true); } } ===================================================================== =========
  • 2. //GUI.java import java.awt.BorderLayout; import java.awt.Dialog.ModalityType; import java.awt.Dimension; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.ButtonGroup; import javax.swing.JButton; import javax.swing.JComboBox; import javax.swing.JDialog; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.JMenuItem; import javax.swing.JPanel; import javax.swing.JRadioButton; import javax.swing.JScrollPane; import javax.swing.JTextArea; import javax.swing.JTextField; public class GUI extends JFrame { private JPanel panel; private JMenuBar menuBar; private JMenu menu; private JMenuItem addNew; private JMenuItem unBlock; private JMenuItem terminate; private JMenuItem readMe; private JMenuItem exit; private JButton cSwitch; private JTextArea info; private JScrollPane scroll; private simulator sim; private final String CS = "CONTEXT SWITCH: "; private int count = 1; public GUI(simulator disSim) {
  • 3. sim = disSim; initComponents(); } private void addNewBox() { final JDialog addDialog = new JDialog(); JPanel miniPanel = new JPanel(new BorderLayout()); miniPanel.setPreferredSize(new Dimension(175, 100)); ButtonGroup radioGroup = new ButtonGroup(); final JRadioButton blocked = new JRadioButton("Blocked List"); final JRadioButton ready = new JRadioButton("Ready Queue"); ready.setSelected(true); radioGroup.add(ready); radioGroup.add(blocked); JPanel radios = new JPanel(); radios.setPreferredSize(new Dimension(50, 50)); radios.add(ready); radios.add(blocked); final JTextField text = new JTextField(10); JButton addButton = new JButton("Add"); addButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { try { int temp = Integer.parseInt(text.getText()); if (blocked.isSelected()) { sim.addProcessBlocked(temp); info.setText(info.getText() + " Added Process to the Blocked List " + sim.getStatus()); } else { sim.addProcessReady(temp); info.setText(info.getText() + " Added Process to the Ready Queue " + sim.getStatus()); } addDialog.dispose(); } catch (NumberFormatException n) {
  • 4. GUI.errorMessage("Please Enter a Number"); } } }); JLabel title = new JLabel(" Type in priority"); miniPanel.add(title, BorderLayout.NORTH); miniPanel.add(addButton, BorderLayout.WEST); miniPanel.add(text, BorderLayout.EAST); miniPanel.add(radios, BorderLayout.SOUTH); addDialog.setTitle("Add New Process"); addDialog.add(miniPanel); addDialog.setResizable(false); addDialog.pack(); addDialog.setLocationRelativeTo(null); addDialog.setModal(true); addDialog.setAlwaysOnTop(true); addDialog.setModalityType(ModalityType.APPLICATION_MODAL); addDialog.setVisible(true); } private void blockerBox() { final JDialog addDialog = new JDialog(); JPanel miniPanel = new JPanel(new BorderLayout()); miniPanel.setPreferredSize(new Dimension(220, 100)); JLabel title = new JLabel(" Select Process ID"); JPanel leftPanel = new JPanel(); leftPanel.setPreferredSize(new Dimension(110, 75)); JPanel rightPanel = new JPanel(); rightPanel.setPreferredSize(new Dimension(110, 75)); final JComboBox blockBox = new JComboBox(); Object[] tempP = sim.getReadyQueue().toArray(); for (int i = 0; i < tempP.length; i++) { blockBox.addItem(((Process) tempP[i]).getID()); } blockBox.setEditable(false); JButton block = new JButton("Block"); block.addActionListener(new ActionListener() {
  • 5. public void actionPerformed(ActionEvent e) { Object[] tempArray = sim.getReadyQueue().toArray(); for (int i = 0; i < tempArray.length; i++) { if (((Process) tempArray[i]).getID().equals( (String) blockBox.getSelectedItem())) { sim.getReadyQueue().remove(((Process) tempArray[i])); sim.getBlockedList().add(((Process) tempArray[i])); } } info.setText(info.getText() + " Blocked Process " + (String) blockBox.getSelectedItem() + " " + sim.getStatus()); addDialog.dispose(); } }); leftPanel.add(block, BorderLayout.NORTH); leftPanel.add(blockBox, BorderLayout.SOUTH); final JComboBox unBlockBox = new JComboBox(); for (int i = 0; i < sim.getBlockedList().size(); i++) { unBlockBox.addItem(sim.getBlockedList().get(i).getID()); } unBlockBox.setEditable(false); JButton unBlock = new JButton("UnBlock"); unBlock.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { for(int i=0; i termBox = new JComboBox(); kill.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Object[] tempArray = sim.getReadyQueue().toArray(); for (int i = 0; i < tempArray.length; i++) { if (((Process) tempArray[i]).getID().equals( (String) termBox.getSelectedItem())) sim.getReadyQueue().remove(((Process) tempArray[i])); } for (int i = 0; i < sim.getBlockedList().size(); i++) { if (sim.getBlockedList().get(i).getID()
  • 6. .equals((String) termBox.getSelectedItem())) sim.getBlockedList().remove(i); } info.setText(info.getText() + " Terminated Process " + (String) termBox.getSelectedItem() + " " + sim.getStatus()); addDialog.dispose(); } }); Object[] tempP = sim.getReadyQueue().toArray(); for (int i = 0; i < tempP.length; i++) { termBox.addItem(((Process) tempP[i]).getID()); } for (int i = 0; i < sim.getBlockedList().size(); i++) { termBox.addItem(sim.getBlockedList().get(i).getID()); } termBox.setEditable(false); miniPanel.add(title, BorderLayout.NORTH); miniPanel.add(kill, BorderLayout.CENTER); miniPanel.add(termBox, BorderLayout.SOUTH); addDialog.setTitle("Kill Process"); addDialog.add(miniPanel); addDialog.setResizable(false); addDialog.pack(); addDialog.setLocationRelativeTo(null); addDialog.setModal(true); addDialog.setAlwaysOnTop(true); addDialog.setModalityType(ModalityType.APPLICATION_MODAL); addDialog.setVisible(true); } private void initComponents() { setTitle("CS 471 Dispatcher Simulator"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setResizable(false); panel = new JPanel(new BorderLayout()); panel.setPreferredSize(new Dimension(550, 380));
  • 7. add(panel); menuBar = new JMenuBar(); menu = new JMenu("Options"); addNew = new JMenuItem("Add New"); addNew.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { addNewBox(); } }); readMe = new JMenuItem("Readme"); readMe.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { readMe(); } }); unBlock = new JMenuItem("(Un)Block"); unBlock.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { blockerBox(); } }); terminate = new JMenuItem("Terminate"); terminate.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { terminationBox(); } }); exit = new JMenuItem("Exit"); exit.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { dispose(); } }); menu.add(addNew); menu.add(unBlock); menu.add(terminate);
  • 8. menu.add(readMe); menu.add(exit); menuBar.add(menu); cSwitch = new JButton("Context Switch"); cSwitch.setPreferredSize(new Dimension(150, 50)); cSwitch.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { sim.contextSwitch(); info.setText(info.getText() + " " + CS + (count++) + " " + sim.getStatus()); } }); info = new JTextArea(); info.setEditable(false); scroll = new JScrollPane(info, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); scroll.setToolTipText("Output"); info.setText(sim.getStatus()); scroll.setPreferredSize(new Dimension(400, 300)); panel.add(scroll, BorderLayout.EAST); panel.add(cSwitch, BorderLayout.WEST); setJMenuBar(menuBar); setLocation(650, 350); setVisible(true); pack(); } private void readMe() { String readMe = "CS471 Operating Systems Summer Session Term Project " + "Author: Matthew Redenius " + "UIN: 00773960 " + "Name: Dispatcher Simulator 1.0 " + "This program is intended to simulate a dispatcher " + "using a priority queue system. This program has a " + "fake priority queue, blocked list, and running " + "process. It allows the user to add and terminate " + "processes in the ready queue and blocked list. " + "It also allows the user to block processss in the "
  • 9. + "ready queue, and unblock processes in the blocked " + "list " + "When adding a process, the user only needs to enter " + "the desired priority and the ID is automatically " + "generated. " + "Once all desired processes are loaded, the user can " + "perform a context switch to load the next process in " + "the ready queue into execution. " + " In main, there is test data provided."; JFrame frame = new JFrame("README"); JPanel panel = new JPanel(); JTextArea label = new JTextArea(readMe); panel.add(label); frame.add(panel); frame.setResizable(false); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); } public static void errorMessage(String message) { JDialog addDialog = new JDialog(); JPanel miniPanel = new JPanel(new BorderLayout()); miniPanel.setPreferredSize(new Dimension(175, 100)); JLabel mess = new JLabel(message); miniPanel.add(mess); addDialog.add(miniPanel); addDialog.setTitle("ERROR"); addDialog.setResizable(false); addDialog.pack(); addDialog.setLocationRelativeTo(null); addDialog.setModal(true); addDialog.setAlwaysOnTop(true); addDialog.setModalityType(ModalityType.APPLICATION_MODAL); addDialog.setVisible(true); }
  • 10. } ===================================================================== == //Process.java public class Process { private int priority; private String id; private boolean executing; private boolean blocked; private boolean ready; public Process(int p, String i) { id=i; priority=p; executing=false; blocked=false; ready=false; } public String getID() { return id; } public int getPriority() { return priority; } public boolean isExecuting() { return executing; } public boolean isReady() { return ready; } public boolean isBlocked() {
  • 11. return blocked; } public void setExec(boolean e) { executing=e; } public void setBlocked(boolean b) { blocked=b; } public void setReady(boolean r) { ready=r; } } ===================================================================== === //simulator.java import java.util.ArrayList; import java.util.Comparator; import java.util.PriorityQueue; import java.util.Random; public class simulator { private PriorityQueue readyQueue; private Process runningProcess; private ArrayList blockedList; private ArrayList allProcesses; private Random generator; public simulator(int queueSize) { generator = new Random(9999); Comparator comparator = new ProcessComparator(); readyQueue = new PriorityQueue(queueSize, comparator); blockedList = new ArrayList(queueSize); allProcesses = new ArrayList(queueSize); } public void start() {
  • 12. runningProcess = removeProcess(); runningProcess.setReady(false); runningProcess.setBlocked(false); runningProcess.setExec(true); } public void print() { while (readyQueue.size() != 0) { System.out.println(removeProcess().getID()); } } public void addProcessReady(int pr) { Process p = makeNewProcess(pr); p.setReady(true); p.setBlocked(false); p.setExec(false); readyQueue.add(p); } public void addProcessBlocked(int pr) { Process p = makeNewProcess(pr); p.setReady(false); p.setBlocked(true); p.setExec(false); blockedList.add(p); } public Process makeNewProcess(int p) { String ran = Integer.toString(generator.nextInt(9999)); Process i = new Process(p, ran); return i; } public Process removeProcess() { return readyQueue.remove(); } public Process getRunningProcess() { return runningProcess; } public ArrayList getBlockedList() {
  • 13. return blockedList; } public ArrayList getAllProcesses() { return allProcesses; } public PriorityQueue getReadyQueue() { return readyQueue; } public String getStatus() { String init = "Running "; if (runningProcess != null) { init = init + "tProcess ID: " + runningProcess.getID() + " " + "Priority: " + runningProcess.getPriority() + " "; } else { init = init + "tProcess ID: " + "NULL" + " " + "Priority: " + "NULL" + " "; } init = init + "Ready Queue "; if (!readyQueue.isEmpty()) { Object[] tempP = getReadyQueue().toArray(); for (int i = 0; i < tempP.length; i++) { Process tempProc = readyQueue.remove(); init = init + "tProcess ID: " + tempProc.getID() + " " + "Priority: " + tempProc.getPriority() + " "; } for (int i = 0; i < tempP.length; i++) { readyQueue.add((Process) tempP[i]); } } else { init = init + "tEmpty "; } init = init + "BlockedList "; if (!blockedList.isEmpty()) { for (int i = 0; i < blockedList.size(); i++) { init = init + "tProcess ID: " + blockedList.get(i).getID() + " " + "Priority: "
  • 14. + blockedList.get(i).getPriority() + " "; } } else { init = init + "tEmpty "; } return init; } public void contextSwitch() { if (!readyQueue.isEmpty()) { runningProcess = readyQueue.remove(); } else { runningProcess = null; } } private class ProcessComparator implements Comparator { public int compare(Process arg0, Process arg1) { if (arg0.getPriority() < arg1.getPriority()) { return -1; } if (arg0.getPriority() > arg1.getPriority()) { return 1; } return 0; } } }