Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [wtp-dev] Proposed new pattern for managed models (was "Re: Scary code")

This pattern has been used for a while, and the requirement to release the resource is documented (e.g. try ... finally is considered part of the API usage pattern).

These objects facade the edit models, which each have a client access registry. This object will track requestors in a smart way, and unreleased models will throw exceptions that indicate exactly where from a model was incorrectly accessed (and later not disposed).
 
We have moved away from this pattern with our Virtual Path API which will be using the StructureEdit (formerly ModuleCore) EMF layer. Clients will now be using a handle based model backed by the EMF model for accessing the information in the .wtpmodules file.
 
Clients will still be required to follow this pattern for the ArtifactEdit classes.
 
 
-------------------------------------------------------------------------
Kind Regards,
 
Michael D. Elder
Rational Studio / J2EE Tools Development     
IBM RTP Lab
Ext: (919) 543-8356
T/L: 441-8356
mdelder@xxxxxxxxxx
 
 
 
Wednesday, April 06, 2005 11:41 PM
To: wtp-dev@xxxxxxxxxxx
cc:
From: David M Williams/Raleigh/IBM@IBMUS
Subject: [wtp-dev] Proposed new pattern for managed models (was "Re: Scary   code")



Naci Dai wrote ....
>There is something that makes me uneasy about the following code...
>
>core = StructureEdit.getStructureEditForRead(projects[i]);

>....
>some stufff
>...
>core.dispose();
>
>This is very open to making mistakes (i.e unbalanced dispose). I do not have

>an answer to an alternative, try-finally is a clumsy workaround,
>but I have a feeling this bug will also be a pattern.

I'm not sure our SSE ModelManager is the only reason for this pattern,
but it is one.

The model provided is a "shared resource" so, it is appropriate for clients to
be required to use a try {} finally{} pattern to ensure proper acquisition and
release. But ... it is admittedly a problem area and often prone to bugs.

To help address this, part of our proposed API change (for next milestone) will be to move to
a pattern something like

connect(requester, IPath)

model = getModel(IPath)

disconnect(requester, IPath).

A try/finally pattern will still be required (and is still appropriate) ... but
1) it is similar to the base eclipse's
pattern in IFileBufferManager ... so maybe more familar to Eclipse programmers? (or, is
at least one problematic pattern instead of two :),  and
2) the presense of 'requester' on the call will allow for improved debugging messages
(eventually) [thanks to Jason Sholl for this suggestion]

Thought I'd post these ideas here now, instead of waiting till whole design change
documented, in case there was any wtp developer comment or implications we
should be aware of.

Thanks for the discussion.


Back to the top