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

org.elasticsearch.common.util.concurrent.PrioritizedCallable Maven / Gradle / Ivy

There is a newer version: 8.14.0
Show newest version
/*
 * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
 * or more contributor license agreements. Licensed under the Elastic License
 * 2.0 and the Server Side Public License, v 1; you may not use this file except
 * in compliance with, at your election, the Elastic License 2.0 or the Server
 * Side Public License, v 1.
 */
package org.elasticsearch.common.util.concurrent;

import org.elasticsearch.common.Priority;

import java.util.concurrent.Callable;

public abstract class PrioritizedCallable implements Callable, Comparable> {

    private final Priority priority;

    public static  PrioritizedCallable wrap(Callable callable, Priority priority) {
        return new Wrapped<>(callable, priority);
    }

    protected PrioritizedCallable(Priority priority) {
        this.priority = priority;
    }

    @Override
    public int compareTo(PrioritizedCallable pc) {
        return priority.compareTo(pc.priority);
    }

    public Priority priority() {
        return priority;
    }

    static class Wrapped extends PrioritizedCallable {

        private final Callable callable;

        private Wrapped(Callable callable, Priority priority) {
            super(priority);
            this.callable = callable;
        }

        @Override
        public T call() throws Exception {
            return callable.call();
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy