use of org.nustaq.kontraktor.Promise in project kontraktor by RuedigerMoeller.
the class DataClient method connect.
public IPromise connect(DataCfg config, TableSpaceActor[] shards, ServiceActor hostingService) {
this.config = config;
this.hostingService = hostingService;
this.shards = shards;
syncTableAccess = new HashMap();
tableSharding = new TableSpaceSharding(shards, key -> Math.abs(key.hashCode()) % shards.length);
tableSharding.init().await();
TableDescription[] schema = config.getSchema();
return all(schema.length, i -> {
Promise p = new Promise();
tableSharding.createOrLoadTable(schema[i]).then((r, e) -> {
if (r != null) {
syncTableAccess.put(schema[i].getName(), r);
}
p.complete(r, e);
});
return p;
});
}
use of org.nustaq.kontraktor.Promise in project kontraktor by RuedigerMoeller.
the class DataShard method init.
@Override
public IPromise init(ConnectableActor gravityConnectable, ServiceArgs options, boolean auto) /*ignored*/
{
IPromise p = new Promise();
try {
super.init(gravityConnectable, options, false).await();
initTableSpace();
registerAtGravity();
p.resolve();
} catch (Throwable t) {
p.reject(t);
}
return p;
}
use of org.nustaq.kontraktor.Promise in project kontraktor by RuedigerMoeller.
the class RxJava method remotingToJ8Streams.
@Test
public void remotingToJ8Streams() {
Observable<Integer> range = Observable.range(0, NUM_MSG / 4);
Publisher<Integer> pub = RxReactiveStreams.toPublisher(range);
KxReactiveStreams.get().asKxPublisher(pub).serve(new TCPNIOPublisher().port(3457));
RateMeasure rm = new RateMeasure("events");
Promise<Integer> finished = new Promise<>();
KxReactiveStreams.get().connect(Integer.class, new TCPConnectable().host("localhost").port(3457)).stream(stream -> {
long count = stream.map(i -> {
rm.count();
return i;
}).count();
finished.resolve((int) count);
});
Assert.assertTrue(finished.await(50000) == NUM_MSG / 4);
}
use of org.nustaq.kontraktor.Promise in project kontraktor by RuedigerMoeller.
the class RxJava method rxToIteratorTest.
@Test
public void rxToIteratorTest() {
Observable<Integer> range = Observable.range(0, NUM_MSG / 4);
Publisher<Integer> pub = RxReactiveStreams.toPublisher(range);
AtomicInteger count = new AtomicInteger(0);
RateMeasure rm = new RateMeasure("events");
Promise<Integer> finished = new Promise<>();
KxReactiveStreams.get().asKxPublisher(pub).async().iterator(it -> {
while (it.hasNext()) {
rm.count();
count.incrementAndGet();
}
finished.resolve(count.get());
});
Assert.assertTrue(finished.await(50000).intValue() == NUM_MSG / 4);
}
use of org.nustaq.kontraktor.Promise in project kontraktor by RuedigerMoeller.
the class RxJava method rxToKontraktorTest.
@Test
public void rxToKontraktorTest() {
Observable<Integer> range = Observable.range(0, NUM_MSG);
Publisher<Integer> pub = RxReactiveStreams.toPublisher(range);
AtomicInteger count = new AtomicInteger(0);
RateMeasure rm = new RateMeasure("events");
Promise<Integer> finished = new Promise<>();
KxReactiveStreams.get().asKxPublisher(pub).subscribe((r, e) -> {
rm.count();
if (Actors.isResult(e)) {
count.incrementAndGet();
} else {
finished.resolve(count.get());
}
});
Assert.assertTrue(finished.await(50000).intValue() == NUM_MSG);
}
Aggregations