public final class

CameraXExecutors

extends java.lang.Object

 java.lang.Object

↳androidx.camera.core.impl.utils.executor.CameraXExecutors

Gradle dependencies

compile group: 'androidx.camera', name: 'camera-core', version: '1.5.0-alpha01'

  • groupId: androidx.camera
  • artifactId: camera-core
  • version: 1.5.0-alpha01

Artifact androidx.camera:camera-core:1.5.0-alpha01 it located at Google repository (https://maven.google.com/)

Overview

Utility class for generating specific implementations of java.util.concurrent.Executor.

Summary

Methods
public static java.util.concurrent.ExecutoraudioExecutor()

Returns a cached java.util.concurrent.Executor suitable for audio I/O.

public static java.util.concurrent.ExecutordirectExecutor()

Returns a cached executor that runs tasks directly from the calling thread.

public static java.util.concurrent.ExecutorhighPriorityExecutor()

public static java.util.concurrent.ExecutorioExecutor()

Returns a cached java.util.concurrent.Executor suitable for disk I/O.

public static booleanisSequentialExecutor(java.util.concurrent.Executor executor)

Returns whether the executor is a sequential executor as returned by CameraXExecutors.newSequentialExecutor(Executor).

public static java.util.concurrent.ScheduledExecutorServicemainThreadExecutor()

Returns a cached java.util.concurrent.ScheduledExecutorService which posts to the main thread.

public static java.util.concurrent.ScheduledExecutorServicemyLooperExecutor()

Returns an executor which posts to the thread's current .

public static java.util.concurrent.ScheduledExecutorServicenewHandlerExecutor(Handler handler)

Returns an executor which posts to the given Handler.

public static java.util.concurrent.ExecutornewSequentialExecutor(java.util.concurrent.Executor delegate)

Returns a new executor which will perform all tasks sequentially.

from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Methods

public static java.util.concurrent.ScheduledExecutorService mainThreadExecutor()

Returns a cached java.util.concurrent.ScheduledExecutorService which posts to the main thread.

public static java.util.concurrent.Executor ioExecutor()

Returns a cached java.util.concurrent.Executor suitable for disk I/O.

public static java.util.concurrent.Executor audioExecutor()

Returns a cached java.util.concurrent.Executor suitable for audio I/O.

public static java.util.concurrent.Executor directExecutor()

Returns a cached executor that runs tasks directly from the calling thread.

public static java.util.concurrent.Executor newSequentialExecutor(java.util.concurrent.Executor delegate)

Returns a new executor which will perform all tasks sequentially.

The returned executor delegates all tasks to the provided delegate Executor, but will ensure all tasks are run in order and without overlapping. Note this can only be guaranteed for tasks that are submitted via the same sequential executor. Tasks submitted directly to the delegate or to different instances of the sequential executor do not have any ordering guarantees.

public static boolean isSequentialExecutor(java.util.concurrent.Executor executor)

Returns whether the executor is a sequential executor as returned by CameraXExecutors.newSequentialExecutor(Executor).

public static java.util.concurrent.ScheduledExecutorService myLooperExecutor()

Returns an executor which posts to the thread's current .

Returns:

An executor which posts to the thread's current looper.

public static java.util.concurrent.ScheduledExecutorService newHandlerExecutor(Handler handler)

Returns an executor which posts to the given Handler.

Returns:

An executor which posts to the given handler.

public static java.util.concurrent.Executor highPriorityExecutor()

Returns:

a cached high priority java.util.concurrent.Executor suitable for lightweight tasks.

Source

/*
 * Copyright 2019 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package androidx.camera.core.impl.utils.executor;

import android.os.Handler;
import android.os.Looper;

import androidx.annotation.NonNull;

import java.util.concurrent.Executor;
import java.util.concurrent.ScheduledExecutorService;

/**
 * Utility class for generating specific implementations of {@link Executor}.
 */
public final class CameraXExecutors {

    // Should not be instantiated
    private CameraXExecutors() {
    }

    /** Returns a cached {@link ScheduledExecutorService} which posts to the main thread. */
    @NonNull
    public static ScheduledExecutorService mainThreadExecutor() {
        return MainThreadExecutor.getInstance();
    }

    /** Returns a cached {@link Executor} suitable for disk I/O. */
    @NonNull
    public static Executor ioExecutor() {
        return IoExecutor.getInstance();
    }

    /** Returns a cached {@link Executor} suitable for audio I/O. */
    @NonNull
    public static Executor audioExecutor() {
        return AudioExecutor.getInstance();
    }

    /** Returns a cached executor that runs tasks directly from the calling thread. */
    @NonNull
    public static Executor directExecutor() {
        return DirectExecutor.getInstance();
    }

    /**
     * Returns a new executor which will perform all tasks sequentially.
     *
     * <p>The returned executor delegates all tasks to the provided delegate Executor, but will
     * ensure all tasks are run in order and without overlapping. Note this can only be
     * guaranteed for tasks that are submitted via the same sequential executor. Tasks submitted
     * directly to the delegate or to different instances of the sequential executor do not have
     * any ordering guarantees.
     */
    @NonNull
    public static Executor newSequentialExecutor(@NonNull Executor delegate) {
        return new SequentialExecutor(delegate);
    }

    /**
     * Returns whether the executor is a sequential executor as returned by
     * {@link #newSequentialExecutor(Executor)}.
     */
    public static boolean isSequentialExecutor(@NonNull Executor executor) {
        return executor instanceof SequentialExecutor;
    }

    /**
     * Returns an executor which posts to the thread's current {@link Looper}.
     *
     * @return An executor which posts to the thread's current looper.
     * @throws IllegalStateException if the current thread does not have a looper.
     */
    @NonNull
    public static ScheduledExecutorService myLooperExecutor() {
        return HandlerScheduledExecutorService.currentThreadExecutor();
    }

    /**
     * Returns an executor which posts to the given {@link Handler}.
     *
     * @return An executor which posts to the given handler.
     */
    @NonNull
    public static ScheduledExecutorService newHandlerExecutor(@NonNull Handler handler) {
        return new HandlerScheduledExecutorService(handler);
    }

    /**
     * @return a cached high priority {@link Executor} suitable for lightweight tasks.
     */
    @NonNull
    public static Executor highPriorityExecutor() {
        return HighPriorityExecutor.getInstance();
    }
}