简体   繁体   中英

Creating a thread-safe class responsible for reordering events

My friend was given this as one of the tasks to do over the summer holidays. Him and I are very confused as to how to go on about completing this task.

The bit where it says "Your class should also take another implementation of EventConsumer in its constructor to pass the reordered events to." is very confusing we really don't know what it's asking.

We are not looking for you to do this for us, all we're asking for is some guidance, we're quite new to programming so please go easy on us.

Here is the question: http://postimg.org/image/snytvxvkr/

Here are the classes they have provided:

Event.java

package tests.task2;

import java.util.*;


public interface Event {

    public String getEventId();

    public String getEventType();

    public Calendar getEventTimestamp();

}

EventConsumer.java

package tests.task2;

public interface EventConsumer {

    public void consumeEvent(Event theEvent);

}

Use announcer framework to send n consume events. With the announcer framework you can even provide multiple implementations of your "EventConsumer" interface.

Check here

"Your class should also take another implementation of EventConsumer in its constructor to pass the reordered events to." =

public class MyEventConsumer implements EventConsumer {

    private EventConsumer target;

    public MyEventConsumer (EventConsumer target) {
        // Do something with the target.
        // probably you want to store it in an instance variable...
        this.target = target;
    }

    public void consumeEvent (Event event) {
        // ...so you can use it here
    }

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM