Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(194)

Delta Between Two Patch Sets: state/megawatcher.go

Issue 7727044: state: add allWatcher
Left Patch Set: Created 12 years ago
Right Patch Set: state: add allWatcher Created 12 years ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « [revision details] ('k') | state/megawatcher_internal_test.go » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 package state 1 package state
2 2
3 import ( 3 import (
4 "container/list" 4 "container/list"
5 "labix.org/v2/mgo" 5 "labix.org/v2/mgo"
6 "launchpad.net/juju-core/state/api/params" 6 "launchpad.net/juju-core/state/api/params"
7 "launchpad.net/tomb" 7 "launchpad.net/tomb"
8 "reflect" 8 "reflect"
9 ) 9 )
10 10
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 if reflect.DeepEqual(info, entry.info) { 196 if reflect.DeepEqual(info, entry.info) {
197 return 197 return
198 } 198 }
199 // We already know about the entity; update its doc. 199 // We already know about the entity; update its doc.
200 a.latestRevno++ 200 a.latestRevno++
201 entry.revno = a.latestRevno 201 entry.revno = a.latestRevno
202 entry.info = info 202 entry.info = info
203 a.list.MoveToFront(elem) 203 a.list.MoveToFront(elem)
204 } 204 }
205 205
206 // Delta holds details of a change to the environment.
207 type Delta struct {
208 // If Remove is true, the entity has been removed;
209 // otherwise it has been created or changed.
210 Remove bool
211 // Entity holds data about the entity that has changed.
212 Entity params.EntityInfo
213 }
214
215 // changesSince returns any changes that have occurred since 206 // changesSince returns any changes that have occurred since
216 // the given revno, oldest first. 207 // the given revno, oldest first.
217 func (a *allInfo) changesSince(revno int64) []Delta { 208 func (a *allInfo) changesSince(revno int64) []params.Delta {
218 e := a.list.Front() 209 e := a.list.Front()
219 n := 0 210 n := 0
220 for ; e != nil; e = e.Next() { 211 for ; e != nil; e = e.Next() {
221 entry := e.Value.(*entityEntry) 212 entry := e.Value.(*entityEntry)
222 if entry.revno <= revno { 213 if entry.revno <= revno {
223 break 214 break
224 } 215 }
225 n++ 216 n++
226 } 217 }
227 if e != nil { 218 if e != nil {
228 // We've found an element that we've already seen. 219 // We've found an element that we've already seen.
229 e = e.Prev() 220 e = e.Prev()
230 } else { 221 } else {
231 // We haven't seen any elements, so we want all of them. 222 // We haven't seen any elements, so we want all of them.
232 e = a.list.Back() 223 e = a.list.Back()
233 n++ 224 n++
234 } 225 }
235 » changes := make([]Delta, 0, n) 226 » changes := make([]params.Delta, 0, n)
236 for ; e != nil; e = e.Prev() { 227 for ; e != nil; e = e.Prev() {
237 entry := e.Value.(*entityEntry) 228 entry := e.Value.(*entityEntry)
238 » » changes = append(changes, Delta{ 229 » » changes = append(changes, params.Delta{
239 » » » Remove: entry.removed, 230 » » » Removed: entry.removed,
240 » » » Entity: entry.info, 231 » » » Entity: entry.info,
241 }) 232 })
242 } 233 }
243 return changes 234 return changes
244 } 235 }
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b