Re: [Prevayler] Re: Other implementations
Brought to you by:
jsampson,
klauswuestefeld
From: klausw <kl...@bo...> - 2002-04-19 04:28:09
|
Unless we find a way of overcoming the problem, it seems impossible to incorporate this improvement in Prevayler. How about implementing an abstract class called something like SerializableReference that would allow instances of its subclasses to be referenced in commands. It would work like this: - Every instance receives an id when created (this is transparent to the client and to the subclasses). - During serialization, if the object is already created in the system, it would use writeReplace() to write just a holder with its id. - During deserialization, the holder would use readResolve() to retrieve the correct object by id. "Class-defined writeReplace and readResolve methods Since 1.2, classes can define writeReplace and readResolve methods which allow instances of the given classes to nominate replacements for themselves during serialization and deserialization. The required signatures of these methods, along with further details, are described in sections 2.5 and 3.6 of the Java Object Serialization Specification." JDK 1.3 / Documentation / Features / Object Serialization. What do you think? See you, Klaus. > Thanks for reminding me of this - work and home life are beginning to > intrude on my personal time. > > Klaus - yes, my implementation is exactly what you'd expect, and breaks > in the way you mention. I spent some time thinking about the problem, > and unless someone else has a good idea, have decided that the cleanest > solution is to simply explain the constraint to developers (i.e. any > type of business object you store in a Command, you need to create and > store in a Command). > > Any thoughts? > > josh > > > Hi all, > > > > I've talked with Josh about this, and seems that it > > loses the references after system crashes or > > shutdowns. > > Well, this happen in the Squeak version of Prevayler > > that Josh nicely sent to me. > > > > Sorry Josh, for my intromission. > > > > Best regards, > > > > #Jean. > > > > Klaus wrote: > >> It seems to me that your implementation to support > >> referencing business objects in commands is to use > >> the > >> same ObjectOutputStream for the commands as was used > >> for > >> the snapshot. > >> > >> The problem is when a command has to reference an > >> object > >> that was created inside the business system AFTER > > the > >> snapshot was taken. > >> > >> Suppose the following: > >> 1) You execute a command to create Person1 with the > >> name > >> "Peter". This command does not reference the new > >> Person, > >> it only has the String for the name. > >> > >> 2) You query by name and retrieve Person1 from the > >> system. > >> > >> 3) You execute a command to change the name of > >> Person1 > >> to "Mary". Person1 was never serialized before so it > >> will be completely serialized to the stream. > >> > >> 4) You query the system. You don't find Peter and > > you > >> find Mary. That is correct. > >> > >> 5) The system crashes. > >> > >> 6) The first command is recovered and a Person > > called > >> "Peter" is created in the new system, as expected. > >> > >> 7) The second command is recovered and instead of > >> changing the person that has just been created by > > the > >> last command, it completely recreates Person1 from > >> the > >> stream and changes its name to "Mary". The system > >> knows nothing about the recreated Person1 and > >> Person1 is > >> garbage collected. The person created in the system > >> ("Peter") remains unaltered. > >> > >> 8) You query the system. You find Peter and you > > don't > >> find Mary. That is incorrect. > >> > >> -------- > >> > >> That is my understanding of your solution and of the > >> problem. Am I at least close? If so, how did you > >> solve > >> it? > >> > >> See you, Klaus. > > > > > > __________________________________________________ > > Do You Yahoo!? > > Yahoo! Tax Center - online filing with TurboTax > > http://taxes.yahoo.com/ > > > > _______________________________________________ > > Prevayler(TM) - The Open-Source Prevalence Layer. > > http://www.prevayler.org > > _______________________________________________ > Prevayler(TM) - The Open-Source Prevalence Layer. http://www.prevayler.org > __________________________________________________________________________ Quer ter seu pr=F3prio endere=E7o na Internet? Garanta j=E1 o seu e ainda ganhe cinco e-mails personalizados. Dom=EDniosBOL - http://dominios.bol.com.br |