Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

how to implement "buffering"  RSS feed

 
mari bo
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everybody,

I have a little problem of implementation of a buffer in my project. There is a distributed system, where there are a Boss and a fixed number of Servants.
Servants have to do tasks(implemented by the "sleep" function).
The Boss has to send a "CHECKPOINT"request to the Servants. After Servants has received that message from the Boss, they have to memorize their own state (the number of tasks) in stable storage. While doing that, no message has to be send. So if a Servant gets a CHeCKPOINT message from the Boss, then it has to buffer the task(s) it was doing, and save its own state in memory.

Now the question is: how can I implement the buffer?

At the moment, every servant has an input LinkedList for the incoming messages, and an output LinkedList for the outgoing messages. When it has to do a task, the servants read the first taask to do from the incoming linkedList. So if it is doing task and in the meanwhile a CHECKpoint-request comes, it has to be able to buffer the task and reply to the CHECKPOINT REQUEST.

Any suggestion?

Thank you for your attention and for your answers!

veronica
 
Clarence Gillespie
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I understand your problem correctly, you might try one of the following:


The stack would work well to push the current tasks down on the stack you create. When the servant is done, they would just need to pop them back off the stack.
java.util.Stack

Implementing one of the following interfaces may be something you want to look at as well.

java.util.Queue
java.util.Deque

Check your java docs for more info.

Hope it helps.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!