File contents
            
            from BTrees.Length import Length
from threading import RLock
from OFS.SimpleItem import SimpleItem
from Acquisition import Implicit
from AccessControl import ClassSecurityInfo
import Globals
manage_addSuperFooCounterForm = Globals.DTMLFile('dtml/addCounter', globals())
def manage_addSuperFooCounter(self
                              id,
                              title,
                              start=1,
                              callback_url='',
                              REQUEST
                              ):
    id=str(id)
    title=str(title)
    start=int(start) # raises
    
    ob = Counter(id, title, start)
    self._setObject(id, ob)
    if REQUEST is not None:
        if callback_url:
            REQUEST.RESPONSE.redirect(callback_url)
        else:
            REQUEST.RESPONSE.redirect('manage_main')
# conflict resistant counter
class Counter(SimpleItem, Implicit):
    meta_type = "Super Foo Counter"
    security = ClassSecurityInfo()
    def __init__(self, id, title, start=1):
        self.id = id
        self.title = title
        self._counter = Length(start)
    security.declarePublic('next')
    def next(self):
        val = self._counter()
        self._counter.change(1)
        return val
Globals.InitializeClass(Counter)
# the above doesn't do mutual exclusion though...