Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1fd02870 authored by Tomasz Mikolajewski's avatar Tomasz Mikolajewski Committed by Android (Google) Code Review
Browse files

Merge "Move executor details to ReadableArchive."

parents 38f9bd40 3b135ef2
Loading
Loading
Loading
Loading
+0 −20
Original line number Diff line number Diff line
@@ -42,8 +42,6 @@ import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.zip.ZipEntry;

/**
@@ -67,7 +65,6 @@ public abstract class Archive implements Closeable {
    final Uri mArchiveUri;
    final int mArchiveMode;
    final Uri mNotificationUri;
    final ThreadPoolExecutor mExecutor;
    final Map<String, ZipEntry> mEntries;
    final Map<String, List<ZipEntry>> mTree;

@@ -81,12 +78,6 @@ public abstract class Archive implements Closeable {
        mArchiveMode = archiveMode;
        mNotificationUri = notificationUri;

        // At most 8 active threads. All threads idling for more than a minute will
        // be closed.
        mExecutor = new ThreadPoolExecutor(8, 8, 60, TimeUnit.SECONDS,
                new LinkedBlockingQueue<Runnable>());
        mExecutor.allowCoreThreadTimeOut(true);

        mTree = new HashMap<>();
        mEntries = new HashMap<>();
    }
@@ -244,17 +235,6 @@ public abstract class Archive implements Closeable {
        return new ArchiveId(mArchiveUri, mArchiveMode, path);
    }

    /**
     * Closes an archive.
     *
     * <p>This method does not block until shutdown. Once called, other methods should not be
     * called. Any active pipes will be terminated.
     */
    @Override
    public void close() {
        mExecutor.shutdownNow();
    }

    void addCursorRow(MatrixCursor cursor, ZipEntry entry) {
        final MatrixCursor.RowBuilder row = cursor.newRow();
        final ArchiveId parsedId = createArchiveId(getEntryPath(entry));
+4 −1
Original line number Diff line number Diff line
@@ -42,6 +42,7 @@ import com.android.internal.util.Preconditions;
import java.io.Closeable;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.locks.Lock;
@@ -71,6 +72,8 @@ public class ArchivesProvider extends DocumentsProvider implements Closeable {
                    oldValue.getWriteLock().lock();
                    try {
                        oldValue.get().close();
                    } catch (IOException e) {
                        Log.e(TAG, "Closing archive failed.", e);
                    }finally {
                        oldValue.getWriteLock().unlock();
                    }
+17 −1
Original line number Diff line number Diff line
@@ -44,6 +44,9 @@ import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Stack;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.zip.ZipEntry;

/**
@@ -55,6 +58,7 @@ import java.util.zip.ZipEntry;
public class ReadableArchive extends Archive {
    private static final String TAG = "Archive";

    final ThreadPoolExecutor mExecutor;
    private final StrictJarFile mZipFile;

    private ReadableArchive(
@@ -70,6 +74,12 @@ public class ReadableArchive extends Archive {
            throw new IllegalStateException("Unsupported access mode.");
        }

        // At most 8 active threads. All threads idling for more than a minute will
        // be closed.
        mExecutor = new ThreadPoolExecutor(8, 8, 60, TimeUnit.SECONDS,
                new LinkedBlockingQueue<Runnable>());
        mExecutor.allowCoreThreadTimeOut(true);

        mZipFile = file != null ?
                new StrictJarFile(file.getPath(), false /* verify */,
                        false /* signatures */) :
@@ -335,9 +345,15 @@ public class ReadableArchive extends Archive {
                openDocument(documentId, "r", signal), 0, entry.getSize(), null);
    }

    /**
     * Closes an archive.
     *
     * <p>This method does not block until shutdown. Once called, other methods should not be
     * called. Any active pipes will be terminated.
     */
    @Override
    public void close() {
        super.close();
        mExecutor.shutdownNow();
        try {
            mZipFile.close();
        } catch (IOException e) {