aboutsummaryrefslogtreecommitdiffstats
path: root/jdisc_messagebus_service/src/main/java/com/yahoo/messagebus/jdisc/test/ReplyQueue.java
blob: 236365a255dfffcc32676e8a220da1b3dafe42ce (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.messagebus.jdisc.test;

import com.yahoo.messagebus.Reply;
import com.yahoo.messagebus.ReplyHandler;

import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;

/**
 * @author <a href="mailto:simon@yahoo-inc.com">Simon Thoresen</a>
 */
public class ReplyQueue implements ReplyHandler {

    private final BlockingQueue<Reply> queue = new LinkedBlockingQueue<>();

    @Override
    public void handleReply(Reply reply) {
        queue.add(reply);
    }

    public Reply awaitReply(int timeout, TimeUnit unit) throws InterruptedException {
        return queue.poll(timeout, unit);
    }
}