Package commons :: Module seqs :: Class PersistentConsumedSeq
[hide private]
[frames] | no frames]

Class PersistentConsumedSeq

source code

object --+
         |
        PersistentConsumedSeq
Known Subclasses:

I generate [0, 1, ...], like count, but I can also save my state to disk. Similar to PersistentSeq, but instead of committing on each call to next, require manual explicit calls to commit. I'm useful for generating unique IDs.

Why not simply use PersistentSeq instead of me? You usually can. However, some applications use me for efficiency. For instance, consider an application that generates a lot of network packets (with sequence numbers), but only sends a small fraction of them out onto the network. If we only want to guarantee the uniqueness of sequence numbers that are exposed to the world, we need only commit when upon sending a packet, and not on generating a packet (next). This could avoid excessive writes.

Instance Methods [hide private]
 
__init__(self, path)
x.__init__(...) initializes x; see x.__class__.__doc__ for signature
source code
int
next(self)
Returns: The next number in the sequence.
source code
int
commit(self, seqno)
Returns: The maximum sequence number ever committed (possibly seqno).
source code
 
close(self)
Closes the log file.
source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Instance Variables [hide private]
int seqno
The next sequence number to be generated.
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, path)
(Constructor)

source code 

x.__init__(...) initializes x; see x.__class__.__doc__ for signature

Parameters:
  • path (str) - File to save my state in. I keep this file open.
Overrides: object.__init__

next(self)

source code 
Returns: int
The next number in the sequence.
Raises:

commit(self, seqno)

source code 
Parameters:
  • seqno (int) - If this is the maximum committed sequence number, then commit this sequence number (to disk). The semantics will get weird if you pass in sequence numbers that haven't been generated yet.
Returns: int
The maximum sequence number ever committed (possibly seqno).
Raises:

close(self)

source code 

Closes the log file. No more operations can be performed.