• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java ICompletableFuture类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.hazelcast.core.ICompletableFuture的典型用法代码示例。如果您正苦于以下问题:Java ICompletableFuture类的具体用法?Java ICompletableFuture怎么用?Java ICompletableFuture使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



ICompletableFuture类属于com.hazelcast.core包,在下文中一共展示了ICompletableFuture类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: putAll

import com.hazelcast.core.ICompletableFuture; //导入依赖的package包/类
@Nonnull
@Override
public Map<K, List<M>> putAll(@Nonnull Map<K, List<M>> values) {
    Map<K, ICompletableFuture<List<M>>> futureMap = new HashMap<>();
    values.forEach((key, message) -> futureMap.put(key, hazelcastMap.putAsync(key, message)));
    Map<K, List<M>> ret = new HashMap<>();
    futureMap.forEach((key, future) -> {
        try {
            List<M> value = future.get();
            if (value != null) {
                ret.put(key, value);
            }
        } catch (ExecutionException | InterruptedException e) {
            // TODO: Figure out if we timed out or were interrupted...
            throw new RuntimeException(e.getMessage(), e);
        }
    });
    return ret;
}
 
开发者ID:morimekta,项目名称:providence,代码行数:20,代码来源:HazelcastMessageListStorage.java


示例2: removeAll

import com.hazelcast.core.ICompletableFuture; //导入依赖的package包/类
@Nonnull
@Override
public Map<K, List<M>> removeAll(Collection<K> keys) {
    Map<K, ICompletableFuture<List<M>>> futureMap = new HashMap<>();
    keys.forEach(key -> futureMap.put(key, hazelcastMap.removeAsync(key)));
    Map<K, List<M>> ret = new HashMap<>();
    futureMap.forEach((key, future) -> {
        try {
            List<M> value = future.get();
            if (value != null) {
                ret.put(key, value);
            }
        } catch (ExecutionException | InterruptedException e) {
            // TODO: Figure out if we timed out or were interrupted...
            throw new RuntimeException(e.getMessage(), e);
        }

    });
    return ret;
}
 
开发者ID:morimekta,项目名称:providence,代码行数:21,代码来源:HazelcastMessageListStorage.java


示例3: putAllBuilders

import com.hazelcast.core.ICompletableFuture; //导入依赖的package包/类
@Nonnull
@Override
@SuppressWarnings("unchecked")
public <B extends PMessageBuilder<Message, Field>> Map<Key, B> putAllBuilders(@Nonnull Map<Key, B> builders) {
    Map<Key, ICompletableFuture<Builder>> futureMap = new HashMap<>();
    builders.forEach((key, builder) -> futureMap.put(key, hazelcastMap.putAsync(key, (Builder) builder)));
    Map<Key, B> ret = new HashMap<>();
    futureMap.forEach((key, future) -> {
        try {
            Builder value = future.get();
            if (value != null) {
                ret.put(key, (B) value);
            }
        } catch (ExecutionException | InterruptedException e) {
            // TODO: Figure out if we timed out or were interrupted...
            throw new RuntimeException(e.getMessage(), e);
        }

    });
    return ret;
}
 
开发者ID:morimekta,项目名称:providence,代码行数:22,代码来源:HazelcastMessageBuilderStorage.java


示例4: removeAll

import com.hazelcast.core.ICompletableFuture; //导入依赖的package包/类
@Nonnull
@Override
public Map<Key, Message> removeAll(Collection<Key> keys) {
    Map<Key, ICompletableFuture<Builder>> futureMap = new HashMap<>();
    keys.forEach(key -> futureMap.put(key, hazelcastMap.removeAsync(key)));
    Map<Key, Message> ret = new HashMap<>();
    futureMap.forEach((key, builder) -> {
        try {
            Builder value = builder.get();
            if (value != null) {
                ret.put(key, value.build());
            }
        } catch (ExecutionException | InterruptedException e) {
            // TODO: Figure out if we timed out or were interrupted...
            throw new RuntimeException(e.getMessage(), e);
        }
    });
    return ret;
}
 
开发者ID:morimekta,项目名称:providence,代码行数:20,代码来源:HazelcastMessageBuilderStorage.java


示例5: putAll

import com.hazelcast.core.ICompletableFuture; //导入依赖的package包/类
@Nonnull
@Override
public Map<Key, Message> putAll(@Nonnull Map<Key, Message> values) {
    Map<Key, ICompletableFuture<Message>> futureMap = new HashMap<>();
    values.forEach((key, message) -> futureMap.put(key, hazelcastMap.putAsync(key, message)));
    Map<Key, Message> ret = new HashMap<>();
    futureMap.forEach((key, future) -> {
        try {
            Message value = future.get();
            if (value != null) {
                ret.put(key, value);
            }
        } catch (ExecutionException | InterruptedException e) {
            // TODO: Figure out if we timed out or were interrupted...
            throw new RuntimeException(e.getMessage(), e);
        }
    });
    return ret;
}
 
开发者ID:morimekta,项目名称:providence,代码行数:20,代码来源:HazelcastMessageStorage.java


示例6: removeAll

import com.hazelcast.core.ICompletableFuture; //导入依赖的package包/类
@Nonnull
@Override
public Map<Key, Message> removeAll(Collection<Key> keys) {
    Map<Key, ICompletableFuture<Message>> futureMap = new HashMap<>();
    keys.forEach(key -> futureMap.put(key, hazelcastMap.removeAsync(key)));
    Map<Key, Message> ret = new HashMap<>();
    futureMap.forEach((key, future) -> {
        try {
            Message value = future.get();
            if (value != null) {
                ret.put(key, value);
            }
        } catch (ExecutionException | InterruptedException e) {
            // TODO: Figure out if we timed out or were interrupted...
            throw new RuntimeException(e.getMessage(), e);
        }
    });
    return ret;
}
 
开发者ID:morimekta,项目名称:providence,代码行数:20,代码来源:HazelcastMessageStorage.java


示例7: execute

import com.hazelcast.core.ICompletableFuture; //导入依赖的package包/类
@Override
public void execute(HazelcastInstance hazelcastInstance)
        throws Exception {

    JobTracker jobTracker = hazelcastInstance.getJobTracker("default");

    IList<Person> list = hazelcastInstance.getList("persons");
    KeyValueSource<String, Person> source = KeyValueSource.fromList(list);

    Job<String, Person> job = jobTracker.newJob(source);

    ICompletableFuture future = job.mapper(new SalaryMapper()) //
            .combiner(new SalaryCombinerFactory()) //
            .reducer(new SalaryReducerFactory()) //
            .submit();

    System.out.println(ToStringPrettyfier.toString(future.get()));
}
 
开发者ID:noctarius,项目名称:hazelcast-mapreduce-presentation,代码行数:19,代码来源:Tutorial4.java


示例8: execute

import com.hazelcast.core.ICompletableFuture; //导入依赖的package包/类
@Override
public void execute(HazelcastInstance hazelcastInstance)
        throws Exception {

    JobTracker jobTracker = hazelcastInstance.getJobTracker("default");

    IList<Person> list = hazelcastInstance.getList("persons");
    KeyValueSource<String, Person> source = KeyValueSource.fromList(list);

    Job<String, Person> job = jobTracker.newJob(source);

    // Collect all people by state
    ICompletableFuture future = job.mapper(new StateBasedCountMapper()).submit();

    // Count people by state
    // ICompletableFuture future = job.mapper(new StateBasedCountMapper()).reducer(new CountReducerFactory()).submit();

    // Same as above but with precalculation per node
    // ICompletableFuture future = job.mapper(new StateBasedCountMapper()).combiner(new CountCombinerFactory())
    //                                .reducer(new CountReducerFactory()).submit();

    System.out.println(ToStringPrettyfier.toString(future.get()));
}
 
开发者ID:noctarius,项目名称:hazelcast-mapreduce-presentation,代码行数:24,代码来源:Tutorial3.java


示例9: submitToPartitionOwner

import com.hazelcast.core.ICompletableFuture; //导入依赖的package包/类
private <T> ScheduledFuture<T> submitToPartitionOwner(Callable<T> task, int partitionId, long delay, long period, boolean fixedRate) {
        if (task == null) {
            throw new NullPointerException("task can't be null");
        }
        if (isShutdown()) {
            throw new RejectedExecutionException(getRejectionMessage());
        }
        NodeEngine nodeEngine = getNodeEngine();
        Data taskData = nodeEngine.toData(task);
        String uuid = buildRandomUuidString();
        String name = getName();
        ScheduledCallableTaskOperation op = new ScheduledCallableTaskOperation(name, uuid, taskData, delay, period, fixedRate);
        ICompletableFuture future = invoke(partitionId, op);
        return new ScheduledDelegatingFuture<T>(future, nodeEngine.getSerializationService(), delay);
//        return new CancellableDelegatingFuture<T>(future, nodeEngine, uuid, partitionId);
    }
 
开发者ID:gurbuzali,项目名称:scheduled-executor,代码行数:17,代码来源:ScheduledExecutorProxy.java


示例10: mapReduce

import com.hazelcast.core.ICompletableFuture; //导入依赖的package包/类
private static Map<String, Long> mapReduce(HazelcastInstance hazelcastInstance)
        throws Exception {

    // Retrieving the JobTracker by name
    JobTracker jobTracker = hazelcastInstance.getJobTracker("default");

    // Creating the KeyValueSource for a Hazelcast IMap
    IMap<String, String> map = hazelcastInstance.getMap("articles");
    KeyValueSource<String, String> source = KeyValueSource.fromMap(map);

    Job<String, String> job = jobTracker.newJob(source);

    // Creating a new Job
    ICompletableFuture<Map<String, Long>> future = job // returned future
            .mapper(new TokenizerMapper())             // adding a mapper
            .combiner(new WordCountCombinerFactory())  // adding a combiner through the factory
            .reducer(new WordCountReducerFactory())    // adding a reducer through the factory
            .submit();                                 // submit the task

    // Attach a callback listener
    future.andThen(buildCallback());

    // Wait and retrieve the result
    return future.get();
}
 
开发者ID:noctarius,项目名称:hz-map-reduce,代码行数:26,代码来源:MapReduceDemo.java


示例11: mapReduceCollate

import com.hazelcast.core.ICompletableFuture; //导入依赖的package包/类
private static long mapReduceCollate(HazelcastInstance hazelcastInstance)
        throws Exception {

    // Retrieving the JobTracker by name
    JobTracker jobTracker = hazelcastInstance.getJobTracker("default");

    // Creating the KeyValueSource for a Hazelcast IMap
    IMap<String, String> map = hazelcastInstance.getMap("articles");
    KeyValueSource<String, String> source = KeyValueSource.fromMap(map);

    // Creating a new Job
    Job<String, String> job = jobTracker.newJob(source);

    ICompletableFuture<Long> future = job // returned future
            .mapper(new TokenizerMapper())             // adding a mapper
            .combiner(new WordCountCombinerFactory())  // adding a combiner through the factory
            .reducer(new WordCountReducerFactory())    // adding a reducer through the factory
            .submit(new WordCountCollator());          // submit the task and supply a collator

    // Wait and retrieve the result
    return future.get();
}
 
开发者ID:noctarius,项目名称:hz-map-reduce,代码行数:23,代码来源:MapReduceDemo.java


示例12: add

import com.hazelcast.core.ICompletableFuture; //导入依赖的package包/类
void add(ICompletableFuture<Long> future) {
    if (batchSize <= 0) {
        return;
    }

    batch.add(future);
    if (batch.size() == batchSize) {
        for (ICompletableFuture batchFuture : batch) {
            try {
                batchFuture.get();
            } catch (Exception e) {
                throw rethrow(e);
            }
        }
        batch.clear();
    }
}
 
开发者ID:hazelcast,项目名称:hazelcast-simulator,代码行数:18,代码来源:AsyncAtomicLongTest.java


示例13: pushEntry

import com.hazelcast.core.ICompletableFuture; //导入依赖的package包/类
@Override
@SuppressWarnings("unchecked")
public void pushEntry(K key, V value) {
    if (storedException.get() != null) {
        throw new RuntimeException("Aborting pushEntry; problems are detected. Please check the cause",
                storedException.get());
    }

    acquirePermit(1);
    try {
        ICompletableFuture<V> future = storeAsync(key, value);
        future.andThen(callback);
    } catch (Exception e) {
        releasePermit(1);

        throw rethrow(e);
    }
}
 
开发者ID:hazelcast,项目名称:hazelcast-simulator,代码行数:19,代码来源:AbstractAsyncStreamer.java


示例14: init

import com.hazelcast.core.ICompletableFuture; //导入依赖的package包/类
@Override
protected void init(@Nonnull Context context) throws Exception {
    ICompletableFuture<EventJournalInitialSubscriberState>[] futures = new ICompletableFuture[partitionIds.length];
    Arrays.setAll(futures, i -> eventJournalReader.subscribeToEventJournal(partitionIds[i]));
    for (int i = 0; i < futures.length; i++) {
        emitOffsets[i] = readOffsets[i] = getSequence(futures[i].get());
    }
}
 
开发者ID:hazelcast,项目名称:hazelcast-jet,代码行数:9,代码来源:StreamEventJournalP.java


示例15: invoke

import com.hazelcast.core.ICompletableFuture; //导入依赖的package包/类
@Nonnull
@Override
public ICompletableFuture<ClientMessage> invoke(@Nonnegative int partitionId, @Nonnull ClientMessage request) {
    try {
        ClientInvocation clientInvocation = new ClientInvocation(client, request, partitionId);
        return clientInvocation.invoke();

    } catch (Exception e) {
        throw ExceptionUtil.rethrow(e);
    }
}
 
开发者ID:noctarius,项目名称:snowcast,代码行数:12,代码来源:Hazelcast37ClientInvocator.java


示例16: execute

import com.hazelcast.core.ICompletableFuture; //导入依赖的package包/类
@Override
public void execute(HazelcastInstance hazelcastInstance)
        throws Exception {

    JobTracker jobTracker = hazelcastInstance.getJobTracker("default");

    IList<Person> list = hazelcastInstance.getList("persons");
    KeyValueSource<String, Person> source = KeyValueSource.fromList(list);

    Job<String, Person> job = jobTracker.newJob(source);

    ICompletableFuture<List<Map.Entry<String, Integer>>> future = //
            job.mapper(new SalaryMapper()) //
                    .combiner(new SalaryCombinerFactory()) //
                    .reducer(new SalaryReducerFactory()) //
                    .submit(new SalaryCollator());

    // Intermediate result
    List<Map.Entry<String, Integer>> orderedSalariesByState = future.get();
    Map.Entry<String, Integer> topSalary = orderedSalariesByState.get(0);

    IList<Crime> crimesList = hazelcastInstance.getList("crimes");
    KeyValueSource<String, Crime> crimeSource = KeyValueSource.fromList(crimesList);

    Job<String, Crime> crimeJob = jobTracker.newJob(crimeSource);

    ICompletableFuture<Map<CrimeCategory, Integer>> crimeFuture = //
            crimeJob.mapper(new CrimeMapper(topSalary.getKey())) //
                    .reducer(new CrimeReducerFactory()) //
                    .submit();

    System.out.println(ToStringPrettyfier.toString(crimeFuture.get()));
}
 
开发者ID:noctarius,项目名称:hazelcast-mapreduce-presentation,代码行数:34,代码来源:Tutorial5.java


示例17: main

import com.hazelcast.core.ICompletableFuture; //导入依赖的package包/类
public static void main(String[] args)
        throws Exception {

    // Prepare Hazelcast cluster
    HazelcastInstance hazelcastInstance = buildCluster(3);

    try {

        // Read data
        fillMapWithData(hazelcastInstance);

        JobTracker tracker = hazelcastInstance.getJobTracker("default");

        IMap<String, String> map = hazelcastInstance.getMap(MAP_NAME);
        KeyValueSource<String, String> source = KeyValueSource.fromMap(map);

        Job<String, String> job = tracker.newJob(source);
        ICompletableFuture<Map<String, Integer>> future = job
                .mapper(new TokenizerMapper())
                // Activate Combiner to add combining phase!
                // .combiner(new WordcountCombinerFactory())
                .reducer(new WordcountReducerFactory())
                .submit();



        System.out.println(ToStringPrettyfier.toString(future.get()));

    } finally {
        // Shutdown cluster
        Hazelcast.shutdownAll();
    }
}
 
开发者ID:noctarius,项目名称:hazelcast-mapreduce-presentation,代码行数:34,代码来源:WordCount.java


示例18: doMapReduce

import com.hazelcast.core.ICompletableFuture; //导入依赖的package包/类
private static void doMapReduce(
        final HazelcastInstance instance,
        final String filename) throws ExecutionException, InterruptedException, IOException
{
    final IMap<Integer, SpatialPoint> geomap = instance.getMap(GEOMAP);
    final JobTracker tracker = instance.getJobTracker("default");
    final Job<Integer, SpatialPoint> job = tracker.newJob(KeyValueSource.fromMap(geomap));
    final ICompletableFuture<Map<Integer, Integer>> future = job.
            mapper(new FeatureMapper(HEXMAP)).
            reducer(new FeatureReducerFactory()).
            submit();

    final FileOutputStream fileOutputStream = new FileOutputStream(filename);
    try
    {
        final PrintStream printStream = new PrintStream(fileOutputStream);
        printStream.format("ID,POPULATION%n");
        final Map<Integer, Integer> result = future.get();
        for (final Map.Entry<Integer, Integer> entry : result.entrySet())
        {
            printStream.format("%d,%d%n", entry.getKey(), entry.getValue());
        }
        printStream.flush();
    }
    finally
    {
        fileOutputStream.close();
    }
}
 
开发者ID:mraad,项目名称:HZSpatial,代码行数:30,代码来源:Main.java


示例19: executeAsync

import com.hazelcast.core.ICompletableFuture; //导入依赖的package包/类
private <T> void executeAsync(ICompletableFuture<T> future,
                              Handler<AsyncResult<T>> resultHandler) {
    future.andThen(
            new HandlerCallBackAdapter(resultHandler),
            VertxExecutorAdapter.getOrCreate(vertx.getOrCreateContext())
    );
}
 
开发者ID:vert-x3,项目名称:vertx-hazelcast,代码行数:8,代码来源:HazelcastInternalAsyncCounter.java


示例20: put

import com.hazelcast.core.ICompletableFuture; //导入依赖的package包/类
@Override
public void put(K k, V v, long ttl, Handler<AsyncResult<Void>> completionHandler) {
  K kk = convertParam(k);
  V vv = convertParam(v);
  executeAsyncVoid(
          (ICompletableFuture<Void>) map.putAsync(kk, vv, ttl, TimeUnit.MILLISECONDS),
          completionHandler
  );
}
 
开发者ID:vert-x3,项目名称:vertx-hazelcast,代码行数:10,代码来源:HazelcastInternalAsyncMap.java



注:本文中的com.hazelcast.core.ICompletableFuture类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java RefactoredDefaultItemAnimator类代码示例发布时间:2022-05-22
下一篇:
Java TerrainQuad类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap