|
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; |
|
6 |
|
7 import java.util.Iterator; |
|
8 |
|
9 /** |
|
10 * Our hacky version of transactional semantics. The goal is to prevent |
|
11 * the following situation: |
|
12 * |
|
13 * * AAA is not modified locally. |
|
14 * * A modified AAA is downloaded during the storing phase. Its local |
|
15 * timestamp is advanced. |
|
16 * * The direction of syncing changes, and AAA is now uploaded to the server. |
|
17 * |
|
18 * The following situation should still be supported: |
|
19 * |
|
20 * * AAA is not modified locally. |
|
21 * * A modified AAA is downloaded and merged with the local AAA. |
|
22 * * The merged AAA is uploaded to the server. |
|
23 * |
|
24 * As should: |
|
25 * |
|
26 * * AAA is modified locally. |
|
27 * * A modified AAA is downloaded, and discarded or merged. |
|
28 * * The current version of AAA is uploaded to the server. |
|
29 * |
|
30 * We achieve this by tracking GUIDs during the storing phase. If we |
|
31 * apply a record such that the local copy is substantially the same |
|
32 * as the record we just downloaded, we add it to a list of records |
|
33 * to avoid uploading. The definition of "substantially the same" |
|
34 * depends on the particular repository. The only consideration is "do we |
|
35 * want to upload this record in this sync?". |
|
36 * |
|
37 * Note that items are removed from this list when a fetch that |
|
38 * considers them for upload completes successfully. The entire list |
|
39 * is discarded when the session is completed. |
|
40 * |
|
41 * This interface exposes methods to: |
|
42 * |
|
43 * * During a store, recording that a record has been stored, and should |
|
44 * thus not be returned in subsequent fetches; |
|
45 * * During a fetch, checking whether a record should be returned. |
|
46 * |
|
47 * In the future this might also grow self-persistence. |
|
48 * |
|
49 * See also RepositorySession.trackRecord. |
|
50 * |
|
51 * @author rnewman |
|
52 * |
|
53 */ |
|
54 public interface StoreTracker { |
|
55 |
|
56 /** |
|
57 * @param guid |
|
58 * The GUID of the item to track. |
|
59 * @return |
|
60 * Whether the GUID was a newly tracked value. |
|
61 */ |
|
62 public boolean trackRecordForExclusion(String guid); |
|
63 |
|
64 /** |
|
65 * @param guid |
|
66 * The GUID of the item to check. |
|
67 * @return |
|
68 * true if the item is already tracked. |
|
69 */ |
|
70 public boolean isTrackedForExclusion(String guid); |
|
71 |
|
72 /** |
|
73 * |
|
74 * @param guid |
|
75 * @return true if the specified GUID was removed from the tracked set. |
|
76 */ |
|
77 public boolean untrackStoredForExclusion(String guid); |
|
78 |
|
79 public RecordFilter getFilter(); |
|
80 |
|
81 public Iterator<String> recordsTrackedForExclusion(); |
|
82 } |