All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.alibaba.schedulerx.worker.pull.BlockingContainerQueue Maven / Gradle / Ivy

There is a newer version: 1.12.2
Show newest version
package com.alibaba.schedulerx.worker.pull;

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

import com.alibaba.schedulerx.protocol.Worker.MasterStartContainerRequest;

/**
 *
 * @author xiaomeng.hxm
 */
public class BlockingContainerQueue {

    private final BlockingQueue queue;

    public BlockingContainerQueue(int capacity) {
        this.queue = new LinkedBlockingQueue<>(capacity);
    }

    public MasterStartContainerRequest get() throws InterruptedException {
        return queue.poll(5, TimeUnit.SECONDS);
    }

    public boolean put(MasterStartContainerRequest request) throws InterruptedException {
        return queue.offer(request, 5, TimeUnit.SECONDS);
    }

    public void clear() {
        queue.clear();
    }

    public int size() {
        return queue.size();
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy