Re: Thread synchronization problem

From: Vincent Lascaux (nospam_at_nospam.org)
Date: 09/02/04


Date: Thu, 2 Sep 2004 00:39:48 +0100


> I cannot offer reliable design advice without knowing what requirements
> the design is supposed to satisfy. You have described specific actions
> that you want your code to perform. Fine, but that's not a design-level
> issue. If you want design advice then I need a higher-level picture.

Sorry about that
The Data class stores some informations that are downloaded from a computer
above the network.
I have in two data classes: one container (Datas) and the actual data (Data)
Datas acts as a map<string, Data>

Datas offers methods such as size(), getByName(string), iterator(),
add(string, Data), remove(string), removeAll()
Data offers also several methods to work (read and modify) the data
contained (I dont think it is necessary to describe the whole context).

When I ask to download a Datas object, I download only the list of names,
and dont want to download the actual content of the Data object.
When I ask to download a Data object, the information is retrieved from the
network.

These two objects are used rather intensively in the application (the only
purpose of this application is in fact to manage these datas).
In my first code, I checked whether the data was empty every time I accessed
it (like every time I did size(), I first checked and downloaded the Datas
object if it was empty). It was fine while the application was small enough,
but soon I forgot to download at some locations in the code, and maintaining
that became quite complex.
So my idea was to move this "check and download if necessary" procedure
inside the Datas and Data object. They would always be considered as not
empty for the user of the table, and when the first method is called, it
would download the data. That's where I am, with my synchronization problem.

> I think it's needlessly complex, and may not satisfy your requirements.
> Earlier you wrote that Data's methods must invoke assertNotEmpty(),
> which they do not do in this design. If those methods cannot perform
> meaningful and appropriate work on an empty instance (or one in the
> process of being downloaded) then this design cannot work. If they
> _can_ perform appropriate work under those circumstances then you have
> not correctly characterized your problem.

The Data object cannot perform meaningful and appropriate work on empty
instance.
The idea behind this design is that if you use the Data object, then you are
responsible for downloading it if it is empty, before accessing any of the
methods.
The DataAccessor is there to ensure that for you, checking if the data has
been previously downloaded before accessing it in any way.
I agree this is complex, and I would like a more simple solution...

>
> From your example above, it seems like you are trying to implement a
> version of the Flyweight pattern. Perhaps you will find some useful
> advice if you know the name of what you're trying to do. On the other
> hand, it may be that an altogether different strategy would be better --
> I just can't say because I don't know _why_ you are doing what you are
> doing.

I'm not sure about the Flyweight pattern. Looking through google, it looks
like it is a pattern to share some common information among several objects.
That doesnt seem to be what I want to do

-- 
Vincent


Relevant Pages

  • Re: [Rubyinstaller-devel] One-Click Ruby Installer needs a new home, can you help him?
    ... I think that hosting a web site (as opposed a download site) is not ... downloads, but provide a better, simplified and clean access to Ruby ... Simple, clean, friendly design. ...
    (comp.lang.ruby)
  • Re: How much text on a page?
    ... allows people to sample a story without having to download the entire ... There is also a bit of future-proofing in my design. ... I recognise that HTML generators will probably not produce ... "WYSIWYG" mode then you may want to look for a newsgroup dedicated to ...
    (uk.net.web.authoring)
  • Re: Thread synchronization problem
    ... > above the network. ... > When I ask to download a Datas object, I download only the list of names, ... > and dont want to download the actual content of the Data object. ... > I'm not sure about the Flyweight pattern. ...
    (comp.lang.java.programmer)
  • Xilinx 3E design programs fine with 500E but fails with 250E
    ... Ive got a design that uses the spartan XC3S500E, ... and a .MCS (which works correctly when you download it direct to the ... it fails to program the external M25P80 SPI flash ... SPI access core not detected. ...
    (comp.arch.fpga)
  • Re: The Right Way to Design a Programme
    ... And no, I'm not suggesting that a system design is immutable, it ... absence of a good tool to capture what is in their mind. ... the UML-yankers out of the room for a few months, ... the cowoker in cubicle next to me suggested I download ...
    (comp.theory)