@AgentCreated public void init() { Future<String> fut = new Future<String>(); fut.addResultListener(new IResultListener<String>() { public void resultAvailable(String message) { ack = message; // setAck(message); } public void exceptionOccurred(Exception exception) { exception.printStackTrace(); } }); fut.setResult("hello"); }
public void exceptionOccurred(Exception exception) { ret.setException(exception); } });
public void exceptionOccurred(Exception exception) { // if(type.toString().indexOf("IFile")!=-1) // System.out.println("Ex result: "+exception); if(!ret.isDone()) { ret.setException(exception); } } });
public <T> IFuture<T> thenCompose(final Function<? super E, IFuture<T>> function, Class<?> futuretype) { final Future<T> ret = getFuture(futuretype); this.addResultListener(new ExceptionDelegationResultListener<E, T>(ret) { public void customResultAvailable(E result) { IFuture<T> res = function.apply(result); res.addResultListener(SResultListener.delegate(ret)); } }); return ret; }
protected void checkFinish() { if(ongoing==0 && finished && !ret.isDone()) { ret.setExceptionIfUndone(new SecurityException("Unable to retrieve certificate: "+name)); } } });
public IFuture<Void> execute(IInternalAccess ia) { final Future<Void> ret = new Future<Void>(); try { AbstractSendTask task = createTask(StreamSendTask.ALIVE, null, null, null); sendTask(task); task.getFuture().addResultListener(new DelegationResultListener<Void>(ret)); } catch(Exception e) { ret.setException(e); } return ret; } });
/** * Get the empty future of some type. * @return The empty future. */ public static <T> IFuture<T> getEmptyFuture() { return new Future<T>((T)null); }
public IFuture<Void> execute(IInternalAccess ia) { ret.setResult(null); return IFuture.DONE; } });
/** * Block until the given time has passed. */ public IFuture<Void> block(long millis) { Future<Void> ret = new Future<Void>(); if(millis>0) { agent.getComponentFeature(IExecutionFeature.class).waitForDelay(millis).get(); ret.setResult(null); } else { // do not set result at all and block forever ret.get(); } return ret; } }
public void customResultAvailable(Boolean res) { if(res.booleanValue()) { ret.setResult(componentfactory); } else { ret.setException(new ComponentCreationException("No factory found for: "+model, ComponentCreationException.REASON_NO_COMPONENT_FACTORY)); } } }));
/** * Get the item catalog. * @return The catalog. */ public IFuture<ItemInfo[]> getCatalog() { IBDIXAgentFeature capa = comp.getComponentFeature(IBDIXAgentFeature.class); final Future<ItemInfo[]> ret = new Future<ItemInfo[]>(); ret.setResult((ItemInfo[])capa.getBeliefbase().getBeliefSet("catalog").getFacts()); return ret; }
public void run() { if(!ret.isDone()) { try { transport.getConnectionManager().ping(adr); ret.setResultIfUndone(adr); } catch(Exception e) { crl.exceptionOccurred(e); } } } });
public void exceptionOccurred(Exception exception) { if(!found) ret.setExceptionIfUndone(exception); } });
/** * Add an functional result listener, which is only called on success. * Exceptions will be handled by DefaultResultListener. * * @param sucListener The listener. */ public void addResultListener(IFunctionalResultListener<E> sucListener) { addResultListener(sucListener, null); }
public void resultAvailable(Object result) { if(partfuture==ret) { partfuture = null; } ret.setResultIfUndone(result); }
@Override public void run() { try { ret.setResultIfUndone(doGetPeerServers(peeraddress, ownaddress, ownid, dbstate, initial)); } catch(Exception e) { ret.setExceptionIfUndone(e); } } });
public IFuture<Void> execute(IInternalAccess ia) { if(!ret.isDone()) { ret.sendForwardCommand(IForwardCommandFuture.Type.UPDATETIMER); ia.waitForDelay(w, this, realtime); } return IFuture.DONE; } };
/** * Get the result - blocking call. * @param timeout The timeout in millis. * @return The future result. */ public E get(long timeout) { // Default for realtime is false because normally waits should // use the kind of wait of the internal clock. Outbound calls // might use explicitly realtime to avoid immediate simulation timeouts. return get(timeout, false); }