Re: How to protect dynamic lookup content when it is changing?
Steven Yi <[email protected]>
| Newsgroups | gmane.comp.java.netbeans.modules.openide.devel |
|---|---|
| Message-ID | <CANtcCs6xZu850HRED7bdCBPuvJ=opGFqeGDAALWGLGqJkiaXOQ@mail.gmail.com> |
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()? > > > >