• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: MultiECLockManager. Set and forget ?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: MultiECLockManager. Set and forget ?


  • Subject: Re: MultiECLockManager. Set and forget ?
  • From: Miguel Arroz <email@hidden>
  • Date: Thu, 26 Apr 2007 01:24:33 +0100

Hi!

Yes, basically, it works automatically. You don't even have to worry about de-regestering the contexts, they will be automatically put away by the memory manager (MultiECLockManager uses soft- references). Remember that you cannot call dispose() method on registered contexts.

Also, I have made some useful methods, that I have on my top level component (a WOComponent subclass, from where all my other components inherit from). I think that something like this exists on Wonder, but I'm still not using their locking mechanisms (yes yes, boo for me, i know!) :)

/**
* <p>Gets the editing context associated with a key.</p>
* <p>Obtains the editing context associated to a key. If the value of the key
* is null, ir creates a new context, registers it on the multi context locker,
* and returns it.</p>
*
* @param contextKey - name of the key that stores the context
* @return the existing context, or a new one.
*/
public EOEditingContext contextForKey(String contextKey) {
if( valueForKey(contextKey) == null ) {
setContextForKey(new EOEditingContext(), contextKey);
}
return (EOEditingContext)valueForKey(contextKey);
}


/**
* <p>Sets an editing context for a key.</p>
* <p>Sets the value of the given key to the given editing context.
* The key must exist in the component as specified by the key/ value
* methodolody used in WebObjects. A public instance variable will do.
* The recommended way to handle setting a context is to have a public
* variable called <whatever>EditingContext, that is never used directly,
* and then two accessor methods:</p>
*
* <code>
* public EOEditingContext <whatever>Context() {
* return contextForKey("<whatever>EditingContext");
* }
*
* public void set<Whatever>Context( EOEditingContext newContext ) {
* setContextForKey(newContext, "<whatever>EditingContext");
* }
* </code>
*
* <p>Note that the variable must NOT have the same name as the getter, or
* the key/value internal methods will enter an infinite loop.</p>
*
* <p>The new context will always be registeres in the multi context locker.
* There's no problem if it was already registeres before.</p>
*
* <p>See more details in the coding guidelines document.</p>
*
* @param newContext
* @param contextKey
*/
public void setContextForKey(EOEditingContext newContext, String contextKey) {
// Previously we were unregistering the context. Big mistake, because the context might
// be used somewhere else, and as the multi-locker class will store a weak reference to
// it, it will be dealloced when it's not needed any more.


takeValueForKey(newContext, contextKey);
if( newContext != null ) {
theSession().lockManager().registerEditingContext (newContext);
}
}


This way, all I have to do it calling contextForKey and setContextForKey. I don't even have to create the contexts, this methods create them automatically.

  Yours

Miguel Arroz

On 2007/04/26, at 01:12, Owen McKerrow wrote:

Hi All,

Im looking at cleaning up our locking procedures on some of our projects. Looking over past emails and on the wiki the most commons suggestions are either MultiECLockManager or Project Wonders ERXEC. We're not using Wonder at the moment so Im thinking MultiECLockManager. I seem to remember Chuck once implying that it was basically a set and forget sort of thing, that once you had registered you EC with it you didn't need to worry about locking anymore. Is this really the case ?

What we have on the current project is a base component that all of our other components extend from. This base component contains a variation of Chucks CoOperatingEditingContext (thanks Chuck), so each of our pages has their own EC with session wide variables, like who's currently logged in, being stored in the default editing context.

What Im wondering is if I was to use MultiECLockManager and it is as simple as it seems, all I should need to do is in my base component when the EC is created, register it with the Manager and then go back through all of my code and find any ec.lock(), ec.unlock() and remove them.

Am I understanding this correctly ?

Owen McKerrow
WebMaster, emlab
Ph : +61 02 4221 5517
http://emlab.uow.edu.au

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

"I like the way this project has somehow, against all common sense, got itself made."
- Peter Jackson, "The Lord of The Rings"



_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40guiamac.com


This email sent to email@hidden


"We have no sympathy for the lost souls
We've chosen the path of disgrace
We give this life to our children
And teach them to hate this place" -- Apocalyptica, Life Burns!

Miguel Arroz
http://www.ipragma.com


_______________________________________________ Do not post admin requests to the list. They will be ignored. Webobjects-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
References: 
 >MultiECLockManager. Set and forget ? (From: Owen McKerrow <email@hidden>)

  • Prev by Date: MultiECLockManager. Set and forget ?
  • Next by Date: Re: MultiECLockManager. Set and forget ?
  • Previous by thread: MultiECLockManager. Set and forget ?
  • Next by thread: Re: MultiECLockManager. Set and forget ?
  • Index(es):
    • Date
    • Thread