Re: How to protect dynamic lookup content when it is changing?

Dmitry Avtonomov <[email protected]>
Newsgroups gmane.comp.java.netbeans.modules.openide.devel
Message-ID <CAMMjtf-zPPhpw52ni_227YR=hYreCMJd4FTWghiKWWvPOkZnxQ@mail.gmail.com>
I guess you could synchronize all access methods on a common lock, but
don't use the lookup itself for sync, as the actual underlying object might
change.

Or use a ReadWriteLock as usual.

But Steven's suggestion is probably the right way to go. Don't forget to
use weak listeners or unsubscribe listeners manually.

On Oct 11, 2016 09:27, "Steven Yi" <[email protected]> wrote:

> Not knowing the complete context, I'm wondering if you could change
> the architecture such that rather than have another thread that might
> poll the lookup data, you could modify the code to use a
> LookupListener and react when modifications have occurred.
>
> On Tue, Oct 11, 2016 at 7:33 AM, rsobies <[email protected]> wrote:
> > i would like to block accesing lookup content when another thread is
> puting into lookup.
> > here is an example
> >
> >
> > Code:
> >
> > public class MyNode extends AbstractNode {
> >
> >     private InstanceContent instanceContent = new InstanceContent();
> >
> >     public MyNode(SomeKey key) {
> >         this(key, new InstanceContent());
> >     }
> >
> >     private CarNode(SomeKey key, InstanceContent ic) {
> >         super(Children.LEAF, new AbstractLookup(ic));
> >
> >         this.instanceContent = ic;
> >         instanceContent.add(key);
> >     }
> >
> >     public void setNewKey(SomeKey key) {
> >         Collection<? extends SomeKey> lookupAll =
> getLookup().lookupAll(SomeKey.class);
> >         for (Object item : lookupAll) {
> >             remove(item);
> >         }
> >
> >  //at this time lookup is empty, if another thread tries to get content,
> it gets null
> >
> >         instanceContent.add(key);
> >     }
> > }
> > }
> >
> >
> >
> >
> > is there an elegant way to block getLookup().lookup(SomeKey.class)
> during execution of setNewKey()?
> >
> >
> >
> >
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.