Merge "Simplify asyncFlushBinaryDictionary."

This commit is contained in:
Keisuke Kuroyanagi 2014-04-28 08:44:51 +00:00 committed by Android (Google) Code Review
commit 2367f8f602
2 changed files with 2 additions and 41 deletions

View file

@ -40,7 +40,6 @@ import java.util.Map;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
/**
* Abstract base class for an expandable dictionary that can be created and updated dynamically
@ -101,9 +100,6 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
/* A extension for a binary dictionary file. */
protected static final String DICT_FILE_EXTENSION = ".dict";
private final AtomicReference<Runnable> mUnfinishedFlushingTask =
new AtomicReference<Runnable>();
/**
* Abstract method for loading initial contents of a given dictionary.
*/
@ -561,14 +557,12 @@ abstract public class ExpandableBinaryDictionary extends Dictionary {
* Flush binary dictionary to dictionary file.
*/
public void asyncFlushBinaryDictionary() {
final Runnable newTask = new Runnable() {
ExecutorUtils.getExecutor(mDictName).execute(new Runnable() {
@Override
public void run() {
flushDictionaryLocked();
}
};
final Runnable oldTask = mUnfinishedFlushingTask.getAndSet(newTask);
ExecutorUtils.getExecutor(mDictName).replaceAndExecute(oldTask, newTask);
});
}
// TODO: Implement BinaryDictionary.isInDictionary().

View file

@ -46,16 +46,6 @@ public class PrioritizedSerialExecutor {
0 /* keepAliveTime */, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(1));
}
/**
* Clears all queued tasks.
*/
public void clearAllTasks() {
synchronized(mLock) {
mTasks.clear();
mPrioritizedTasks.clear();
}
}
/**
* Enqueues the given task into the task queue.
* @param r the enqueued task
@ -120,33 +110,10 @@ public class PrioritizedSerialExecutor {
}
}
public void remove(final Runnable r) {
synchronized(mLock) {
mTasks.remove(r);
mPrioritizedTasks.remove(r);
}
}
public void replaceAndExecute(final Runnable oldTask, final Runnable newTask) {
synchronized(mLock) {
if (oldTask != null) remove(oldTask);
execute(newTask);
}
}
public void shutdown() {
synchronized(mLock) {
mIsShutdown = true;
mThreadPoolExecutor.shutdown();
}
}
public boolean isTerminated() {
synchronized(mLock) {
if (!mIsShutdown) {
return false;
}
return mPrioritizedTasks.isEmpty() && mTasks.isEmpty() && mActive == null;
}
}
}