当前位置: 首页>>代码示例>>Java>>正文


Java ICompletableFuture类代码示例

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


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


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