private final void writeValues(final ValueCallback<Success> callback) { assert valuesWriting.size() == 0; synchronized (valuesWriting) { synchronized (pendingValues) { valuesWriting.putAll(pendingValues); pendingValues.clear(); } } // final List<Operation<Success>> ops = new // ArrayList<Operation<Success>>(valuesWriting.size()); // System.out.println("wirting values " + valuesWriting.size()); // for (final Entry<K, Object> e : valuesWriting.entrySet()) { // ops.add(new Operation<Success>() { // // @SuppressWarnings("unchecked") // @Override // public void apply(final ValueCallback<Success> callback) { // // } // // }); // } AsyncCommon.map( new ArrayList<Entry<K, Object>>(valuesWriting.entrySet()), new AsyncFunction<Entry<K, Object>, Success>() { @Override public void apply(final Entry<K, Object> e, final ValueCallback<Success> callback) { if (e.getValue() == REMOVE) { decorated.remove(e.getKey(), AsyncCommon.asSimpleCallback(callback)); } else { decorated.put(e.getKey(), (V) e.getValue(), AsyncCommon.asSimpleCallback(callback)); } } }, new ListCallback<Success>() { @Override public void onSuccess(final List<Success> value) { valuesWriting.clear(); callback.onSuccess(Success.INSTANCE); } @Override public void onFailure(final Throwable t) { valuesWriting.clear(); callback.onFailure(t); } }); }
@Override public void stop(final SimpleCallback callback) { waitTillEmpty(); executor.shutdown( AsyncCommon.embed( callback, new Runnable() { @Override public void run() { cbExecutor.shutdown( AsyncCommon.embed( callback, new Runnable() { @Override public void run() { decorated.stop(callback); } })); } })); }