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

com.github.phantomthief.pool.impl.KeyAffinityExecutorForStats Maven / Gradle / Ivy

The newest version!
package com.github.phantomthief.pool.impl;

import java.util.Iterator;
import java.util.concurrent.Callable;

import com.github.phantomthief.pool.KeyAffinityExecutor;
import com.github.phantomthief.pool.KeyAffinityExecutorStats;
import com.github.phantomthief.util.ThrowableRunnable;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;

/**
 * @author w.vela
 * Created on 2018-11-29.
 */
class KeyAffinityExecutorForStats implements KeyAffinityExecutor {

    private final KeyAffinityExecutor delegate;

    private KeyAffinityExecutorForStats(KeyAffinityExecutor delegate) {
        this.delegate = delegate;
    }

    static  KeyAffinityExecutor wrapStats(KeyAffinityExecutor executor) {
        if (executor instanceof KeyAffinityExecutorForStats) {
            return executor;
        } else {
            return new KeyAffinityExecutorForStats<>(executor);
        }
    }

    @Override
    public boolean inited() {
        return delegate.inited();
    }

    @Override
    public void close() {
        throw new UnsupportedOperationException();
    }

    @Override
    public Iterator iterator() {
        return delegate.iterator();
    }

    @Override
    public  ListenableFuture submit(K key, Callable task) {
        return delegate.submit(key, task);
    }

    @Override
    public void executeEx(K key, ThrowableRunnable task) {
        delegate.executeEx(key, task);
    }

    @Override
    public KeyAffinityExecutorStats stats() {
        if (delegate.inited()) {
            return delegate.stats();
        } else {
            return null;
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy