/** * Add a service query to the registry. * @param type The service type. * @param scope The scope. * @param filter The filter. */ public static <T> ISubscriptionIntermediateFuture<T> addQuery(final IComponentIdentifier cid, Class<T> type, String scope, IAsyncFilter<T> filter) { ServiceQuery<T> query = new ServiceQuery<T>(type, scope, filter, cid); return SynchronizedServiceRegistry.getRegistry(cid).addQuery(query); } }
queries = new HashMap<ClassInfo, Set<ServiceQueryInfo<?>>>(); Set<ServiceQueryInfo<T>> mqs = (Set)queries.get(query.getType()); if(mqs==null) queries.put(query.getType(), (Set)mqs); Iterator<T> sers = (Iterator<T>)getServices(query.getType()); if(sers!=null) Collection<T> ssers = searchfunc.checkScope(sers, query.getOwner(), query.getScope(), false); searchfunc.checkAsyncFilters(query.getFilter(), ssers.iterator()) .addIntermediateResultListener(new UnlimitedIntermediateDelegationResultListener<T>(ret));
public void run() { // Class<T> mytype = query.getType()==null? null: (Class<T>)query.getType().getType0(); // searchRemoteServices(query.getOwner(), mytype, query.getFilter()).addIntermediateResultListener(lis); searchRemoteServices(query.getOwner(), query.getType(), query.getFilter()).addIntermediateResultListener(lis); if(!ret.isDone()) waitForDelay(delay, this); else System.out.println("stopping global query polling: "+query); } });
/** * Remove all service queries of a specific component from the registry. * @param owner The query owner. */ public void removeQueries(IComponentIdentifier owner) { if(queries!=null) { for(Map.Entry<ClassInfo, Set<ServiceQueryInfo<?>>> entry: new HashSet<Map.Entry<ClassInfo, Set<ServiceQueryInfo<?>>>>(queries.entrySet())) { for(ServiceQueryInfo<?> query: entry.getValue().toArray(new ServiceQueryInfo<?>[entry.getValue().size()])) { if(owner.equals(query.getQuery().getOwner())) { removeQuery(query.getQuery()); // entry.getValue().remove(query); } } } } }
/** * Remove a service query from the registry. * @param query ServiceQuery. */ public <T> void removeQuery(ServiceQuery<T> query) { if(queries!=null) { Set<ServiceQueryInfo<T>> mqs = (Set)queries.get(query.getType()); if(mqs!=null) { for(ServiceQueryInfo<T> sqi: mqs) { if(sqi.getQuery().equals(query)) { sqi.getFuture().terminate(); mqs.remove(sqi); break; } } if(mqs.size()==0) queries.remove(query.getType()); } } }
if(RequiredServiceInfo.SCOPE_GLOBAL.equals(query.getScope()))
if(owner.equals(query.getQuery().getOwner()))
/** * Add a service query to the registry. * @param type The service type. * @param scope The scope. * @param filter The filter. */ public <T> ISubscriptionIntermediateFuture<T> addQuery(Class<T> type, String scope, IAsyncFilter<T> filter) { ServiceQuery<T> query = new ServiceQuery<T>(type, scope, filter, getComponent().getComponentIdentifier()); return SynchronizedServiceRegistry.getRegistry(getComponent()).addQuery(query); } }