Re: Is there an unique identifier for each object?
Thursday, March 17, 2005 07:39 AM
Google for references on unique identifier generation. I think it largely depends on clarifying your domain e.g. how wide of a net are you going to cast with your universe of identifiers, etc. All within one JVM, or across multiple JVM's? Is there going to be clustering, replication etc., where some physically distinct objects might actually need to be identified with the same equivalence class?
What order of magnitude is your total number of objects likely to grow to? Tens, hundreds, millions, billions?
How long are your objects going to last? Is the number of identified objects going to grow, without bound? Could the id's ever "cycle" e.g. start over after long enough time has passed so all the original low-numbered ones are long gone?
How fast are you going to be creating and identifying new objects? Will there be a reasonable time lag between requests for new id's, allowing a slower algorithm involving unique timestamps, or must they be generated very very quickly? Will you even be able to have a central id generator/repository, or would that be a bottleneck so you need a more distributed system, with inherent synchronization problems?
Will there be times you want to re-use id's after an object has been gone for long enough, or do you want their unique id to be forever "retired" after the corresponding object is long gone? Will you want to ever garbage collect among your id's, reap "holes", large gaps in your set of id's, for sets of objects that have been gone for long enough?
One example is just to have a table in your database, with a row for each object, and use the primary key as your unique id (maybe using a 'sequence' to generate the keys, whatever). But that depends on your domain, if you do have a database that all your collaborating agents (servers, JVM's, distributed objects, whatever) can reference in a synchronized manner, and if you can indeed manage to maintain a row for each of your objects, etc.
Email systems are another example. Because of the RFC requirements for headers on messages, they need to have "message-id" generating algorithms, which are supposed to be unique across the world of email messages, so look into how they are managed etc. (sendmail, qmail, etc.) Typically they use the hostname or IP address, plus a timestamp, etc. But of course then you must have a unique hostname and/or routable (not NAT'ted) IP address, reasonably synchronized clocks, correct timezone and daylight savings settings, etc.
Also re IP addresses, is your system going to be running long enough that you might have to upgrade to IPv6 addresses?
Microsoft also has their own unique id generation system for COM/DCOM objects, among their tools that come with Visual Studio, MSDN etc. That's where all those long id's come from, in the Windows "registry". I think theirs was modified from a prior system in OSF's DCE? or CORBA? I forget, but look it up.