|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 package org.mozilla.gecko.background.sync.helpers; |
|
5 |
|
6 import java.util.concurrent.ExecutorService; |
|
7 |
|
8 import org.mozilla.gecko.sync.repositories.delegates.RepositorySessionStoreDelegate; |
|
9 |
|
10 public class DefaultStoreDelegate extends DefaultDelegate implements RepositorySessionStoreDelegate { |
|
11 |
|
12 @Override |
|
13 public void onRecordStoreFailed(Exception ex, String guid) { |
|
14 performNotify("Store failed", ex); |
|
15 } |
|
16 |
|
17 @Override |
|
18 public void onRecordStoreSucceeded(String guid) { |
|
19 performNotify("DefaultStoreDelegate used", null); |
|
20 } |
|
21 |
|
22 @Override |
|
23 public void onStoreCompleted(long storeEnd) { |
|
24 performNotify("DefaultStoreDelegate used", null); |
|
25 } |
|
26 |
|
27 @Override |
|
28 public RepositorySessionStoreDelegate deferredStoreDelegate(final ExecutorService executor) { |
|
29 final RepositorySessionStoreDelegate self = this; |
|
30 return new RepositorySessionStoreDelegate() { |
|
31 |
|
32 @Override |
|
33 public void onRecordStoreSucceeded(final String guid) { |
|
34 executor.execute(new Runnable() { |
|
35 @Override |
|
36 public void run() { |
|
37 self.onRecordStoreSucceeded(guid); |
|
38 } |
|
39 }); |
|
40 } |
|
41 |
|
42 @Override |
|
43 public void onRecordStoreFailed(final Exception ex, final String guid) { |
|
44 executor.execute(new Runnable() { |
|
45 @Override |
|
46 public void run() { |
|
47 self.onRecordStoreFailed(ex, guid); |
|
48 } |
|
49 }); |
|
50 } |
|
51 |
|
52 @Override |
|
53 public void onStoreCompleted(final long storeEnd) { |
|
54 executor.execute(new Runnable() { |
|
55 @Override |
|
56 public void run() { |
|
57 self.onStoreCompleted(storeEnd); |
|
58 } |
|
59 }); |
|
60 } |
|
61 |
|
62 @Override |
|
63 public RepositorySessionStoreDelegate deferredStoreDelegate(ExecutorService newExecutor) { |
|
64 if (newExecutor == executor) { |
|
65 return this; |
|
66 } |
|
67 throw new IllegalArgumentException("Can't re-defer this delegate."); |
|
68 } |
|
69 }; |
|
70 } |
|
71 } |