Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please write java code only where it indicates. do not change any other code that is already written. thank you 9.8 LAB: Timeout manager with

Please write java code only where it indicates. do not change any other code that is already written. thank you

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

9.8 LAB: Timeout manager with PriorityQueue Timeout manager overview A timeout manager stores a priority queue of timeout items, each a (callback method, callback time) pair. Each callback method is called approximately N milliseconds after the timeout is set, where N is the delay specified when adding the timeout item. Ex: - At time t=0, a 500 millisecond timeout is set for method A - At time t=100, a 3000 millisecond timeout is set for method B - At time t=2000, a 1000 millisecond timeout is set for method C So the timeout manager should call the callbacks as follows: - Call method A at time t=0+500=500 - Call method C at time t=2000+1000=3000 - Call method B at time t=100+3000=3100 A timeout item with a callback time t=500 with a delay of 1000 has callbackTime = 500+1000=1500. The callbackMethod private field is the method to call after the timeout expires. Timeoutltem implements the compareTo0 method so that Timeoutltems can be put in a PriorityQueue that gives higher priority to lesser callbackTime values. Step 2: Inspect MillisecondClock.java and TestClock.java MillisecondClock is an abstract base class for a clock. The getTime( method returns an integer indicating the clock's current time, in milliseconds. Inspect the class declarations in the read only TestClock.java file. Times are simulated during grading using the TestClock class. TestClock extends MillisecondClock and allows the clock's time to be set via the setTime 0 method. Step 3: Implement TimeoutManager's addTimeout() and update() methods Complete the TimeoutManager class implementation in TimeoutManager.java. addTimeout() must add a new Timeoutltem to the priority queue that expires delayBeforeCal lback milliseconds after the current time. update 0 must dequeue and call the callback method for each expired timeout item. Use TimeoutManager's clock field to get the current time. Step 4: Test in develop mode, then submit File LabProgram.java contains two automated tests that can be run in develop mode. Each adds timeouts and invokes updates at various times, then verifies that the proper callback methods are called during each update. Additional tests can be added, if desired. Ensure that the two tests in develop mode pass before submitting you code. File is marked as read only Current file: MillisecondClock.java - 1 public abstract class MillisecondClock \{ 2 abstract int getTime(); 3} 4 public class TestClock extends MillisecondClock \{ private int currentTime; public TestClock() currentTime =0; @ @verride public int getTime() return currentTime; \} I/ Sets this clock's current time, provided the new time is greater than the // previously set time. public boolean setTime(int newTime) \{ /l Only allow time to move forward if (newTime > currentTime) currentTime = newTime; return true; \} return false; File is marked as read only Current file: Timeoutltem.java - Current file: TimeoutManager.java - Load default template

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Connect 2-semester For Auditing & Assurance Services A Systematic Approach

Authors: Author

10th Edition

1259292045, 9781259292040

More Books

Students also viewed these Accounting questions

Question

differentiate the function ( x + 1 ) / ( x ^ 3 + x - 6 )

Answered: 1 week ago

Question

4. Explain how to price managerial and professional jobs.

Answered: 1 week ago