Results 1 to 7 of 7
  1. #1
    veronica is offline Member
    Join Date
    Feb 2011
    Posts
    13
    Rep Power
    0

    Question how to implement "buffering"

    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

  2. #2
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default

    Any suggestion?
    Yes. I suggest you write something and then show use where you are having trouble :D
    Last edited by quad64bit; 03-01-2011 at 01:40 AM. Reason: typo

  3. #3
    veronica is offline Member
    Join Date
    Feb 2011
    Posts
    13
    Rep Power
    0

    Default

    the question is: how can I implement the buffer?

    meaning that I ask for an idea, a java tool, or something that could possibly help me to write some code in the right direction.
    In other words: what is a buffer in java?

    Thanks a lot.

  4. #4
    gcalvin is offline Senior Member
    Join Date
    Mar 2010
    Posts
    953
    Rep Power
    5

    Default

    I think what you'll want here (although it's hard to know for sure without seeing more of your design/code) is a Queue.

    Queue (Java Platform SE 6)

    A Queue is a Collection, like a List or a Set, but is designed for First-In, First-Out (FIFO). You add objects to the end of a Queue, and pull them off at the head. Because it's a Collection, you can report what is in the Queue at any particular time.

    Queue is an Interface, so you need to choose an implementation for your project. Unless you know you want something different, I would suggest a LinkedList.

    That should give you some direction, anyway, but I can't be sure it's the right direction without knowing quite a bit more. Good luck!

    -Gary-

  5. #5
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default

    The second question is this, are you to implement a buffer in java, or do you need a buffer that uses java? This is an important distinction. In the former case, you must write it from scratch because thats what you are being graded on. In the latter, don't reinvent the wheel and use code that has been well written for you as gcalvin suggested.

  6. #6
    gcalvin is offline Senior Member
    Join Date
    Mar 2010
    Posts
    953
    Rep Power
    5

    Default

    @OP: Looking again at your initial post, it seems you already have a design that uses LinkedLists. I'm not quite clear on what you mean by "stable storage" though. Does that mean that each Servant needs to save its queue to a text file or something?

    Maybe if you give us the full requirements, and any code you've written already, it will be clearer. We're not going to do the assignment for you, of course, but we can probably give you better pointers.

    -Gary-

  7. #7
    DarrylBurke's Avatar
    DarrylBurke is online now Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,404
    Rep Power
    20

Similar Threads

  1. Replies: 3
    Last Post: 10-12-2010, 04:21 PM
  2. Java, Military Format using "/" and "%" Operator!!
    By sk8rsam77 in forum New To Java
    Replies: 11
    Last Post: 02-26-2010, 03:03 AM
  3. Replies: 1
    Last Post: 01-21-2010, 09:20 AM
  4. Replies: 2
    Last Post: 01-24-2009, 06:56 PM
  5. Replies: 1
    Last Post: 10-20-2008, 07:35 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •