Java代写:CSE214DownloadScheduler


代写一个下载的调度器程序,这个作业仍然是考察基础的数据结构的应用。

Background

Computer hard drives are made of spinning platters, which hold billions (or
even trillions) of little magnetic cells, each of which holds a 0 or a 1 in
its polarity. In these cells, bits are stored, and cells together hold the
data and files on most computers. The data in hard drives is read by a “read-
write head” that picks a particular circle on the hard drive, and reads all
the data as the hard disk spins. Due to hard drive construction, file I/O is
fastest when bits are read sequentially (no jumping around between files).
The Insta-Cram corporation owns a server farm in a top-secret location on Long
Island, from where they deliver illicit videos of professors delivering
computer science lectures, which were stealthily recorded and furtively
uploaded by enterprising students. Since their service is usually free, there
is a lot of demand for downloading their videos. Insta-cram stores their
videos on multiple hard-drives, each tied to a different server. They have
hired you to write a download scheduler for their service, in order to make
sure that users who request videos first are served first. Additionally,
Insta-Cram offers a premium membership, where, for the low price of $2.14 per
month, a user gets to access the next available download slot, bypassing the
free users.
You will be implementing the download scheduler as a set of queues. Each
download will have a size between approximately 114 and 219 megabytes,
selected randomly. You will be given a number of servers to work with; all of
these will have a fixed file transfer speed. You will get a number of premium
and free users, with a download request probability for each category at every
given second (timestep). The servers will have to complete one job before
starting the next, and every time the premium users request a job, it must be
given the next available time slot.
At the end of the “day” (at the end of program execution), you will be
required to print some stats, including the total number of jobs served to
premium customers, total number of jobs served to regular customers, the total
number of megabytes served to premium customers, and the total number of
megabytes served to regular customers (the number of megabytes should get
updated after file download is completed).

Required Classes

DownloadManager

  • public static void main(String args)
    • Displays menu asking for
      • Probability Of Regular Job per Timestep
      • Probability Of Premium Job per Timestep
      • Download Speed (mbps)
      • Number Of Servers
      • Simulation Length
    • Each timestep is printed to the screen until the end of the simulation. Information in timestep includes:
      • Regular Queue
      • Premium Queue
      • Information about each job currently in a server
      • Summary about any jobs that were dequeued
    • Summary at the end of the program
      • Number of Regular Jobs Downloaded (completed)
      • Number of Premium Jobs Downloaded (completed)
      • Average regular wait time (for completed jobs, from time queued to time finished)
      • Average premium wait time (for completed jobs, from time queued to time finished)
      • Total Size of Regular Jobs (completed, in Mb)
      • Total Size of Premium Jobs (completed, in Mb)
      • Total Megabytes served (completed jobs)

DownloadScheduler

  • private DownloadQueue regularQ - This is the queue where you will store the regular download jobs
  • private DownloadQueue premiumQ - This is the queue where you will store the premium download jobs. Connected with the regularQ, this forms a two-level priority queue. You will always dequeue from this queue until it is empty before dequeueing from the regularQ.
  • private int currentTime - This is where you store the time elapsed since the start of the simulation.
  • private int simulationEndTime - this stores the time when the simulation should end.
  • private DownloadRandomizer random - this will generate jobs at each timestep. We will give this to you. You must use this class as provided, with NO MODIFICATIONS.
  • private DownloadJob[] CurrentJobs - This is where you store the jobs that are currently downloading. Once a job is done downloading, you can remove it from the array (at the end of the timestep), update the statistics, and replace it with a new job.
    Precondition: the CurrentJobs array, download speed, probabilities of various
    jobs, and queues have been initialized.
  • private int downloadSpeed - This stores the speed of the download in Megabytes Per Second. If a job finishes partway through a second (ie: download speed =10Mbps, job size=214mb), you should wait until the beginning of the next second to remove it and add replace it with a new job.
  • public String simulate() - this method creates a simulation based on the user input.

DownloadQueue

This queue will be of DownloadJob objects and you may implement it as you
wish. If you choose to use Java API classes, you must use inheritance (extend
a Java API class) to simplify the class definition. Your queue should have
these public methods:

  • public void/boolean enqueue(DownloadJob d) - adds d to the end of the queue. You may use either void or boolean for this method.
  • public DownloadJob dequeue() - takes the DownloadJob that is at the front of the queue, saves the value, removes the DownloadJob from the queue, and returns the Value. If the queue was empty, throw an EmptyQueueException.
  • public DownloadJob peek() - takes the DownloadJob that is at the front of the queue, and returns that value to the caller. Does NOT remove that DownloadJob from the queue. If the queue was empty, throw an EmptyQueueException.
  • public boolean isEmpty() - returns true if queue is empty, false otherwise.
    The details for these methods are standard queue methods. You can find those
    details in the lecture slides.

DownloadJob

  • private int downloadSize
  • private int downloadSizeRemaining - so you can easily keep track of how much has been downloaded
  • private int timeRequested - timestamp of when the job was requested (so you can calculate average wait time for the download).
  • private boolean isPremium - stores whether this is a regular or a premium download.
  • private int id - starts at 1 , increases.

DownloadRandomizer

  • We will provide this class to you. You must use this as provided, with no modifications. You do not need to submit this class with your assignment.
  • This class is documented as to how you should use it.
  • We may make changes to this class when grading your HW, but if your program works with what we provide, we can promise your program will work with the grading version.
  • You DO NOT need to submit this with your assignment.

General Recommendations

You might want to implement a toString() method for classes to make debugging
and printing easier. You do not have to do this, but it will help you.
You can feel free to add any extra methods and variables as you see fit
(public and private).

UI Required Functions

Initialization Inputs:

  • Number of Servers
  • Server Download Speed (megabytes/second)
  • Probability of regular client download request in one second
  • Probability of premium client download request in one second
  • Simulation Time (in seconds).

文章作者: SafePoker
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 SafePoker !
  目录