Java Code Examples for org.apache.ignite.lang.IgniteFuture#listen()
The following examples show how to use
org.apache.ignite.lang.IgniteFuture#listen() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AsyncMapImpl.java From vertx-ignite with Apache License 2.0 | 6 votes |
/** * @param ttl Time to live in ms. */ private <T> Future<T> executeWithTtl(Function<IgniteCache<K, V>, IgniteFuture<T>> cacheOp, long ttl) { ContextInternal ctx = vertx.getOrCreateContext(); Promise<T> promise = ctx.promise(); IgniteCache<K, V> cache0 = ttl > 0 ? cache.withExpiryPolicy(new CreatedExpiryPolicy(new Duration(TimeUnit.MILLISECONDS, ttl))) : cache; IgniteFuture<T> future = cacheOp.apply(cache0); future.listen(fut -> { try { promise.complete(unmarshal(future.get())); } catch (IgniteException e) { promise.fail(new VertxException(e)); } }); return promise.future(); }
Example 2
Source File: PlatformDotNetEntityFrameworkCacheExtension.java From ignite with Apache License 2.0 | 6 votes |
/** * Starts the background cleanup of old cache entries. * * @param grid Grid. * @param metaCache Meta cache. * @param dataCacheName Data cache name. * @param currentVersions Current versions. */ private void startBackgroundCleanup(Ignite grid, final Cache<CleanupNodeId, UUID> metaCache, final String dataCacheName, final Map<String, EntryProcessorResult<Long>> currentVersions) { if (cleanupFlags.containsKey(dataCacheName)) return; // Current node already performs cleanup. if (!trySetGlobalCleanupFlag(grid, metaCache)) return; cleanupFlags.put(dataCacheName, true); final ClusterGroup dataNodes = grid.cluster().forDataNodes(dataCacheName); IgniteFuture f = grid.compute(dataNodes).broadcastAsync( new RemoveOldEntriesRunnable(dataCacheName, currentVersions)); f.listen(new CleanupCompletionListener(metaCache, dataCacheName)); }
Example 3
Source File: GridTestUtils.java From ignite with Apache License 2.0 | 6 votes |
/** {@inheritDoc} */ @Override public IgniteFuture<?> onDiscovery( int type, long topVer, ClusterNode node, Collection<ClusterNode> topSnapshot, @Nullable Map<Long, Collection<ClusterNode>> topHist, @Nullable DiscoverySpiCustomMessage spiCustomMsg ) { hook.beforeDiscovery(spiCustomMsg); IgniteFuture<?> fut = delegate.onDiscovery(type, topVer, node, topSnapshot, topHist, spiCustomMsg); fut.listen(f -> hook.afterDiscovery(spiCustomMsg)); return fut; }
Example 4
Source File: HelloIgniteAsyn.java From ignite-book-code-samples with GNU General Public License v3.0 | 5 votes |
public static void main(String[] args) { System.out.println("Hello Ignite Asynchronous!!"); // create a new instance of TCP Discovery SPI TcpDiscoverySpi spi = new TcpDiscoverySpi(); // create a new instance of tcp discovery multicast ip finder TcpDiscoveryMulticastIpFinder tcMp = new TcpDiscoveryMulticastIpFinder(); tcMp.setAddresses(Arrays.asList("localhost")); // change your IP address here // set the multi cast ip finder for spi spi.setIpFinder(tcMp); // create new ignite configuration IgniteConfiguration cfg = new IgniteConfiguration(); cfg.setClientMode(false); // set the discovery spi to ignite configuration cfg.setDiscoverySpi(spi); // Start ignite Ignite ignite = Ignition.start(cfg); // get or create cache IgniteCache<Integer, String> cache = ignite.getOrCreateCache("testCache"); // get an asynchronous cache IgniteCache<Integer, String> asynCache = cache.withAsync(); // put some cache elements for(int i = 1; i <= 100; i++){ cache.put(i, Integer.toString(i)); } String val = asynCache.withAsync().get(1); System.out.println("Non future call:" + val); IgniteFuture<String> igniteFuture = asynCache.future(); igniteFuture.listen(f-> System.out.println("Cache Value:" + f.get())); ignite.close(); }
Example 5
Source File: PlatformProcessorImpl.java From ignite with Apache License 2.0 | 5 votes |
/** {@inheritDoc} */ @Override public void onDisconnected(IgniteFuture<?> reconnectFut) throws IgniteCheckedException { platformCtx.gateway().onClientDisconnected(); // 1) onReconnected is called on all grid components. // 2) After all of grid components have completed their reconnection, reconnectFut is completed. reconnectFut.listen(new CI1<IgniteFuture<?>>() { @Override public void apply(IgniteFuture<?> future) { platformCtx.gateway().onClientReconnected(clusterRestarted); } }); }
Example 6
Source File: VisorCacheClearTask.java From ignite with Apache License 2.0 | 5 votes |
/** * @param fut Future to listen. * @return {@code true} If future was not completed and this job should holdCC. */ private boolean callAsync(IgniteFuture fut) { if (fut.isDone()) return false; jobCtx.holdcc(); fut.listen(lsnr); return true; }
Example 7
Source File: IgniteProxy.java From bucket4j with Apache License 2.0 | 5 votes |
private static <T> CompletableFuture<T> convertFuture(IgniteFuture<T> igniteFuture) { CompletableFuture<T> completableFuture = new CompletableFuture<>(); igniteFuture.listen((IgniteInClosure<IgniteFuture<T>>) completedIgniteFuture -> { try { completableFuture.complete(completedIgniteFuture.get()); } catch (Throwable t) { completableFuture.completeExceptionally(t); } }); return completableFuture; }
Example 8
Source File: GridTestMain.java From ignite with Apache License 2.0 | 4 votes |
/** * @throws Exception If failed. */ private static void colocateJobs() throws Exception { X.println("Collocating jobs..."); Ignite g = G.ignite(); final IgniteCache<GridTestKey, Long> cache = g.cache("partitioned"); final BlockingQueue<IgniteFuture> q = new ArrayBlockingQueue<>(400); long start = System.currentTimeMillis(); // Collocate computations and data. for (long i = 0; i < GridTestConstants.ENTRY_COUNT; i++) { final long key = i; final IgniteFuture<?> f = g.compute().affinityRunAsync("partitioned", GridTestKey.affinityKey(key), new IgniteRunnable() { // This code will execute on remote nodes by collocating keys with cached data. @Override public void run() { Long val = cache.localPeek(new GridTestKey(key), CachePeekMode.ONHEAP); if (val == null || val != key) throw new RuntimeException("Invalid value found [key=" + key + ", val=" + val + ']'); } }); q.put(f); f.listen(new CI1<IgniteFuture<?>>() { @Override public void apply(IgniteFuture<?> o) { q.poll(); } }); if (i % 10000 == 0) X.println("Executed jobs: " + i); } long end = System.currentTimeMillis(); X.println("Executed " + GridTestConstants.ENTRY_COUNT + " computations in " + (end - start) + "ms."); }
Example 9
Source File: DataGridCompute.java From spring-boot-ignite with Apache License 2.0 | 3 votes |
/** * @param jobs the list of jobs to be distributed into the data grid nodes from the master node * @param igniteReducer the ignite reducer which will be used to determine the reduction and collection logic * @param callback the callback to be invoked upon receiving the reduced final response * @param <R> generic response type from the jobs * @param <E> generic map reduced response type * @throws IgniteException * * a generic async map reduced call inside ignite compute grid */ public <R, E> void executeMapReduceFailFast(Collection<IgniteCallable<R>> jobs, IgniteReducer<R, E> igniteReducer, Consumer<E> callback) throws IgniteException { // you need to define your cluster group and if any defined in your data grid IgniteCompute igniteCompute = ignite.compute(ignite.cluster().forPredicate(clusterNode -> !clusterNode.isClient())); //execute the list of jobs in map reduce fashion and pass the custom reducer as well IgniteFuture<E> future=igniteCompute.callAsync(jobs, igniteReducer); // then async listen for the result to invoke your post call back future.listen(result -> callback.accept(result.get())); }