/** * Creates an {@link CounterResultListener}. * * @param num The number of sub callbacks. * @param countReachedListener Listener to be called when the given number is reached. * @param intermediateListener Listener to be called for intermediate Results. * @param exListener Listener to be called for exceptions. * @return {@link CounterResultListener} */ public static <E> CounterResultListener<E> countResults(int num, IFunctionalResultListener<Void> countReachedListener, IFunctionalResultListener<E> intermediateListener, IFunctionalExceptionListener exListener) { return new CounterResultListener<E>(num, countReachedListener, intermediateListener, exListener); }
/** * Creates an {@link CounterResultListener}. * * @param num The number of sub callbacks. * @param countReachedListener Listener to be called when the given number is reached. * @return {@link CounterResultListener} */ public static <E> CounterResultListener<E> countResults(int num, IFunctionalResultListener<Void> countReachedListener) { return new CounterResultListener<E>(num, countReachedListener); }
/** * Creates an {@link CounterResultListener}. * * @param num The number of sub callbacks. * @param countReachedListener Listener to be called when the given number is reached. * @param exListener Listener to be called for exceptions. * @return {@link CounterResultListener} */ public static <E> CounterResultListener<E> countResults(int num, IFunctionalResultListener<Void> countReachedListener, IFunctionalExceptionListener exListener) { return new CounterResultListener<E>(num, countReachedListener, exListener); }
/** * Shutdown the plugin. */ public IFuture<Void> shutdown() { final Future<Void> ret = new Future<Void>(); comptree.dispose(); CounterResultListener<Void> lis = new CounterResultListener<Void>(msgservices.values().size(), true, new SwingDelegationResultListener<Void>(ret)); for(Iterator it=msgservices.values().iterator(); it.hasNext(); ) { Object[] entry = (Object[])it.next(); ((IMessageService)entry[0]).removeMessageListener(listener).addResultListener(lis); } return ret; }
/** * Shutdown the plugin. */ public IFuture<Void> shutdown() { final Future<Void> ret = new Future<Void>(); comptree.dispose(); CounterResultListener<Void> lis = new CounterResultListener<Void>(panels.size(), true, new SwingDelegationResultListener<Void>(ret)); for(Iterator<IAbstractViewerPanel> it=panels.values().iterator(); it.hasNext(); ) { it.next().shutdown().addResultListener(lis); } return ret; }
public void customResultAvailable(Properties mprops) { props = mprops; final CounterResultListener<Void> crl = new CounterResultListener<Void>(providers.size(), access.createResultListener(new DelegationResultListener<Void>(ret))); for(Iterator<String> it=providers.keySet().iterator(); it.hasNext(); ) { final String id = it.next(); IPropertiesProvider provider = providers.get(id); Properties sub = props.getSubproperty(id); if(sub!=null) { provider.setProperties(sub).addResultListener(access.createResultListener(crl)); } else { crl.resultAvailable(null); } } } });
public void customResultAvailable(Void result) { adapter = null; cms = null; instance = null; // Shudown the required service property providers if(reqserprops!=null && reqserprops.size()>0) { CounterResultListener<Void> lis = new CounterResultListener<Void>(reqserprops.size(), new DelegationResultListener<Void>(ret)); for(INFMixedPropertyProvider pp: reqserprops.values()) { pp.shutdownNFPropertyProvider().addResultListener(lis); } } else { super.customResultAvailable(result); } } });
/** * Fires a types added event. * @param types The types added. * @return Null, when done. */ public IFuture fireTypesAdded(String[] types) { final Future ret = new Future(); IMultiKernelListener[] ls = (IMultiKernelListener[]) listeners.toArray(new IMultiKernelListener[listeners.size()]); IResultListener counter = ia.createResultListener(new CounterResultListener(ls.length, true, ia.createResultListener(new DelegationResultListener(ret)))); for (int i = 0; i < ls.length; ++i) ls[i].componentTypesAdded(types).addResultListener(counter); return ret; }
/** * Fires a types removed event. * @param types The types removed. * @return Null, when done. */ public IFuture fireTypesRemoved(String[] types) { final Future ret = new Future(); IMultiKernelListener[] ls = (IMultiKernelListener[]) listeners.toArray(new IMultiKernelListener[listeners.size()]); IResultListener counter = ia.createResultListener(new CounterResultListener(ls.length, true, ia.createResultListener(new DelegationResultListener(ret)))); for (int i = 0; i < ls.length; ++i) ls[i].componentTypesAdded(types).addResultListener(counter); return ret; }
public void customResultAvailable(Properties mprops) { props = mprops; final CounterResultListener<Void> crl = new CounterResultListener<Void>(providers.size(), access.getComponentFeature(IExecutionFeature.class).createResultListener(new DelegationResultListener<Void>(ret))); for(Iterator<String> it=providers.keySet().iterator(); it.hasNext(); ) { final String id = it.next(); IPropertiesProvider provider = providers.get(id); Properties sub = props.getSubproperty(id); if(sub!=null) { provider.setProperties(sub).addResultListener(access.getComponentFeature(IExecutionFeature.class).createResultListener(crl)); } else { crl.resultAvailable(null); } } } });
/** * Shutdown the provider. */ public IFuture<Void> shutdownNFPropertyProvider() { Future<Void> ret = new Future<Void>(); if(nfproperties!=null) { CounterResultListener<Void> lis = new CounterResultListener<Void>(nfproperties.size(), true, new DelegationResultListener<Void>(ret)); for(INFProperty<?, ?> prop: nfproperties.values()) { prop.dispose().addResultListener(lis); } } else { ret.setResult(null); } return ret; }
/** * Set properties loaded from project. */ public IFuture<Void> setProperties(Properties ps) { Future<Void> ret = new Future<Void>(); this.props = ps; IAbstractViewerPanel[] pans = (IAbstractViewerPanel[])panels.values().toArray(new IAbstractViewerPanel[0]); CounterResultListener<Void> lis = new CounterResultListener<Void>(pans.length, true, new SwingDelegationResultListener<Void>(ret)); for(int i=0; i<pans.length; i++) { Properties sub = props!=null? props.getSubproperty(pans[i].getId()): null; pans[i].setProperties(sub).addResultListener(lis); } return ret; }
/** * Shutdown the provider. */ public IFuture<Void> shutdownNFPropertyProvider() { Future<Void> ret = new Future<Void>(); if(nfproperties!=null) { CounterResultListener<Void> lis = new CounterResultListener<Void>(nfproperties.size(), true, new DelegationResultListener<Void>(ret)); for(INFProperty<?, ?> prop: nfproperties.values()) { prop.dispose().addResultListener(lis); } } else { ret.setResult(null); } return ret; }
/** * Wait for all added futures being finished. */ public IFuture<Void> waitFor() { Future<Void> ret = new Future<Void>(); if(futures!=null) { CounterResultListener<E> lis = new CounterResultListener<E>(futures.size(), new DelegationResultListener<Void>(ret)); for(IFuture<E> fut: futures) { fut.addResultListener(lis); } } else { ret.setResult(null); } return ret; }
/** * Terminate all extensions. */ public IFuture<Void> terminateExtensions() { // Hack!!! When init fails , terminateExtensions() can not be called on component thread // as component already terminated. assert !getComponentAdapter().isExternalThread() || IComponentDescription.STATE_TERMINATED.equals(getComponentDescription().getState()); Future<Void> ret = new Future<Void>(); IExtensionInstance[] exts = getExtensions(); CounterResultListener<Void> lis = new CounterResultListener<Void>(exts.length, false, new DelegationResultListener<Void>(ret)); for(int i=0; i<exts.length; i++) { exts[i].terminate().addResultListener(lis); } return ret; }
/** * */ public void body() { Future<Void> ret = new Future<Void>(); int target = ((Integer)getBeliefbase().getBelief("target").getFact()).intValue(); int money = ((Integer)getBeliefbase().getBelief("money").getFact()).intValue(); // Create a subgoal for each euro to get CounterResultListener<Void> lis = new CounterResultListener<Void>(target-money, new DelegationResultListener<Void>(ret)); for(int i=0; i<target-money; i++) { createOneEuroSubgoal().addResultListener(lis); } ret.get(); // waitForEver(); }
final IResultListener<Void> lis = new CounterResultListener<Void>(infos.length, new DelegationResultListener<Void>(ret));
/** * Add nf properties from a type. */ public IFuture<Void> addNFProperties(NFProperties nfprops, IService ser) { Future<Void> ret = new Future<Void>(); INFMixedPropertyProvider prov = getProvidedServicePropertyProvider(ser.getServiceIdentifier()); CounterResultListener<Void> lis = new CounterResultListener<Void>(nfprops.value().length, new DelegationResultListener<Void>(ret)); for(NFProperty nfprop : nfprops.value()) { Class<?> clazz = nfprop.value(); INFProperty<?, ?> prop = AbstractNFProperty.createProperty(clazz, getComponent(), ser, null, SNameValue.createUnparsedExpressionsList(nfprop.parameters())); prov.addNFProperty(prop).addResultListener(lis); } return ret; }
/** * Add nf properties from a type. */ public IFuture<Void> addNFMethodProperties(NFProperties nfprops, IService ser, MethodInfo mi) { Future<Void> ret = new Future<Void>(); INFMixedPropertyProvider prov = getProvidedServicePropertyProvider(ser.getServiceIdentifier()); CounterResultListener<Void> lis = new CounterResultListener<Void>(nfprops.value().length, new DelegationResultListener<Void>(ret)); for(NFProperty nfprop : nfprops.value()) { Class<?> clazz = ((NFProperty)nfprop).value(); INFProperty<?, ?> prop = AbstractNFProperty.createProperty(clazz, getComponent(), ser, mi, SNameValue.createUnparsedExpressionsList(nfprop.parameters())); prov.addMethodNFProperty(mi, prop).addResultListener(lis); } return ret; }
public void body() { IComponentManagementService cms = getAgent().getComponentFeature(IRequiredServicesFeature.class) .searchService(IComponentManagementService.class, RequiredServiceInfo.SCOPE_PLATFORM).get(); Environment en = (Environment)getBeliefbase().getBelief("environment").getFact(); Creature[] creatures = en.getCreatures(); Future<Void> destroyed = new Future<Void>(); IResultListener<Map<String, Object>> lis = new CounterResultListener<Map<String, Object>>(creatures.length, new DelegationResultListener<Void>(destroyed)); for(int i = 0; i < creatures.length; i++) { // System.out.println(creatures[i].getAID()); en.removeCreature(creatures[i]); cms.destroyComponent(creatures[i].getAID()).addResultListener(lis); } destroyed.get(); cms.destroyComponent(getScope().getComponentIdentifier().getParent()); } }