@Override public void end() throws InterruptedException { if (mCruncher != null && key != -1) { mCruncher.end(key); } }
@Override public void start() { if (mCruncher != null) { key = mCruncher.start(); } }
@Override public synchronized void end(int key) throws InterruptedException { long startTime = System.currentTimeMillis(); try { waitForAll(key); mOutstandingJobs.get(key).clear(); mLogger.verbose("Job finished in %1$d", System.currentTimeMillis() - startTime); } finally { // even if we have failures, we need to shutdown property the sub processes. if (refCount.decrementAndGet() == 0) { mCrunchingRequests.shutdown(); mLogger.verbose("Shutdown finished in %1$d", System.currentTimeMillis() - startTime); } } } }
/** * Creates a new {@link com.android.builder.png.QueuedCruncher} or return an existing one * based on the underlying AAPT executable location. * @param aaptLocation the APPT executable location. * @param logger the logger to use * @return a new of existing instance of the {@link com.android.builder.png.QueuedCruncher} */ public QueuedCruncher newCruncher( @NonNull String aaptLocation, @NonNull ILogger logger) { synchronized (sLock) { logger.info("QueuedCruncher is using %1$s", aaptLocation); if (!sInstances.containsKey(aaptLocation)) { QueuedCruncher queuedCruncher = new QueuedCruncher(aaptLocation, logger); sInstances.put(aaptLocation, queuedCruncher); } return sInstances.get(aaptLocation); } } }
futureResult = mCruncher.crunchPng(key, file, outputFile); } catch (PngException e) { throw new AaptException(e, String.format(
@Override public synchronized void end(int key) throws InterruptedException { long startTime = System.currentTimeMillis(); try { waitForAll(key); mOutstandingJobs.get(key).clear(); mLogger.verbose("Job finished in %1$d", System.currentTimeMillis() - startTime); } finally { // even if we have failures, we need to shutdown property the sub processes. if (refCount.decrementAndGet() == 0) { try { mCrunchingRequests.shutdown(); } catch(InterruptedException e) { Thread.interrupted(); mLogger.warning("Error while shutting down crunching queue : %s", e.getMessage()); } mLogger.verbose("Shutdown finished in %1$d", System.currentTimeMillis() - startTime); } } } }
/** * Creates a new {@link com.android.builder.png.QueuedCruncher} or return an existing one * based on the underlying AAPT executable location. * * @param aaptLocation the AAPT executable location. * @param logger the logger to use * @param cruncherProcesses number of cruncher processes to use; {@code 0} to use the * default number * @return a new of existing instance of the {@link com.android.builder.png.QueuedCruncher} */ public QueuedCruncher newCruncher( @NonNull String aaptLocation, @NonNull ILogger logger, int cruncherProcesses) { synchronized (sLock) { logger.verbose("QueuedCruncher is using %1$s", aaptLocation); if (!sInstances.containsKey(aaptLocation)) { QueuedCruncher queuedCruncher = new QueuedCruncher(aaptLocation, logger, cruncherProcesses); sInstances.put(aaptLocation, queuedCruncher); } return sInstances.get(aaptLocation); } } }