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

org.glassfish.enterprise.concurrent.ManagedScheduledExecutorServiceAdapter Maven / Gradle / Ivy

/*
 * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved.
 * Copyright (c) 2022 Payara Foundation and/or its affiliates.
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License v. 2.0, which is available at
 * http://www.eclipse.org/legal/epl-2.0.
 *
 * This Source Code may also be made available under the following Secondary
 * Licenses when the conditions for such availability set forth in the
 * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
 * version 2 with the GNU Classpath Exception, which is available at
 * https://www.gnu.org/software/classpath/license.html.
 *
 * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
 */

package org.glassfish.enterprise.concurrent;

import jakarta.enterprise.concurrent.ContextService;
import java.util.Collection;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import jakarta.enterprise.concurrent.ManagedScheduledExecutorService;
import jakarta.enterprise.concurrent.Trigger;
import org.glassfish.enterprise.concurrent.internal.ManagedCompletableFuture;

import java.util.function.Supplier;

/**
 * The ManagedScheduledExecutorService instance to be handed to the
 * application components, with all life cycle operations overriden to 
 * throw UnSupportedException.
 */
public class ManagedScheduledExecutorServiceAdapter
        extends AbstractManagedExecutorServiceAdapter
        implements ManagedScheduledExecutorService {

    private ManagedScheduledExecutorService executor;

    public ManagedScheduledExecutorServiceAdapter(ManagedScheduledExecutorService executor) {
        this.executor = executor;
    }

    @Override
    public void execute(Runnable command) {
        executor.execute(command);
    }

    @Override
    public Future submit(Runnable task) {
        return executor.submit(task);
    }

    @Override
    public  Future submit(Runnable task, T result) {
        return executor.submit(task, result);
    }

    @Override
    public  Future submit(Callable task) {
        return executor.submit(task);
    }

    @Override
    public  T invokeAny(Collection> tasks, long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException {
        return executor.invokeAny(tasks, timeout, unit);
    }

    @Override
    public  T invokeAny(Collection> tasks) throws InterruptedException, ExecutionException {
        return executor.invokeAny(tasks);
    }

    @Override
    public  List> invokeAll(Collection> tasks, long timeout, TimeUnit unit) throws InterruptedException {
        return executor.invokeAll(tasks, timeout, unit);
    }

    @Override
    public  List> invokeAll(Collection> tasks) throws InterruptedException {
        return executor.invokeAll(tasks);
    }

    @Override
    public ScheduledFuture scheduleWithFixedDelay(Runnable command, long initialDelay, long delay, TimeUnit unit) {
        return executor.scheduleWithFixedDelay(command, initialDelay, delay, unit);
    }

    @Override
    public ScheduledFuture scheduleAtFixedRate(Runnable command, long initialDelay, long period, TimeUnit unit) {
        return executor.scheduleAtFixedRate(command, initialDelay, period, unit);
    }

    @Override
    public  ScheduledFuture schedule(Callable callable, long delay, TimeUnit unit) {
        return executor.schedule(callable, delay, unit);
    }

    @Override
    public ScheduledFuture schedule(Runnable command, long delay, TimeUnit unit) {
        return executor.schedule(command, delay, unit);
    }

    @Override
    public  ScheduledFuture schedule(Callable callable, Trigger trigger) {
        return executor.schedule(callable, trigger);
    }

    @Override
    public ScheduledFuture schedule(Runnable command, Trigger trigger) {
        return executor.schedule(command, trigger);
    }

    @Override
    public  CompletableFuture completedFuture(U value) {
        return ManagedCompletableFuture.completedFuture(value, executor);
    }

    @Override
    public  CompletionStage completedStage(U value) {
        return ManagedCompletableFuture.completedStage(value, executor);
    }

    @Override
    public  CompletableFuture copy(CompletableFuture future) {
        return executor.copy(future);
    }

    @Override
    public  CompletionStage copy(CompletionStage completionStage) {
        return executor.copy(completionStage);
    }

    @Override
    public  CompletableFuture failedFuture(Throwable ex) {
        return ManagedCompletableFuture.failedFuture(ex, this);
    }

    @Override
    public  CompletionStage failedStage(Throwable ex) {
        return ManagedCompletableFuture.failedStage(ex, this);
    }

    @Override
    public ContextService getContextService() {
        return executor.getContextService();
    }

    @Override
    public  CompletableFuture newIncompleteFuture() {
        return new ManagedCompletableFuture<>(executor);
    }

    @Override
    public CompletableFuture runAsync(Runnable runnable) {
        return ManagedCompletableFuture.runAsync(runnable, executor);
    }

    @Override
    public  CompletableFuture supplyAsync(Supplier supplier) {
        return ManagedCompletableFuture.supplyAsync(supplier, executor);
    }

}