/** * Put a file. * @param file The file data. * @param path The target path. * @return True, when the file has been copied. */ public ITerminableIntermediateFuture<Long> uploadFile(IInputConnection con, String path, String name) { try { return con.writeToOutputStream(new FileOutputStream(path+File.separator+name), agent); } catch(Exception e) { return new TerminableIntermediateFuture<Long>(e); } }
/** * Checks if the search is finished and then * automatically terminates the search future. */ protected boolean checkFinished(IResultSelector ressel, TerminableIntermediateFuture<IService> fut) { boolean ret = ressel.isFinished(fut.getIntermediateResults()); if(ret) { fut.terminate(); } return ret; }
/** * Get required services. * @return The services. */ public <T> ITerminableIntermediateFuture<T> getRequiredServices(RequiredServiceInfo info, RequiredServiceBinding binding, boolean rebind, IRemoteFilter<T> filter) { if(info==null) { TerminableIntermediateFuture<T> ret = new TerminableIntermediateFuture<T>(); ret.setException(new IllegalArgumentException("Info must not null.")); return ret; } IRequiredServiceFetcher fetcher = getRequiredServiceFetcher(info.getName()); return fetcher.getServices(info, binding, rebind, filter); }
public void exceptionOccurred(Exception exception) { // The search is considered as success if at least // one service could be found. // Otherwise search in a disconnected platform could // raise a timeout exception which is propagated here. if(ret.getIntermediateResults().size()>0) { ret.setFinishedIfUndone(); } else { ret.setExceptionIfUndone(exception); } } });
final IResultSelector selector, Map<Class<?>, Collection<IService>> services) final TerminableIntermediateFuture<IService> ret = new TerminableIntermediateFuture<IService>(); final TerminableIntermediateDelegationFuture<IService> del = new TerminableIntermediateDelegationFuture<IService>(); ret.addResultListener(new TerminableIntermediateDelegationResultListener<IService>(del, ret) ret.setTerminationCommand(new ITerminationCommand()
ret.addIntermediateResult(Long.valueOf(0)); if(ret!=null) ret.setExceptionIfUndone(new RuntimeException(TransferInfo.STATE_ERROR, e)); } else { e.printStackTrace();
public void exceptionOccurred(Exception exception) { ret.setException(exception); } });
final TerminableIntermediateFuture<IRemoteCommand> ret = new TerminableIntermediateFuture<IRemoteCommand>(new TerminationCommand() ret.addResultListener(new IResultListener<Collection<IRemoteCommand>>()
/** * 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()); } } }
final TerminableIntermediateFuture<Long> ret = new TerminableIntermediateFuture<Long>(); ret.setExceptionIfUndone(e);
/** * Retrieve information about platforms as they appear or vanish. * @param include_initial If true, information about initially known platforms will be immediately posted to the caller. * Otherwise only changes that happen after the subscription will be posted. * @return An intermediate future that is notified about any changes. */ public ITerminableIntermediateFuture<DiscoveryInfo> subscribeToPlatformList(boolean include_initial) { if(listeners==null) { listeners = new LinkedHashSet<TerminableIntermediateFuture<DiscoveryInfo>>(); } TerminableIntermediateFuture<DiscoveryInfo> ret = new TerminableIntermediateFuture<DiscoveryInfo>(); listeners.add(ret); if(include_initial) { for(DiscoveryInfo dif: discovered.values()) { ret.addIntermediateResult(dif); } } return ret; }
public void exceptionOccurred(Exception exception) { // ret.setResult(new RemoteResultCommand(null, exception, callid, false)); ret.addIntermediateResultIfUndone(new RemoteResultCommand(null, null, exception, callid, false, null, getNonFunctionalProperties())); ret.setFinishedIfUndone(); } });
ret.setFinishedIfUndone(); ret.setException(exception);
public void intermediateResultAvailable(IService result) { ret.addIntermediateResult(result); }
final TerminableIntermediateFuture<T> ret = new TerminableIntermediateFuture<T>(); ret.setFinished(); ret.setFinished(); ret.setFinished();
public void resultAvailable(Collection<IService> result) { removeOpenCall(endret, fut); if(result!=null) { for(Iterator<IService> it=((Collection<IService>)result).iterator(); it.hasNext(); ) { IService next = it.next(); // Must recheck if already finished (otherwise duplicate results may occur). if(!endret.getIntermediateResults().contains(next) // && !selector.isFinished(endret.getIntermediateResults())) && !checkFinished(selector, endret)) { // System.out.println("found: "+next); endret.addIntermediateResult(next); } } } checkAndSetResults(ret, finished, 0); }
ret.setResult(result); ret.addIntermediateResult(ser); ret.setTerminationCommand(new ITerminationCommand()
/** * Terminate the future and supply a custom reason. */ public void terminate(Exception reason) { boolean term = !isDone() && (terminate==null || terminate.checkTermination(reason)); if(term && setExceptionIfUndone(reason)) { if(terminate!=null) { terminate.terminated(reason); } } }
public void exceptionOccurred(Exception exception) { // if(selector instanceof TypeResultSelector && ((TypeResultSelector) selector).getType().toString().indexOf("ILocalService")!=-1) // { // System.out.println("remote search failed locally: "+componentid+", "+exception); // } ret.setExceptionIfUndone(exception); } });