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

io.leoplatform.sdk.ExternalExecutorManager Maven / Gradle / Ivy

The newest version!
package io.leoplatform.sdk;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.inject.Inject;
import javax.inject.Singleton;
import java.util.Optional;
import java.util.concurrent.Executor;

@Singleton
public class ExternalExecutorManager implements ExecutorManager {
    private static final Logger log = LoggerFactory.getLogger(ExternalExecutorManager.class);

    private final Executor externalService;

    @Inject
    public ExternalExecutorManager(Executor executor) {
        this.externalService = validate(executor);
        log.info("Registered user executor");
    }

    @Override
    public Executor get() {
        return externalService;
    }

    @Override
    public void add(Runnable r) {
        externalService.execute(r);
    }

    @Override
    public void end() {
        log.info("Not stopping registered executor");
    }

    private Executor validate(Executor executor) {
        return Optional.ofNullable(executor)
                .orElseThrow(() -> new IllegalArgumentException("Invalid or missing Executor"));
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy