本文整理汇总了Java中com.hazelcast.core.IList类的典型用法代码示例。如果您正苦于以下问题:Java IList类的具体用法?Java IList怎么用?Java IList使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
IList类属于com.hazelcast.core包,在下文中一共展示了IList类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: toArray
import com.hazelcast.core.IList; //导入依赖的package包/类
@Override
public double[] toArray() {
IList<Double> list = inner.collect(DistributedCollectors.toIList(uniqueListName()));
try {
double[] array = new double[list.size()];
int index = 0;
for (Double d : list) {
array[index++] = d;
}
return array;
} finally {
list.destroy();
}
}
示例2: buildDAG
import com.hazelcast.core.IList; //导入依赖的package包/类
@Override
public Vertex buildDAG(DAG dag) {
String listName = uniqueListName();
IList<T> list = context.getJetInstance().getList(listName);
Vertex previous = upstream.buildDAG(dag);
Vertex writer = dag.newVertex("write-list-" + listName, SinkProcessors.writeListP(listName));
if (upstream.isOrdered()) {
writer.localParallelism(1);
}
dag.edge(from(previous, 1).to(writer, 0));
context.addStreamListener(() -> {
list.forEach(consumer);
list.destroy();
});
return previous;
}
示例3: reduce
import com.hazelcast.core.IList; //导入依赖的package包/类
@Override
public Boolean reduce(StreamContext context, Pipe<? extends T> upstream) {
String listName = uniqueListName();
DAG dag = new DAG();
Vertex previous = upstream.buildDAG(dag);
Vertex anyMatch = dag.newVertex("any-match", () -> new AnyMatchP<>(predicate));
Vertex writer = dag.newVertex("write-" + listName, SinkProcessors.writeListP(listName));
dag.edge(between(previous, anyMatch))
.edge(between(anyMatch, writer));
executeJob(context, dag);
IList<Boolean> results = context.getJetInstance().getList(listName);
boolean result = anyMatch(results);
results.destroy();
return result;
}
示例4: writeListP
import com.hazelcast.core.IList; //导入依赖的package包/类
@Nonnull
public static ProcessorMetaSupplier writeListP(@Nonnull String name, @Nullable ClientConfig clientConfig) {
boolean isLocal = clientConfig == null;
return dontParallelize(new HazelcastWriterSupplier<>(
serializableConfig(clientConfig),
index -> new ArrayList<>(),
ArrayList::add,
instance -> {
IList<Object> list = instance.getList(name);
return buffer -> {
try {
list.addAll(buffer);
} catch (HazelcastInstanceNotActiveException e) {
handleInstanceNotActive(instance, e, isLocal);
}
buffer.clear();
};
},
noopConsumer()
));
}
示例5: ilistCollect_whenSourceMap
import com.hazelcast.core.IList; //导入依赖的package包/类
@Test
public void ilistCollect_whenSourceMap() throws Exception {
IStreamMap<String, Integer> map = getMap();
fillMap(map);
IList<Entry<String, Integer>> collected = map.stream().collect(toIList(randomString()));
Entry<String, Integer>[] expecteds = map.entrySet().toArray(new Entry[0]);
Entry<String, Integer>[] actuals = collected.toArray(new Entry[0]);
Comparator<Entry<String, Integer>> entryComparator = Comparator.comparing(Entry::getKey);
Arrays.sort(expecteds, entryComparator);
Arrays.sort(actuals, entryComparator);
assertArrayEquals(expecteds, actuals);
}
示例6: ilistCollect_whenSourceCache
import com.hazelcast.core.IList; //导入依赖的package包/类
@Test
public void ilistCollect_whenSourceCache() throws Exception {
IStreamCache<String, Integer> cache = getCache();
fillCache(cache);
IList<Entry<String, Integer>> collected = cache.stream().collect(toIList(randomString()));
Cache.Entry<String, Integer>[] expecteds = new Cache.Entry[cache.size()];
int count = 0;
for (Cache.Entry<String, Integer> entry : cache) {
expecteds[count++] = entry;
}
Map.Entry<String, Integer>[] actuals = collected.toArray(new Map.Entry[0]);
Arrays.sort(expecteds, Comparator.comparing(Cache.Entry::getKey));
Arrays.sort(actuals, Comparator.comparing(Map.Entry::getKey));
assertEquals(expecteds.length, actuals.length);
for (int i = 0; i < expecteds.length; i++) {
assertEquals(expecteds[i].getKey(), actuals[i].getKey());
assertEquals(expecteds[i].getValue(), actuals[i].getValue());
}
}
示例7: sourceList
import com.hazelcast.core.IList; //导入依赖的package包/类
@Test
public void sourceList() throws InterruptedException {
IStreamList<Integer> list = getList();
fillList(list);
IList<Integer> result = list
.stream()
.filter(f -> f < 100)
.collect(DistributedCollectors.toIList(randomString()));
assertEquals(100, result.size());
for (int i = 0; i < 100; i++) {
int val = result.get(i);
assertEquals(i, val);
}
}
示例8: sourceList
import com.hazelcast.core.IList; //导入依赖的package包/类
@Test
public void sourceList() {
IStreamList<Integer> list = getList();
int modulus = 10;
fillList(list, i -> i % modulus);
IList<Integer> result = list
.stream()
.distinct()
.collect(DistributedCollectors.toIList(randomString()));
assertEquals(modulus, result.size());
for (int i = 0; i < 10; i++) {
assertTrue(Integer.toString(i), result.contains(i));
}
}
示例9: testReadHdfs
import com.hazelcast.core.IList; //导入依赖的package包/类
@Test
public void testReadHdfs() {
DAG dag = new DAG();
Vertex source = dag.newVertex("source", readHdfsP(jobConf, mapperType.mapper))
.localParallelism(4);
Vertex sink = dag.newVertex("sink", writeListP("sink"))
.localParallelism(1);
dag.edge(between(source, sink));
Future<Void> future = instance.newJob(dag).getFuture();
assertCompletesEventually(future);
IList list = instance.getList("sink");
assertEquals(expectedSinkSize(), list.size());
assertTrue(list.get(0).toString().contains("value"));
}
示例10: execute
import com.hazelcast.core.IList; //导入依赖的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()));
}
示例11: execute
import com.hazelcast.core.IList; //导入依赖的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()));
}
示例12: addRemoveItemListener
import com.hazelcast.core.IList; //导入依赖的package包/类
@Test
@Ignore
public void addRemoveItemListener() throws InterruptedException {
HazelcastClient hClient = getHazelcastClient();
final IList<String> list = hClient.getList("addRemoveItemListenerList");
final CountDownLatch addLatch = new CountDownLatch(4);
final CountDownLatch removeLatch = new CountDownLatch(4);
ItemListener<String> listener = new CountDownItemListener<String>(addLatch, removeLatch);
list.addItemListener(listener, true);
list.add("hello");
list.add("hello");
list.remove("hello");
list.remove("hello");
list.removeItemListener(listener);
list.add("hello");
list.add("hello");
list.remove("hello");
list.remove("hello");
Thread.sleep(10);
assertEquals(2, addLatch.getCount());
assertEquals(2, removeLatch.getCount());
}
示例13: size
import com.hazelcast.core.IList; //导入依赖的package包/类
@Test
public void size() {
HazelcastClient hClient = getHazelcastClient();
IList<Integer> list = hClient.getList("size");
int count = 100;
assertTrue(list.isEmpty());
for (int i = 0; i < count; i++) {
assertTrue(list.add(i));
}
assertEquals(count, list.size());
for (int i = 0; i < count / 2; i++) {
assertTrue(list.add(i));
}
assertFalse(list.isEmpty());
assertEquals(count + count / 2, list.size());
}
示例14: remove
import com.hazelcast.core.IList; //导入依赖的package包/类
@Test
public void remove() {
HazelcastClient hClient = getHazelcastClient();
IList<Integer> list = hClient.getList("remove");
int count = 100;
assertTrue(list.isEmpty());
for (int i = 0; i < count; i++) {
assertTrue(list.add(i));
}
assertEquals(count, list.size());
for (int i = 0; i < count; i++) {
assertTrue(list.remove((Object) i));
}
assertTrue(list.isEmpty());
for (int i = count; i < 2 * count; i++) {
assertFalse(list.remove((Object) i));
}
}
示例15: iterate
import com.hazelcast.core.IList; //导入依赖的package包/类
@Test
public void iterate() {
HazelcastClient hClient = getHazelcastClient();
IList<Integer> list = hClient.getList("iterate");
list.add(1);
list.add(2);
list.add(2);
list.add(3);
assertEquals(4, list.size());
Map<Integer, Integer> counter = new HashMap<Integer, Integer>();
counter.put(1, 1);
counter.put(2, 2);
counter.put(3, 1);
for (Iterator<Integer> iterator = list.iterator(); iterator.hasNext(); ) {
Integer integer = iterator.next();
counter.put(integer, counter.get(integer) - 1);
iterator.remove();
}
assertEquals(Integer.valueOf(0), counter.get(1));
assertEquals(Integer.valueOf(0), counter.get(2));
assertEquals(Integer.valueOf(0), counter.get(3));
assertTrue(list.isEmpty());
}