HappyDoc Generated Documentation unidist/sharedcounter.py

unidist / sharedcounter.py 

sharedcounter

Shared Counter module. Get access to shared counters. Numeric values, which can be atomically get/set, or atomically incremented.

TODO(g): Implement serialization, archiving, snapshotting, and replication to sharestate. This will allow us flexibility in many things. This is not necessarily going to be the best scaling solution, but it will work and provide a way to keep state and distribute. Name spaces should have this specified individually. If not specified, state will not be archived, serialized, snapshotted or replicated.

  • Use the "archive" and "snapshot" modules for this, so archival and snapshotting is universal. Ensure a process restart will do the right thing in attempting to restore from snapshot, then archive, if present.

    TODO(g): Merge achive and snapshot. They are the same technology. If we really want to keep state, then we must archive each transactions and snapshot to avoid having to replay too many archives.

Functions   
  Set 
Set ( name,  value )

Sets the named counter to this value. Should be numeric, but is not tested.

Args: name: string, name of the counter value: int, value to set this counter. This is using the counter as a numeric state, not a real counter, but it's here for functionality not being strictly semantic about what a counter is.

Returns: int, value after setting (for consistency between other functions).

  GetAllCounters 
GetAllCounters ()

Returns a dict (copy) of all the counters we have.

  Get 
Get ( name )

Returns the value of this counter, or CounterDoesntExist class.

If named counter does not exist, starts counter value at zero.

Args: name: string, name of the counter

  _UnlockCounter 
_UnlockCounter ( name )

Unlock a counter after operations.

Args: name: string, name of the counter

Exceptions   

CounterDoesntExist( 'Not found: %s' % name )

  _LockCounter 
_LockCounter ( name )

Lock a counter for operations.

Args: name: string, name of the counter

  Increment 
Increment ( name,  value=1 )

Increments the named counter by value (default is 1). Returns the new value.

If named counter does not exist, starts counter value at zero.

Args: name: string, name of the counter value: int (optional), value to increment this counter by. Default is 1.

Returns: int, value of the counter after it has been incremented

  GetIncrement 
GetIncrement ( name,  value=1 )

Increments the named counter to this value. Returns the previous value.

If named counter does not exist, starts counter value at zero.

Args: name: string, name of the counter value: int (optional), value to increment this counter by. Default is 1.

Returns: int, value of counter before it was incremented.

  GetSet 
GetSet ( name,  value )

Sets the named counter to this value. Returns the previous value.

Args: name: string, name of the counter value: int, value to set this counter. This is using the counter as a numeric state, not a real counter, but it's here for functionality not being strictly semantic about what a counter is.

Returns: int, value of the counter, before the new value was set

Classes   

CounterDoesntExist

This counter does not exist, so it cannot by returned.


This document was automatically generated Tue Aug 17 15:20:25 2010 by HappyDoc version 3.1