mobile/android/base/sync/repositories/delegates/DeferredRepositorySessionStoreDelegate.java

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:d05098627917
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4
5 package org.mozilla.gecko.sync.repositories.delegates;
6
7 import java.util.concurrent.ExecutorService;
8
9 public class DeferredRepositorySessionStoreDelegate implements
10 RepositorySessionStoreDelegate {
11 protected final RepositorySessionStoreDelegate inner;
12 protected final ExecutorService executor;
13
14 public DeferredRepositorySessionStoreDelegate(
15 RepositorySessionStoreDelegate inner, ExecutorService executor) {
16 this.inner = inner;
17 this.executor = executor;
18 }
19
20 @Override
21 public void onRecordStoreSucceeded(final String guid) {
22 executor.execute(new Runnable() {
23 @Override
24 public void run() {
25 inner.onRecordStoreSucceeded(guid);
26 }
27 });
28 }
29
30 @Override
31 public void onRecordStoreFailed(final Exception ex, final String guid) {
32 executor.execute(new Runnable() {
33 @Override
34 public void run() {
35 inner.onRecordStoreFailed(ex, guid);
36 }
37 });
38 }
39
40 @Override
41 public RepositorySessionStoreDelegate deferredStoreDelegate(ExecutorService newExecutor) {
42 if (newExecutor == executor) {
43 return this;
44 }
45 throw new IllegalArgumentException("Can't re-defer this delegate.");
46 }
47
48 @Override
49 public void onStoreCompleted(final long storeEnd) {
50 executor.execute(new Runnable() {
51 @Override
52 public void run() {
53 inner.onStoreCompleted(storeEnd);
54 }
55 });
56 }
57 }

mercurial