how to create a system-wide independent universal counter object primarily for Database keys?

Posted by andora on Stack Overflow See other posts from Stack Overflow or by andora
Published on 2010-04-05T14:32:00Z Indexed on 2010/04/05 15:13 UTC
Read the original article Hit count: 253

Filed under:
|
|
|
|

I would like to create/use a system-wide independent universal 'counter object' that can be called via COM in a thread-safe manner.

The counter object will be passed an ID to identify which counter to return, handle the counting, 'persist' the count (occasionally), have reasonable performance (as fast as possible) perhaps capable of 1000 counts per second or better (1mS) and be accessible cross-process/out-of-process. The current count status must be persisted between object restarts/shutdowns.

The counter object is liklely to be a 'singleton' type object implemented in some form of free-threaded dictionary, containing maybe 10 counters (perhaps 50 max). The count needs to be monotonic and consistent, (ie: guaranteed unique sequential values).

Each counter should have a few methods, like reset, inc, dec, set, clear, remove. As a luxury, I would like to have a variable-increment (ie: 'step by' value). To support thread-safefty, perhaps some sorm of critical-section or mutex call. It just needs to return a long/4byte signed integer.

I really want something that can be called from anywhere, including VBScript, so I figure COM is my preferred solution.

The primary use of this is for database keys. I am unable to use autoinc or guid type keys and have ruled out database-generated counting systems at this point.

I've spent days researching this and I have really struggled to find a solution. The best I can find is a free-threaded dictionary object that can be instantiated using COM+ from Motobit - it seems to offer all the 'basics' and I guess I could create some form of wrapper for this.

So, here are my questions:

  • Does such a 'general purpose counter-object already exist? Can you direct me to it? (MS did do an IIS/ASP object called 'MSWC.Counter' but this isn't 'cross-process'/ out-of-process component and isn't thread-safe. (but if it was, it would do!)

  • What is the best way of creating such a Component? (I'd prefer VB6 right-now, [don't ask!] but can do in VB.NET2005 if I had to). I don't have the skills/knowledge/tools to use anything else.

I am desparate for a workable solution. I need specific guidance! If anybody can code something up for me I am prepared to pay for it.

© Stack Overflow or respective owner

Related posts about com

Related posts about vb6