/** * */ public DelegatingTerminableIntermediateDelegationFuture(ITerminableIntermediateFuture<?> src, FutureFunctionality func) { if(func==null) throw new IllegalArgumentException("Func must not null."); this.func = func; src.addResultListener(new TerminableIntermediateDelegationResultListener(this, src)); }
public IFuture<Void> execute(IInternalAccess ia) { fut.terminate(); return IFuture.DONE; } });
/** * */ public IFuture<Void> test(int level) { // final Future<Void> ret = new Future<Void>(); // System.out.println("invoked test on: "+agent.getComponentIdentifier()+" level="+level+" "+ServiceCall.getCurrentInvocation().getCause()); if(level<10) { Collection<ITestService> tss = SServiceProvider.getServices(agent, ITestService.class).get(); if(tss.size()>0) { int num = (int)(Math.random()*tss.size()); // System.out.println("found: "+tss.size()+" "+num); List<ITestService> l = new ArrayList<ITestService>(tss); ITestService ts = l.get(num); // The .get() is important to not interrupt the call chain // Do we want it to work also without? ts.test(level+1).get(); } } // return ret; return IFuture.DONE; } }
/** * Terminate the future and supply a custom reason. */ public void terminate(Exception reason) { boolean mynotify; synchronized(this) { // Notify when src is set and not already notified // Remember to notify when src is not set and not already notified mynotify = src!=null && !notified; notify = src==null && !notified; notified = notified || mynotify; if(notify) this.reason = reason; } if(mynotify) src.terminate(reason); if(storedinfos!=null) { for(Object info: storedinfos) { src.sendBackwardCommand(info); } storedinfos = null; } }
if(!future.isDone()) future.addResultListener(new IIntermediateResultListener<IService>() try res = future.get(null);
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); } });
sub.addIntermediateResultListener(new IIntermediateResultListener<String>()
/** * */ public DelegatingTerminableIntermediateDelegationFuture(ITerminableIntermediateFuture<?> src, FutureFunctionality func) { if(func==null) throw new IllegalArgumentException("Func must not null."); this.func = func; src.addResultListener(new TerminableIntermediateDelegationResultListener(this, src)); }
public void intermediateResultAvailable(Void result) { fut.terminate(); } public void customResultAvailable(Collection<Void> result)
@AgentBody public void body() { // System.out.println("MY PLATFORM :" + ia.getComponentIdentifier().getPlatformName()); Collection<IMessageService> services = (Collection)ia.getComponentFeature(IRequiredServicesFeature.class).getRequiredServices("MessageService").get(); IServiceIdentifier[] res = new IServiceIdentifier[services!=null? services.size(): 0]; if(services!=null) { Iterator<IMessageService> it = services.iterator(); for(int i=0; i<services.size(); i++) { res[i] = ((IService)it.next()).getServiceIdentifier(); } ia.getComponentFeature(IArgumentsResultsFeature.class).getResults().put("found", res); if(selfkill) ia.killComponent(); } } }
sub.addIntermediateResultListener(new IIntermediateResultListener<String>()
/** * Create a new future. */ public TerminableIntermediateDelegationFuture(ITerminableIntermediateFuture<?> src) { src.addResultListener(new TerminableIntermediateDelegationResultListener(this, src)); }
/** * Possibly notify the termination source. */ protected void doNotify() { boolean mynotify; synchronized(this) { // Notify when someone has called terminate (notify is set) // src is set and not already notified mynotify = notify && !notified; notified = notified || mynotify; } if(mynotify) src.terminate(reason); }
/** * The agent body. */ @AgentBody public void body() { // todo: make ITerminable in DefaultServiceFetcher try { while(true) { ComposedEvaluator<IAService> ranker = new ComposedEvaluator<IAService>(); ranker.addEvaluator(new ExecutionTimeEvaluator(agent.getExternalAccess(), new MethodInfo(IAService.class.getMethod("test", new Class[0])), true)); ITerminableIntermediateFuture<IAService> sfut = agent.getComponentFeature(IRequiredServicesFeature.class).getRequiredServices("aser"); Collection<Tuple2<IAService, Double>> res = SServiceProvider.rankServicesWithScores(sfut, ranker, null).get(); System.out.println("Found: "+res); IAService aser = res.iterator().next().getFirstEntity(); aser.test().get(); } } catch(Exception e) { System.out.println("User agent problem: "+e); } }
IRequiredServicesFeature rsf = getAgent().getComponentFeature(IRequiredServicesFeature.class); ITerminableIntermediateFuture<IBuyBookService> fut = rsf.getRequiredServices("buyservice"); fut.addIntermediateResultListener(new TimeoutIntermediateResultListener<IBuyBookService>(5000, getExternalAccess(), new IIntermediateResultListener<IBuyBookService>()
/** * Rank the services of a search with a specific ranker and emit the scores. */ public static <S> ITerminableIntermediateFuture<Tuple2<S, Double>> rankServicesWithScores(ITerminableIntermediateFuture<S> searchfut, IServiceRanker<S> ranker, IRankingSearchTerminationDecider<S> decider) { TerminableIntermediateDelegationFuture<Tuple2<S, Double>> ret = new TerminableIntermediateDelegationFuture<Tuple2<S, Double>>(); searchfut.addResultListener(new ServiceRankingDelegationResultListener2<S>(ret, searchfut, ranker, decider)); return ret; }
public void terminated(Exception reason) { Set<ITerminableIntermediateFuture<IService>> ocs = opencalls.get(ret); if(ocs!=null) { for(ITerminableIntermediateFuture<IService> fut: ocs) { fut.terminate(reason); } } opencalls.remove(ret); }
Collection<ITestService> tss = sfut.get(); INFPropertyComponentFeature nfp = agent.getComponentFeature(INFPropertyComponentFeature.class); if(tss.size()>0)
/** * Rank the services of a search with a specific ranker and emit the scores. */ public static <S> ITerminableIntermediateFuture<Tuple2<S, Double>> rankServicesWithScores(ITerminableIntermediateFuture<S> searchfut, IServiceRanker<S> ranker, IRankingSearchTerminationDecider<S> decider) { TerminableIntermediateDelegationFuture<Tuple2<S, Double>> ret = new TerminableIntermediateDelegationFuture<Tuple2<S, Double>>(); searchfut.addResultListener(new ServiceRankingDelegationResultListener2<S>(ret, searchfut, ranker, decider)); return ret; }
public void terminated(Exception reason) { Set<ITerminableIntermediateFuture<IService>> ocs = opencalls.get(ret); if(ocs!=null) { for(ITerminableIntermediateFuture<IService> fut: ocs) { fut.terminate(reason); } } opencalls.remove(ret); }