dmachop
BAN USER- 0of 0 votes
AnswersYou are given a limit buffer class that has two parameters - window in milliseconds and a threshold of the buffer. This means that the buffer can hold threshold amount of items within window in milliseconds.
There is a stream of data that consists of an event name:
call_backup, retrieve_data, call_backup, log_info, backup_log...
which is added onto the LimitBuffer. Write a logic that calls alert(..) when the buffer exceeds the threshold for a given window.
- dmachop in United Statesclass LimitBuffer { public LimitBuffer(long windowMs, int threshold) { } private void alert(String eventName) { } public void addEvent(String eventName) { } } /*class LimitBufferTester { LimitBuffer buffer = new LimitBuffer(2000, 30); while(true) { String randomStr = null; buffer.addEvent(randomStr); } }*/
| Report Duplicate | Flag | PURGE
Hired.com Java Developer
@emb Yes. This is what is given to me and you can add any member/methods on top of this class. When this deals with a size limited buffer, there should be an eviction logic along with this. For example, limitBuffer(1000, 20) means that the instance can hold a maximum of 20 items in 1 millisecond. If there are about 20 items and a new item is about to be added within a span of 1 millisecond, the class should call alert stating that this item could not be added because maximum capacity has exceeded. A few practical examples that I can think about is the maximum messages that can be held by a mailbox for a year or the maximum api calls that is held per day.
- dmachop June 11, 2016