org.mycore.util.concurrent.MCRPrioritySupplier Maven / Gradle / Ivy
/*
* This file is part of *** M y C o R e ***
* See http://www.mycore.de/ for details.
*
* MyCoRe is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* MyCoRe is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with MyCoRe. If not, see .
*/
package org.mycore.util.concurrent;
import java.util.concurrent.atomic.AtomicLong;
import java.util.function.Supplier;
/**
* A supplier with a priority.
*
* stackoverflow
*
* @author Matthias Eichner
*
* @param the type of results supplied by this supplier
*/
public class MCRPrioritySupplier implements Supplier, MCRPrioritizable {
private static AtomicLong CREATION_COUNTER = new AtomicLong(0);
private Supplier delegate;
private int priority;
private long created;
public MCRPrioritySupplier(Supplier delegate, int priority) {
this.delegate = delegate;
this.priority = priority;
this.created = CREATION_COUNTER.incrementAndGet();
}
@Override
public T get() {
return delegate.get();
}
@Override
public int getPriority() {
return this.priority;
}
@Override
public long getCreated() {
return created;
}
}