Left: | ||
Right: |
LEFT | RIGHT |
---|---|
1 // gozk - ZooKeeper support for the Go language | 1 // gozk - ZooKeeper support for the Go language |
2 // | 2 // |
3 // https://wiki.ubuntu.com/gozk | 3 // https://wiki.ubuntu.com/gozk |
4 // | 4 // |
5 // Copyright (c) 2010-2011 Canonical Ltd. | 5 // Copyright (c) 2010-2011 Canonical Ltd. |
6 // | 6 // |
7 // Written by Gustavo Niemeyer <gustavo.niemeyer@canonical.com> | 7 // Written by Gustavo Niemeyer <gustavo.niemeyer@canonical.com> |
8 // | 8 // |
9 package zookeeper | 9 package zookeeper |
10 | 10 |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
85 // event := <-watch | 85 // event := <-watch |
86 // if !event.Ok() { | 86 // if !event.Ok() { |
87 // err = event | 87 // err = event |
88 // return | 88 // return |
89 // } | 89 // } |
90 // | 90 // |
91 // Note that closed channels will deliver zeroed Event, which means | 91 // Note that closed channels will deliver zeroed Event, which means |
92 // event.Type is set to EVENT_CLOSED and event.State is set to STATE_CLOSED, | 92 // event.Type is set to EVENT_CLOSED and event.State is set to STATE_CLOSED, |
93 // to facilitate handling. | 93 // to facilitate handling. |
94 type Event struct { | 94 type Event struct { |
95 » // Type gives the type of event (one of the EVENT_* constants). | 95 » Type int // One of the EVENT_* constants. |
96 » // If Type is EVENT_SESSION, then the event is a session | 96 » Path string // For non-session events, the path of the watched node. |
97 » // event. | 97 » State int // One of the STATE_* constants. |
niemeyer
2012/02/13 13:53:57
This is extremely redundant. Please use something
rog
2012/02/13 14:48:27
Done.
| |
98 » Type int | |
99 | |
100 » // For non-session events, Path gives the path of the node | |
101 » // that was being watched. | |
102 » Path string | |
103 | |
104 » // For session events, State (one of the STATE* constants) gives the ses sion | |
105 » // status. | |
106 » State int | |
107 } | 98 } |
108 | 99 |
109 // Error represents a ZooKeeper error. | 100 // Error represents a ZooKeeper error. |
110 type Error int | 101 type Error int |
111 | 102 |
112 const ( | 103 const ( |
113 ZOK Error = C.ZOK | 104 ZOK Error = C.ZOK |
114 ZSYSTEMERROR Error = C.ZSYSTEMERROR | 105 ZSYSTEMERROR Error = C.ZSYSTEMERROR |
115 ZRUNTIMEINCONSISTENCY Error = C.ZRUNTIMEINCONSISTENCY | 106 ZRUNTIMEINCONSISTENCY Error = C.ZRUNTIMEINCONSISTENCY |
116 ZDATAINCONSISTENCY Error = C.ZDATAINCONSISTENCY | 107 ZDATAINCONSISTENCY Error = C.ZDATAINCONSISTENCY |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
337 // last modified. | 328 // last modified. |
338 func (stat *Stat) MTime() time.Time { | 329 func (stat *Stat) MTime() time.Time { |
339 return millisec2time(int64(stat.c.mtime)) | 330 return millisec2time(int64(stat.c.mtime)) |
340 } | 331 } |
341 | 332 |
342 // Version returns the number of changes to the data of the node. | 333 // Version returns the number of changes to the data of the node. |
343 func (stat *Stat) Version() int32 { | 334 func (stat *Stat) Version() int32 { |
344 return int32(stat.c.version) | 335 return int32(stat.c.version) |
345 } | 336 } |
346 | 337 |
347 // CVersion returns the number of changes to the children of the node. | 338 // CVersion returns the number of changes to the children of the node. |
niemeyer
2012/02/13 13:53:57
This needs clarification. Will a change in a child
rog
2012/02/13 14:48:27
Done.
| |
339 // This only changes when children are created or removed. | |
348 func (stat *Stat) CVersion() int32 { | 340 func (stat *Stat) CVersion() int32 { |
349 return int32(stat.c.cversion) | 341 return int32(stat.c.cversion) |
350 } | 342 } |
351 | 343 |
352 // AVersion returns the number of changes to the ACL of the node. | 344 // AVersion returns the number of changes to the ACL of the node. |
353 func (stat *Stat) AVersion() int32 { | 345 func (stat *Stat) AVersion() int32 { |
354 return int32(stat.c.aversion) | 346 return int32(stat.c.aversion) |
355 } | 347 } |
356 | 348 |
357 // If the node is an ephemeral node, EphemeralOwner returns the session id | 349 // If the node is an ephemeral node, EphemeralOwner returns the session id |
358 // of the owner of the node; otherwise it will return zero. | 350 // of the owner of the node; otherwise it will return zero. |
359 func (stat *Stat) EphemeralOwner() int64 { | 351 func (stat *Stat) EphemeralOwner() int64 { |
360 return int64(stat.c.ephemeralOwner) | 352 return int64(stat.c.ephemeralOwner) |
361 } | 353 } |
362 | 354 |
363 // DataLength returns the length of the data in the node in bytes. | 355 // DataLength returns the length of the data in the node in bytes. |
364 func (stat *Stat) DataLength() int32 { | 356 func (stat *Stat) DataLength() int32 { |
365 return int32(stat.c.dataLength) | 357 return int32(stat.c.dataLength) |
366 } | 358 } |
367 | 359 |
368 // NumChildren returns the number of children of the znode. | 360 // NumChildren returns the number of children of the node. |
niemeyer
2012/02/13 13:53:57
s/znode/node/, as everywhere else.
rog
2012/02/13 14:48:27
Done.
| |
369 func (stat *Stat) NumChildren() int32 { | 361 func (stat *Stat) NumChildren() int32 { |
370 return int32(stat.c.numChildren) | 362 return int32(stat.c.numChildren) |
371 } | 363 } |
372 | 364 |
373 // Pzxid returns the Pzxid of the node, whatever that is. | 365 // Pzxid returns the Pzxid of the node, whatever that is. |
niemeyer
2012/02/13 13:53:57
:-)
| |
374 func (stat *Stat) Pzxid() int64 { | 366 func (stat *Stat) Pzxid() int64 { |
375 return int64(stat.c.pzxid) | 367 return int64(stat.c.pzxid) |
376 } | 368 } |
377 | 369 |
378 // ----------------------------------------------------------------------- | 370 // ----------------------------------------------------------------------- |
379 // Functions and methods related to ZooKeeper itself. | 371 // Functions and methods related to ZooKeeper itself. |
380 | 372 |
381 const bufferSize = 1024 * 1024 | 373 const bufferSize = 1024 * 1024 |
382 | 374 |
383 // SetLogLevel changes the minimum level of logging output generated | 375 // SetLogLevel changes the minimum level of logging output generated |
(...skipping 637 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1021 event := Event{ | 1013 event := Event{ |
1022 Type: int(data.event_type), | 1014 Type: int(data.event_type), |
1023 Path: C.GoString(data.event_path), | 1015 Path: C.GoString(data.event_path), |
1024 State: int(data.connection_state), | 1016 State: int(data.connection_state), |
1025 } | 1017 } |
1026 watchId := uintptr(data.watch_context) | 1018 watchId := uintptr(data.watch_context) |
1027 C.destroy_watch_data(data) | 1019 C.destroy_watch_data(data) |
1028 sendEvent(watchId, event) | 1020 sendEvent(watchId, event) |
1029 } | 1021 } |
1030 } | 1022 } |
LEFT | RIGHT |