Search in sources :

Example 26 with Promise

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;
    });
}
Also used : Record(org.nustaq.reallive.api.Record) Arrays(java.util.Arrays) TableSpaceActor(org.nustaq.reallive.impl.tablespace.TableSpaceActor) Promise(org.nustaq.kontraktor.Promise) HashMap(java.util.HashMap) RealLiveTable(org.nustaq.reallive.api.RealLiveTable) Callback(org.nustaq.kontraktor.Callback) TimeUnit(java.util.concurrent.TimeUnit) TableDescription(org.nustaq.reallive.api.TableDescription) CountDownLatch(java.util.concurrent.CountDownLatch) IPromise(org.nustaq.kontraktor.IPromise) java.io(java.io) TableSpaceSharding(org.nustaq.reallive.impl.tablespace.TableSpaceSharding) ServiceActor(org.nustaq.kontraktor.services.ServiceActor) CallerSideMethod(org.nustaq.kontraktor.annotations.CallerSideMethod) Log(org.nustaq.kontraktor.util.Log) FSTConfiguration(org.nustaq.serialization.FSTConfiguration) Actors(org.nustaq.kontraktor.Actors) RLPredicate(org.nustaq.reallive.api.RLPredicate) ClusteredTableSpaceClient(org.nustaq.reallive.impl.tablespace.ClusteredTableSpaceClient) Promise(org.nustaq.kontraktor.Promise) IPromise(org.nustaq.kontraktor.IPromise) HashMap(java.util.HashMap) TableSpaceSharding(org.nustaq.reallive.impl.tablespace.TableSpaceSharding) TableDescription(org.nustaq.reallive.api.TableDescription)

Example 27 with Promise

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;
}
Also used : IPromise(org.nustaq.kontraktor.IPromise) Promise(org.nustaq.kontraktor.Promise) IPromise(org.nustaq.kontraktor.IPromise)

Example 28 with Promise

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);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TCPConnectable(org.nustaq.kontraktor.remoting.tcp.TCPConnectable) Publisher(org.reactivestreams.Publisher) Test(org.junit.Test) Promise(org.nustaq.kontraktor.Promise) KxPublisher(org.nustaq.kontraktor.reactivestreams.KxPublisher) KxReactiveStreams(org.nustaq.kontraktor.reactivestreams.KxReactiveStreams) WebSocketPublisher(org.nustaq.kontraktor.remoting.http.undertow.WebSocketPublisher) RateMeasure(org.nustaq.kontraktor.util.RateMeasure) Observable(rx.Observable) TimeUnit(java.util.concurrent.TimeUnit) MyEvent(examples.MyEvent) CountDownLatch(java.util.concurrent.CountDownLatch) RxReactiveStreams(rx.RxReactiveStreams) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Actors(org.nustaq.kontraktor.Actors) TCPNIOPublisher(org.nustaq.kontraktor.remoting.tcp.TCPNIOPublisher) WebSocketConnectable(org.nustaq.kontraktor.remoting.websockets.WebSocketConnectable) Assert(org.junit.Assert) Promise(org.nustaq.kontraktor.Promise) TCPConnectable(org.nustaq.kontraktor.remoting.tcp.TCPConnectable) RateMeasure(org.nustaq.kontraktor.util.RateMeasure) TCPNIOPublisher(org.nustaq.kontraktor.remoting.tcp.TCPNIOPublisher) Test(org.junit.Test)

Example 29 with Promise

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);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Promise(org.nustaq.kontraktor.Promise) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) RateMeasure(org.nustaq.kontraktor.util.RateMeasure) Test(org.junit.Test)

Example 30 with Promise

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);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Promise(org.nustaq.kontraktor.Promise) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) RateMeasure(org.nustaq.kontraktor.util.RateMeasure) Test(org.junit.Test)

Aggregations

Promise (org.nustaq.kontraktor.Promise)67 IPromise (org.nustaq.kontraktor.IPromise)62 Test (org.junit.Test)10 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)9 Actor (org.nustaq.kontraktor.Actor)6 Remoted (org.nustaq.kontraktor.annotations.Remoted)6 IOException (java.io.IOException)4 Actors (org.nustaq.kontraktor.Actors)4 RateMeasure (org.nustaq.kontraktor.util.RateMeasure)4 JsonObject (com.eclipsesource.json.JsonObject)3 ByteBuffer (java.nio.ByteBuffer)3 KeyManagementException (java.security.KeyManagementException)3 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)3 CertificateException (java.security.cert.CertificateException)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 Consumer (java.util.function.Consumer)3 ActorServer (org.nustaq.kontraktor.remoting.base.ActorServer)3 TCPConnectable (org.nustaq.kontraktor.remoting.tcp.TCPConnectable)3 TableSpaceActor (org.nustaq.reallive.impl.tablespace.TableSpaceActor)3 EOFException (java.io.EOFException)2