am 64b95965: Merge "[Lazy2] Pass a runnable to abort"

* commit '64b9596544acbeec1a416185e9472cfbd49cde60':
  [Lazy2] Pass a runnable to abort
main
Kurt Partridge 2013-03-13 06:22:31 -07:00 committed by Android Git Automerger
commit f6d68ee385
1 changed files with 11 additions and 4 deletions

View File

@ -98,6 +98,8 @@ public class ResearchLog {
* output. * output.
* *
* See class comment for details about {@code JsonWriter} construction. * See class comment for details about {@code JsonWriter} construction.
*
* @param onClosed run after the close() operation has completed asynchronously
*/ */
private synchronized void close(final Runnable onClosed) { private synchronized void close(final Runnable onClosed) {
mExecutor.submit(new Callable<Object>() { mExecutor.submit(new Callable<Object>() {
@ -144,8 +146,10 @@ public class ResearchLog {
/** /**
* Waits for publication requests to finish, closes the JsonWriter, but then deletes the backing * Waits for publication requests to finish, closes the JsonWriter, but then deletes the backing
* output file. * output file.
*
* @param onAbort run after the abort() operation has completed asynchronously
*/ */
private synchronized void abort() { private synchronized void abort(final Runnable onAbort) {
mExecutor.submit(new Callable<Object>() { mExecutor.submit(new Callable<Object>() {
@Override @Override
public Object call() throws Exception { public Object call() throws Exception {
@ -159,6 +163,9 @@ public class ResearchLog {
if (mFile != null) { if (mFile != null) {
mFile.delete(); mFile.delete();
} }
if (onAbort != null) {
onAbort.run();
}
} }
return null; return null;
} }
@ -173,7 +180,7 @@ public class ResearchLog {
* @param timeout time to wait for close in milliseconds * @param timeout time to wait for close in milliseconds
*/ */
public void blockingAbort(final long timeout) { public void blockingAbort(final long timeout) {
abort(); abort(null);
awaitTermination(timeout, TimeUnit.MILLISECONDS); awaitTermination(timeout, TimeUnit.MILLISECONDS);
} }
@ -231,10 +238,10 @@ public class ResearchLog {
return null; return null;
} }
}); });
} catch (RejectedExecutionException e) { } catch (final RejectedExecutionException e) {
// TODO: Add code to record loss of data, and report. // TODO: Add code to record loss of data, and report.
if (DEBUG) { if (DEBUG) {
Log.d(TAG, "ResearchLog.publish() rejecting scheduled execution"); Log.d(TAG, "ResearchLog.publish() rejecting scheduled execution", e);
} }
} }
} }