/** * 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); }
/** * Create a new listener. */ public KillListener(IModelInfo model, String fullname, Future fut, Component parent) { super(parent); this.model = model; this.fullname = fullname; fut.addResultListener(new IResultListener() { public void resultAvailable(Object result) { cid = (IComponentIdentifier)result; } public void exceptionOccurred(Exception exception) { // handled in createComponent(...) // KillListener.this.exceptionOccurred(exception); } }); }
/** * Create a new listener. */ public KillListener(IModelInfo model, String fullname, Future fut, Component parent) { super(parent); this.model = model; this.fullname = fullname; fut.addResultListener(new IResultListener() { public void resultAvailable(Object result) { cid = (IComponentIdentifier)result; } public void exceptionOccurred(Exception exception) { // handled in createComponent(...) // KillListener.this.exceptionOccurred(exception); } }); }
/** * Add a result listener by combining an OnSuccessListener and an * OnExceptionListener. * * @param sucListener The listener that is called on success. * @param exListener The listener that is called on exceptions. Passing * <code>null</code> enables default exception logging. */ public void addResultListener(IFunctionalResultListener<E> sucListener, IFunctionalExceptionListener exListener) { addResultListener(SResultListener.createResultListener(sucListener, exListener)); }
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; }
public IFuture<Void> thenAccept(final Consumer<? super E> consumer, Class<?> futuretype) { final Future<Void> ret = getFuture(futuretype); this.addResultListener(new ExceptionDelegationResultListener<E, Void>(ret) { public void customResultAvailable(E result) { consumer.accept(result); ret.setResult(null); } }); return ret; }
public <T> IFuture<T> thenApply(final Function<? super E, ? extends T> function, Class<?> futuretype) { final Future<T> ret = getFuture(futuretype); this.addResultListener(new ExceptionDelegationResultListener<E, T>(ret) { public void customResultAvailable(E result) { T res = function.apply(result); ret.setResult(res); } }); return ret; }
public <U,V> IFuture<V> thenCombine(final IFuture<U> other, final BiFunction<? super E,? super U, ? extends V> function, Class<?> futuretype) { final Future<V> ret = getFuture(futuretype); this.addResultListener(new ExceptionDelegationResultListener<E, V>(ret) { public void customResultAvailable(final E e) { other.addResultListener(new ExceptionDelegationResultListener<U, V>(ret) { public void customResultAvailable(U u) { ret.setResult(function.apply(e, u)); } }); } }); return ret; }
/** * Add a listener * @param listener The listener. */ public void addResultListener(IResultListener<E> listener) { super.addResultListener(new BDIComponentResultListener<E>(listener, getAgent())); } }
/** * * @param listener */ public void addResultListener(IResultListener<E> listener) { super.addResultListener(new BDIComponentResultListener<E>(listener, (BDIAgentInterpreter)((BDIAgent)ia).getInterpreter())); } }
public void proceed() { // Only wait 2 secs for sending status before terminating the agent. done.addResultListener(new TimeoutResultListener<Void>(2000, agent.getExternalAccess(), new DelegationResultListener<Void>(ret) { public void exceptionOccurred(Exception exception) { super.resultAvailable(null); } })); } });
public void proceed() { // Only wait 2 secs for sending status before terminating the agent. done.addResultListener(new TimeoutResultListener<Void>(2000, agent.getExternalAccess(), new DelegationResultListener<Void>(ret) { public void exceptionOccurred(Exception exception) { super.resultAvailable(null); } })); } });
/** * Compensate in case the task is canceled. * @return To be notified, when the compensation has completed. */ public IFuture cancel(final IInternalAccess instance) { final Future ret = new Future(); creationFuture.addResultListener(instance.createResultListener(new IResultListener() { public void resultAvailable(Object result) { space.removeObjectTask(taskid, objectid); ret.setResult(null); } public void exceptionOccurred(Exception exception) { ret.setResult(null); } })); return ret; }
@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 customResultAvailable(IComponentManagementService cms) { final List<IComponentIdentifier> cids = new ArrayList<IComponentIdentifier>(); Future<Void> fut = new Future<Void>(); fut.addResultListener(new ExceptionDelegationResultListener<Void, IComponentIdentifier>(ret) { public void customResultAvailable(Void result) { if(cids.size()>0) { ret.setResult(cids.get(0)); } else { ret.setException(new RuntimeException("Component not created: "+component)); } } }); createComponent(new ComponentInstanceInfo[]{component}, cms, getModel(), 0, fut, cids); } }));
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; } });
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; } });
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; } });
/** * Send addRef to the origin process of the remote reference. * @param rr The remote reference. */ public Future<Void> sendAddRemoteReference(final RemoteReference rr) { checkThread(); // DGC: notify rr origin that a new proxy of target object exists // todo: handle failures! final Future<Void> ret = new Future<Void>(); // System.out.println("send add: "+rr); final String callid = SUtil.createUniqueId(rsms.getRMSComponentIdentifier().getLocalName()); RemoteDGCAddReferenceCommand com = new RemoteDGCAddReferenceCommand(rr, rsms.getRMSComponentIdentifier(), callid); Future<Object> fut = new Future<Object>(); fut.addResultListener(new ExceptionDelegationResultListener<Object, Void>(ret) { public void customResultAvailable(Object result) { ret.setResult(null); } }); rsms.sendMessage(rr.getRemoteManagementServiceIdentifier(), null, com, callid, BasicService.DEFAULT_REMOTE, fut, null); return ret; }
/** * Send addRef to the origin process of the remote reference. * @param rr The remote reference. */ public Future<Void> sendAddRemoteReference(final RemoteReference rr) { checkThread(); // DGC: notify rr origin that a new proxy of target object exists // todo: handle failures! final Future<Void> ret = new Future<Void>(); // System.out.println("send add: "+rr); final String callid = SUtil.createUniqueId(rsms.getRMSComponentIdentifier().getLocalName()); RemoteDGCAddReferenceCommand com = new RemoteDGCAddReferenceCommand(rr, rsms.getRMSComponentIdentifier(), callid); Future<Object> fut = new Future<Object>(); fut.addResultListener(new ExceptionDelegationResultListener<Object, Void>(ret) { public void customResultAvailable(Object result) { ret.setResult(null); } }); rsms.sendMessage(rr.getRemoteManagementServiceIdentifier(), null, com, callid, BasicService.getRemoteDefaultTimeout(), fut, null, null); return ret; }