/** Delete all cached values, the template changed. */ protected void collectFires(Collection<Object> evAndListeners) { Object[] previousItems = getItemsCache(); clearCaches(); if (previousItems != null) { Object[] newArray = allItemsWithoutBeforeLookup().toArray(); if (compareArrays(previousItems, newArray)) { // do not fire any change if nothing has been changed return; } } LookupListener[] arr; synchronized (this) { if (listeners == null) { return; } if (listeners instanceof LookupListener) { arr = new LookupListener[] { (LookupListener) listeners }; } else { ArrayList<?> l = (ArrayList<?>) listeners; arr = l.toArray(new LookupListener[l.size()]); } } final LookupListener[] ll = arr; final LookupEvent ev = new LookupEvent(this); notifyListeners(ll, ev, evAndListeners); }
/** Set of all classes. * */ @Override public Set<Class<? extends T>> allClasses() { reference.lookup.beforeLookup(reference.template); Set<Class<? extends T>> s = getClassesCache(); if (s != null) { return s; } s = new HashSet<Class<? extends T>>(); for (Pair<T> item : allItemsWithoutBeforeLookup()) { Class<? extends T> clazz = item.getType(); if (clazz != null) { s.add(clazz); } } s = Collections.unmodifiableSet(s); setClassesCache(s); return s; }
protected Collection<T> allInstances(boolean callBeforeLookup) { if (callBeforeLookup) { reference.lookup.beforeLookup(reference.template); } Collection<T> s = getInstancesCache(); if (s != null) { return s; } Collection<Pair<T>> items = allItemsWithoutBeforeLookup(); ArrayList<T> list = new ArrayList<T>(items.size()); Iterator<Pair<T>> it = items.iterator(); while (it.hasNext()) { Pair<T> item = it.next(); T obj = item.getInstance(); if (reference.template.getType().isInstance(obj)) { list.add(obj); } } s = Collections.unmodifiableList(list); setInstancesCache(s); return s; }
Object[] c = getItemsCache (); if (c != null) { return Collections.unmodifiableList (Arrays.asList (c)); try { try { return Collections.unmodifiableCollection (initItems (t)); } catch (AbstractLookup.ISE ex) {
Object[] c = getItemsCache (); if (c != null) { return Collections.unmodifiableList (Arrays.asList (c)); try { try { return Collections.unmodifiableCollection (initItems (t)); } catch (AbstractLookup.ISE ex) {
Object[] previousItems = getItemsCache (); clearCaches (); Object[] newArray = allItemsWithoutBeforeLookup ().toArray ();
/** Delete all cached values, the template changed. */ protected void collectFires(Collection<Object> evAndListeners) { Object[] previousItems = getItemsCache(); clearCaches(); if (previousItems != null) { Object[] newArray = allItemsWithoutBeforeLookup().toArray(); if (compareArrays(previousItems, newArray)) { // do not fire any change if nothing has been changed return; } } LookupListener[] arr; synchronized (this) { if (listeners == null) { return; } if (listeners instanceof LookupListener) { arr = new LookupListener[] { (LookupListener) listeners }; } else { ArrayList<?> l = (ArrayList<?>) listeners; arr = l.toArray(new LookupListener[l.size()]); } } final LookupListener[] ll = arr; final LookupEvent ev = new LookupEvent(this); notifyListeners(ll, ev, evAndListeners); }
/** Implements the search for allItems, but without asking for before lookup */ private Collection<Pair<T>> allItemsWithoutBeforeLookup() { Pair<T>[] c = getItemsCache(); if (c != null) { return Collections.unmodifiableList(Arrays.asList(c)); } ArrayList<Pair<Object>> saferCheck = null; AbstractLookup.Storage<?> t = reference.lookup.enterStorage(); try { try { return Collections.unmodifiableCollection(initItems(t)); } catch (AbstractLookup.ISE ex) { // do less effective evaluation of items outside of the // locked storage saferCheck = new ArrayList<Pair<Object>>(); Enumeration<Pair<Object>> en = t.lookup(null); // get all Pairs while (en.hasMoreElements()) { Pair<Object> i = en.nextElement(); saferCheck.add(i); } } } finally { reference.lookup.exitStorage(); } return extractPairs(saferCheck); }
/** Implements the search for allItems, but without asking for before lookup */ private Collection<Pair<T>> allItemsWithoutBeforeLookup() { Pair<T>[] c = getItemsCache(); if (c != null) { return Collections.unmodifiableList(Arrays.asList(c)); } ArrayList<Pair<Object>> saferCheck = null; AbstractLookup.Storage<?> t = reference.lookup.enterStorage(); try { try { return Collections.unmodifiableCollection(initItems(t)); } catch (AbstractLookup.ISE ex) { // do less effective evaluation of items outside of the // locked storage saferCheck = new ArrayList<Pair<Object>>(); Enumeration<Pair<Object>> en = t.lookup(null); // get all Pairs while (en.hasMoreElements()) { Pair<Object> i = en.nextElement(); saferCheck.add(i); } } } finally { reference.lookup.exitStorage(); } return extractPairs(saferCheck); }
Object[] previousItems = getItemsCache (); clearCaches (); Object[] newArray = allItemsWithoutBeforeLookup ().toArray ();
/** Delete all cached values, the template changed. */ protected void collectFires(Collection<Object> evAndListeners) { Object[] previousItems = getItemsCache(); clearCaches(); if (previousItems != null) { Object[] newArray = allItemsWithoutBeforeLookup().toArray(); if (compareArrays(previousItems, newArray)) { // do not fire any change if nothing has been changed return; } } LookupListener[] arr; synchronized (this) { if (listeners == null) { return; } if (listeners instanceof LookupListener) { arr = new LookupListener[] { (LookupListener) listeners }; } else { ArrayList<?> l = (ArrayList<?>) listeners; arr = l.toArray(new LookupListener[l.size()]); } } final LookupListener[] ll = arr; final LookupEvent ev = new LookupEvent(this); notifyListeners(ll, ev, evAndListeners); }
protected Collection<T> allInstances(boolean callBeforeLookup) { if (callBeforeLookup) { reference.lookup.beforeLookup(reference.template); } Collection<T> s = getInstancesCache(); if (s != null) { return s; } Collection<Pair<T>> items = allItemsWithoutBeforeLookup(); ArrayList<T> list = new ArrayList<T>(items.size()); Iterator<Pair<T>> it = items.iterator(); while (it.hasNext()) { Pair<T> item = it.next(); T obj = item.getInstance(); if (reference.template.getType().isInstance(obj)) { list.add(obj); } } s = Collections.unmodifiableList(list); setInstancesCache(s); return s; }
/** The general lookup method. * @param template the template describing the services we are looking for * @return object containing the results */ public final Lookup.Result lookup (Lookup.Template template) { for (;;) { AbstractLookup.ISE toRun = null; AbstractLookup.Storage t = enterStorage (); try { R r = new R (); ReferenceToResult newRef = new ReferenceToResult (r, this, template); newRef.next = t.registerReferenceToResult (newRef); return r; } catch (AbstractLookup.ISE ex) { toRun = ex; } finally { exitStorage (); } toRun.recover (this); // and try again } }
/** The general lookup method. * @param template the template describing the services we are looking for * @return object containing the results */ public final Lookup.Result lookup (Lookup.Template template) { for (;;) { AbstractLookup.ISE toRun = null; AbstractLookup.Storage t = enterStorage (); try { R r = new R (); ReferenceToResult newRef = new ReferenceToResult (r, this, template); newRef.next = t.registerReferenceToResult (newRef); return r; } catch (AbstractLookup.ISE ex) { toRun = ex; } finally { exitStorage (); } toRun.recover (this); // and try again } }
/** Set of all classes. * */ public Set allClasses () { reference.lookup.beforeLookup (reference.template); Set s = getClassesCache (); if (s != null) { return s; } s = new HashSet (); Iterator it = allItemsWithoutBeforeLookup ().iterator (); while (it.hasNext ()) { Item item = (Item)it.next (); Class clazz = item.getType (); if (clazz != null) { s.add (clazz); } } setClassesCache (s); return s; }
public Collection allInstances () { reference.lookup.beforeLookup (reference.template); Collection s = getInstancesCache (); if (s != null) { return s; } Collection items = allItemsWithoutBeforeLookup (); s = new ArrayList (items.size ()); Iterator it = items.iterator (); while (it.hasNext ()) { Item item = (Item)it.next (); Object obj = item.getInstance (); if (obj != null) { s.add (obj); } } setInstancesCache (s); return s; }
@Override public final <T> Lookup.Result<T> lookup(Lookup.Template<T> template) { beforeLookupResult(template); for (;;) { AbstractLookup.ISE toRun = null; AbstractLookup.Storage<?> t = enterStorage(); try { R<T> r = new R<T>(); ReferenceToResult<T> newRef = new ReferenceToResult<T>(r, this, template); newRef.next = t.registerReferenceToResult(newRef); return r; } catch (AbstractLookup.ISE ex) { toRun = ex; } finally { exitStorage(); } toRun.recover(this); // and try again } }
/** Set of all classes. * */ public Set allClasses () { reference.lookup.beforeLookup (reference.template); Set s = getClassesCache (); if (s != null) { return s; } s = new HashSet (); Iterator it = allItemsWithoutBeforeLookup ().iterator (); while (it.hasNext ()) { Item item = (Item)it.next (); Class clazz = item.getType (); if (clazz != null) { s.add (clazz); } } setClassesCache (s); return s; }
/** Set of all classes. * */ @Override public Set<Class<? extends T>> allClasses() { reference.lookup.beforeLookup(reference.template); Set<Class<? extends T>> s = getClassesCache(); if (s != null) { return s; } s = new HashSet<Class<? extends T>>(); for (Pair<T> item : allItemsWithoutBeforeLookup()) { Class<? extends T> clazz = item.getType(); if (clazz != null) { s.add(clazz); } } s = Collections.unmodifiableSet(s); setClassesCache(s); return s; }
public Collection<T> allInstances() { reference.lookup.beforeLookup(reference.template); Collection<T> s = getInstancesCache(); if (s != null) { return s; } Collection<Pair<T>> items = allItemsWithoutBeforeLookup(); ArrayList<T> list = new ArrayList<T>(items.size()); Iterator<Pair<T>> it = items.iterator(); while (it.hasNext()) { Pair<T> item = it.next(); T obj = item.getInstance(); if (reference.template.getType().isInstance(obj)) { list.add(obj); } } s = Collections.unmodifiableList(list); setInstancesCache(s); return s; }