Presentation is loading. Please wait.

Presentation is loading. Please wait.

1. BuilderVisitor 2. XMLMetadataVisitor 3. ProcessMetadataVisitor 4. FolderRenameVisitor 5. ComparerVisitor 6. SyncerVisitor 7. XMLWriterVisitor.

Similar presentations


Presentation on theme: "1. BuilderVisitor 2. XMLMetadataVisitor 3. ProcessMetadataVisitor 4. FolderRenameVisitor 5. ComparerVisitor 6. SyncerVisitor 7. XMLWriterVisitor."— Presentation transcript:

1

2

3 1. BuilderVisitor 2. XMLMetadataVisitor 3. ProcessMetadataVisitor 4. FolderRenameVisitor 5. ComparerVisitor 6. SyncerVisitor 7. XMLWriterVisitor

4 1. BuilderVisitor  Builds the merged tree. 2. ComparerVisitor  Compares and updates the state of each node. 3. SyncerVisitor  Takes the updated state of each node and performs an action to keep them synchronized.

5 BuilderVisitor

6 Traverse and build or populate tree for “C:\Users\Wysie\Desktop\A” RootCompareObject string[] paths paths[0] = “C:\Users\Wysie\Desktop\A” paths[1] = “C:\Users\Wysie\Desktop\B” paths[2] = “C:\Users\Wysie\Desktop\C” FileCompareObject name = “CueSheet.docx” numOfPaths = 3 bool[] exists; bool[0] = true bool[1] = false bool[2] = false string[] hash; hash[0] = “QWERTY”; hash[1] = null; hash[2] = null; long[] lastModified; long[0] = 99999; long[1] = 0; long[2] = 0; FileCompareObject name = “Results.txt” numOfPaths = 3 bool[] exists; bool[0] = true bool[1] = false bool[2] = false string[] hash; hash[0] = “AAAAA”; hash[1] = null; hash[2] = null; long[] lastModified; long[0] = 70000; long[1] = 0; long[2] = 0; FolderCompareObject name = “School Work” numOfPaths = 3 bool[] exists; bool[0] = true bool[1] = false bool[2] = false FileCompareObject name = “Final.pdf” numOfPaths = 3 bool[] exists; bool[0] = true bool[1] = false bool[2] = false string[] hash; hash[0] = “ZXCVB”; hash[1] = null; hash[2] = null; long[] lastModified; long[0] = 30000; long[1] = 0; long[2] = 0; FileCompareObject name = “Proposal.docx” numOfPaths = 3 bool[] exists; bool[0] = true bool[1] = false bool[2] = false string[] hash; hash[0] = “ASDFG”; hash[1] = null; hash[2] = null; long[] lastModified; long[0] = 10000; long[1] = 0; long[2] = 0; Since “A” is the first folder to be build, all the FileCompareObjects or FolderCompareObjects will be created. Index 0: C:\Users\Wysie\Desktop\A Index 1: C:\Users\Wysie\Desktop\B Index 2: C:\Users\Wysie\Desktop\C Build FolderCompareObject with name “School Work”, and populate information at index 0. Now, traverse the contents of “School Work” and build new objects. In this case, build “Final.pdf” and “Proposal.docx” and populate index 0. Nothing else to build, so we return all the way back to RootCompareObject. Now, we build “CueSheet.docx” and populate information at index 0. Finally, we build “Results.txt” and populate the information at index 0.

7 Traverse and build or populate tree for “C:\Users\Wysie\Desktop\B” RootCompareObject string[] paths paths[0] = “C:\Users\Wysie\Desktop\A” paths[1] = “C:\Users\Wysie\Desktop\B” paths[2] = “C:\Users\Wysie\Desktop\C” FileCompareObject name = “CueSheet.docx” numOfPaths = 3 bool[] exists; bool[0] = true bool[1] = false bool[2] = false string[] hash; hash[0] = “QWERTY”; hash[1] = null; hash[2] = null; long[] lastModified; long[0] = 99999; long[1] = 0; long[2] = 0; FileCompareObject name = “Results.txt” numOfPaths = 3 bool[] exists; bool[0] = true bool[1] = false bool[2] = false string[] hash; hash[0] = “AAAAA”; hash[1] = null; hash[2] = null; long[] lastModified; long[0] = 70000; long[1] = 0; long[2] = 0; FolderCompareObject name = “School Work” numOfPaths = 3 bool[] exists; bool[0] = true bool[1] = false bool[2] = false FileCompareObject name = “Final.pdf” numOfPaths = 3 bool[] exists; bool[0] = true bool[1] = false bool[2] = false string[] hash; hash[0] = “ZXCVB”; hash[1] = null; hash[2] = null; long[] lastModified; long[0] = 30000; long[1] = 0; long[2] = 0; FileCompareObject name = “Proposal.docx” numOfPaths = 3 bool[] exists; bool[0] = true bool[1] = false bool[2] = false string[] hash; hash[0] = “ASDFG”; hash[1] = null; hash[2] = null; long[] lastModified; long[0] = 10000; long[1] = 0; long[2] = 0; Index 0: C:\Users\Wysie\Desktop\A Index 1: C:\Users\Wysie\Desktop\B Index 2: C:\Users\Wysie\Desktop\C Since “School Work” does not exist in “B”, the entire portion remains unchanged. “CueSheet.docx” is found in “B”. We now populate index 1 of “CueSheet.docx” with information. FileCompareObject name = “CueSheet.docx” numOfPaths = 3 bool[] exists; bool[0] = true bool[1] = true bool[2] = false string[] hash; hash[0] = “QWERTY”; hash[1] = “MNBVC”; hash[2] = null; long[] lastModified; long[0] = 99999; long[1] = 88888; long[2] = 0; FileCompareObject name = “Results.txt” numOfPaths = 3 bool[] exists; bool[0] = true bool[1] = true bool[2] = false string[] hash; hash[0] = “AAAAA”; hash[1] = “VVBBB”; hash[2] = null; long[] lastModified; long[0] = 70000; long[1] = 90000; long[2] = 0; “Results.txt” is also found in “B”. We now populate index 1 of “Results.txt” with information.

8 FileCompareObject name = “Results.txt” numOfPaths = 3 bool[] exists; bool[0] = true bool[1] = true bool[2] = false string[] hash; hash[0] = “AAAAA”; hash[1] = “VVBBB”; hash[2] = null; long[] lastModified; long[0] = 70000; long[1] = 90000; long[2] = 0; FileCompareObject name = “CueSheet.docx” numOfPaths = 3 bool[] exists; bool[0] = true bool[1] = true bool[2] = false string[] hash; hash[0] = “QWERTY”; hash[1] = “MNBVC”; hash[2] = null; long[] lastModified; long[0] = 99999; long[1] = 88888; long[2] = 0; Traverse and build or populate tree for “C:\Users\Wysie\Desktop\C” RootCompareObject string[] paths paths[0] = “C:\Users\Wysie\Desktop\A” paths[1] = “C:\Users\Wysie\Desktop\B” paths[2] = “C:\Users\Wysie\Desktop\C” FolderCompareObject name = “School Work” numOfPaths = 3 bool[] exists; bool[0] = true bool[1] = false bool[2] = false FileCompareObject name = “Final.pdf” numOfPaths = 3 bool[] exists; bool[0] = true bool[1] = false bool[2] = false string[] hash; hash[0] = “ZXCVB”; hash[1] = null; hash[2] = null; long[] lastModified; long[0] = 30000; long[1] = 0; long[2] = 0; FileCompareObject name = “Proposal.docx” numOfPaths = 3 bool[] exists; bool[0] = true bool[1] = false bool[2] = false string[] hash; hash[0] = “ASDFG”; hash[1] = null; hash[2] = null; long[] lastModified; long[0] = 10000; long[1] = 0; long[2] = 0; Index 0: C:\Users\Wysie\Desktop\A Index 1: C:\Users\Wysie\Desktop\B Index 2: C:\Users\Wysie\Desktop\C “School Work” exists in “C”. Populate index 2 in “C”. FolderCompareObject name = “School Work” numOfPaths = 3 bool[] exists; bool[0] = true bool[1] = false bool[2] = true “Final.pdf” does not exist. However, “Proposal.docx” exists. Populate at index 2. FileCompareObject name = “Proposal.docx” numOfPaths = 3 bool[] exists; bool[0] = true bool[1] = false bool[2] = true string[] hash; hash[0] = “ASDFG”; hash[1] = null; hash[2] = “DFGHJK”; long[] lastModified; long[0] = 10000; long[1] = 0; long[2] = 10000;

9  There are many other attributes that are left out, such as priority, new name, creation time, among many others. For a more detailed explanation, please take a look at the source code comments.

10 ComparerVisitor

11 FileCompareObject name = “Proposal.docx” numOfPaths = 3 bool[] exists; bool[0] = true bool[1] = false bool[2] = true string[] hash; hash[0] = “ASDFG”; hash[1] = null; hash[2] = “DFGHJK”; long[] lastModified; long[0] = 10000; long[1] = 0; long[2] = 10000; FolderCompareObject name = “School Work” numOfPaths = 3 bool[] exists; bool[0] = true bool[1] = false bool[2] = true FileCompareObject name = “Results.txt” numOfPaths = 3 bool[] exists; bool[0] = true bool[1] = true bool[2] = false string[] hash; hash[0] = “AAAAA”; hash[1] = “VVBBB”; hash[2] = null; long[] lastModified; long[0] = 70000; long[1] = 90000; long[2] = 0; FileCompareObject name = “CueSheet.docx” numOfPaths = 3 bool[] exists; bool[0] = true bool[1] = true bool[2] = false string[] hash; hash[0] = “QWERTY”; hash[1] = “MNBVC”; hash[2] = null; long[] lastModified; long[0] = 99999; long[1] = 88888; long[2] = 0; ComparerVisitor will now visit the tree. RootCompareObject string[] paths paths[0] = “C:\Users\Wysie\Desktop\A” paths[1] = “C:\Users\Wysie\Desktop\B” paths[2] = “C:\Users\Wysie\Desktop\C” FileCompareObject name = “Final.pdf” numOfPaths = 3 bool[] exists; bool[0] = true bool[1] = false bool[2] = false string[] hash; hash[0] = “ZXCVB”; hash[1] = null; hash[2] = null; long[] lastModified; long[0] = 30000; long[1] = 0; long[2] = 0; Index 0: C:\Users\Wysie\Desktop\A Index 1: C:\Users\Wysie\Desktop\B Index 2: C:\Users\Wysie\Desktop\C FileCompareObject name = “CueSheet.docx” numOfPaths = 3 bool[] exists; bool[0] = true bool[1] = true bool[2] = false string[] hash; hash[0] = “QWERTY”; hash[1] = “MNBVC”; hash[2] = null; long[] lastModified; long[0] = 99999; long[1] = 88888; long[2] = 0; srcPosition = 0 FileCompareObject name = “Results.txt” numOfPaths = 3 bool[] exists; bool[0] = true bool[1] = true bool[2] = false string[] hash; hash[0] = “AAAAA”; hash[1] = “VVBBB”; hash[2] = null; long[] lastModified; long[0] = 70000; long[1] = 90000; long[2] = 0; srcPosition = 1 FolderCompareObject name = “School Work” numOfPaths = 3 bool[] exists; bool[0] = true bool[1] = false bool[2] = true srcPosition = 0 FileCompareObject name = “Final.pdf” numOfPaths = 3 bool[] exists; bool[0] = true bool[1] = false bool[2] = false string[] hash; hash[0] = “ZXCVB”; hash[1] = null; hash[2] = null; long[] lastModified; long[0] = 30000; long[1] = 0; long[2] = 0; srcPosition = 0 FileCompareObject name = “Proposal.docx” numOfPaths = 3 bool[] exists; bool[0] = true bool[1] = false bool[2] = true string[] hash; hash[0] = “ASDFG”; hash[1] = null; hash[2] = “ASDFG”; long[] lastModified; long[0] = 10000; long[1] = 0; long[2] = 10000; srcPosition = 0 It will first visit “School Work”. Since it exists in index 0 and index 2, but not in index 1, the algorithm will set source position to 0. Now, it will traverse the contents of “School Work”. For “Final.pdf”, since it only exists in index 0, source position will again be set to 0. For “Proposal.docx”, it exists in 0 and 2, but not in 1. Comparing the hash of index 0 and 2 shows that they are identical. Thus, source position will be set to 0. It will now visit “CueSheet.docx”. Since it exists in index 0 and 1 but not in 2, comparison will be done between 0 and 1. Based on the last modified date, the one at index 0 is more updated then the one at index 1. Thus, source position will be set to 0. Finally, “Results.txt” is visited. Again, it exists in index 0 and 1. This time round, the one at index 1 is found to be more updated. Source position is 1.

12  The purpose of source position is for SyncerVisitor to find out which file to propagate.  In actual fact, there is another array called priority. All files which are determined to be equal (same hash if create/update, same new name if rename, or file does not exist if delete) are given equal priority.  During actual synchronization, only lower priority indexes than that of the source position will be affected. This is to prevent redundant file or folder changes.

13 SyncerVisitor

14 FolderCompareObject name = “School Work” numOfPaths = 3 bool[] exists; bool[0] = true bool[1] = false bool[2] = true srcPosition = 0 FileCompareObject name = “Final.pdf” numOfPaths = 3 bool[] exists; bool[0] = true bool[1] = false bool[2] = false string[] hash; hash[0] = “ZXCVB”; hash[1] = null; hash[2] = null; long[] lastModified; long[0] = 30000; long[1] = 0; long[2] = 0; srcPosition = 0 FileCompareObject name = “Proposal.docx” numOfPaths = 3 bool[] exists; bool[0] = true bool[1] = false bool[2] = true string[] hash; hash[0] = “ASDFG”; hash[1] = null; hash[2] = “ASDFG”; long[] lastModified; long[0] = 10000; long[1] = 0; long[2] = 10000; srcPosition = 0 FileCompareObject name = “Results.txt” numOfPaths = 3 bool[] exists; bool[0] = true bool[1] = true bool[2] = false string[] hash; hash[0] = “AAAAA”; hash[1] = “VVBBB”; hash[2] = null; long[] lastModified; long[0] = 70000; long[1] = 90000; long[2] = 0; srcPosition = 1 FileCompareObject name = “CueSheet.docx” numOfPaths = 3 bool[] exists; bool[0] = true bool[1] = true bool[2] = false string[] hash; hash[0] = “QWERTY”; hash[1] = “MNBVC”; hash[2] = null; long[] lastModified; long[0] = 99999; long[1] = 88888; long[2] = 0; srcPosition = 0 SyncerVisitor will now visit the tree. RootCompareObject string[] paths paths[0] = “C:\Users\Wysie\Desktop\A” paths[1] = “C:\Users\Wysie\Desktop\B” paths[2] = “C:\Users\Wysie\Desktop\C” Index 0: C:\Users\Wysie\Desktop\A Index 1: C:\Users\Wysie\Desktop\B Index 2: C:\Users\Wysie\Desktop\C It will first visit “School Work”, determine the source position, and then create a folder when necessary. The state of the node will then be updated. FolderCompareObject name = “School Work” numOfPaths = 3 bool[] exists; bool[0] = true bool[1] = true bool[2] = true srcPosition = 0 FileCompareObject name = “Final.pdf” numOfPaths = 3 bool[] exists; bool[0] = true bool[1] = true bool[2] = true string[] hash; hash[0] = “ZXCVB”; hash[1] = “ZXCVB”;; hash[2] = “ZXCVB”;; long[] lastModified; long[0] = 30000; long[1] = 30000; long[2] = 30000; srcPosition = 0 Next it will visit “Final.pdf”. Since source position is 0, it will be copied over to the other positions, and the state of the node will then be updated. Then, it will visit “Proposal.docx”. Since source position is 0, but index 2 is determined to be equal, only 1 will be updated. FileCompareObject name = “Proposal.docx” numOfPaths = 3 bool[] exists; bool[0] = true bool[1] = true bool[2] = true string[] hash; hash[0] = “ASDFG”; hash[1] = “ASDFG”; hash[2] = “ASDFG”; long[] lastModified; long[0] = 10000; long[1] = 10000; long[2] = 10000; srcPosition = 0 The next node to be visited is “CueSheet.docx”. Since the source position is 0, and it is the most updated, it will propagate to the other 2 locations. FileCompareObject name = “CueSheet.docx” numOfPaths = 3 bool[] exists; bool[0] = true bool[1] = true bool[2] = true string[] hash; hash[0] = “QWERTY”; hash[1] = “QWERTY”; hash[2] = “QWERTY”; long[] lastModified; long[0] = 99999; long[1] = 99999; long[2] = 99999; srcPosition = 0 Finally, “Results.txt” will be visited. Since the source position is 1, and it is more updated then the rest, it will propagate to the other nodes. FileCompareObject name = “Results.txt” numOfPaths = 3 bool[] exists; bool[0] = true bool[1] = true bool[2] = true string[] hash; hash[0] = “VVBBB”; hash[1] = “VVBBB”; hash[2] = “VVBBB”; long[] lastModified; long[0] = 90000; long[1] = 90000; long[2] = 90000; srcPosition = 1 With that, all the files and folders are now synchronized.

15  As stated earlier, a priority array in each node is used to determine if a file is actually copied over.

16  We hope this simple presentation will give you a good overview of how the visitor pattern, and in particular, how our merged tree, works.  Many other functions and visitors were not explained, please look at the detailed comments in the source code, as well as the developer guide, if you are interested.  Traversing the tree can be pre, post, or level- order traversal, depending on what is needed.


Download ppt "1. BuilderVisitor 2. XMLMetadataVisitor 3. ProcessMetadataVisitor 4. FolderRenameVisitor 5. ComparerVisitor 6. SyncerVisitor 7. XMLWriterVisitor."

Similar presentations


Ads by Google