Search in sources :

Example 1 with ActorClientConnector

use of org.nustaq.kontraktor.remoting.base.ActorClientConnector in project kontraktor by RuedigerMoeller.

the class KxReactiveStreams method connect.

/**
 * @param eventType
 * @param connectable
 * @param disconHandler - can be null
 * @param <T>
 * @return
 */
public <T> IPromise<KxPublisher<T>> connect(Class<T> eventType, ConnectableActor connectable, Callback<ActorClientConnector> disconHandler) {
    Callback<ActorClientConnector> discon = (acc, err) -> {
        Log.Info(this, "Client disconnected");
        acc.closeClient();
        if (disconHandler != null) {
            disconHandler.complete(acc, err);
        }
    };
    IPromise connect = connectable.actorClass(KxPublisherActor.class).inboundQueueSize(scheduler.getDefaultQSize()).connect(discon, r -> {
        Object remoteref = r;
        if (((KxPublisherActor) remoteref)._callerSideSubscribers != null) {
            ((KxPublisherActor) remoteref)._callerSideSubscribers.forEach(subs -> {
                ((Subscriber) subs).onError(new IOException("connection lost"));
            });
            ((KxPublisherActor) remoteref)._callerSideSubscribers = null;
        }
    });
    Promise<KxPublisher<T>> res = new Promise<>();
    connect.then((publisher, err) -> {
        if (publisher != null) {
            ((KxPublisherActor) publisher)._streams = this;
            res.resolve((KxPublisher<T>) publisher);
        } else {
            res.reject(err);
        }
    });
    return res;
}
Also used : ActorPublisher(org.nustaq.kontraktor.remoting.base.ActorPublisher) Iterator(java.util.Iterator) ActorClientConnector(org.nustaq.kontraktor.remoting.base.ActorClientConnector) Spliterators(java.util.Spliterators) java.util.stream(java.util.stream) Processor(org.reactivestreams.Processor) Publisher(org.reactivestreams.Publisher) Collection(java.util.Collection) SimpleScheduler(org.nustaq.kontraktor.impl.SimpleScheduler) IOException(java.io.IOException) Function(java.util.function.Function) Consumer(java.util.function.Consumer) SyncProcessor(org.nustaq.kontraktor.reactivestreams.impl.SyncProcessor) KxSubscriber(org.nustaq.kontraktor.reactivestreams.impl.KxSubscriber) ConnectableActor(org.nustaq.kontraktor.remoting.base.ConnectableActor) KxPublisherActor(org.nustaq.kontraktor.reactivestreams.impl.KxPublisherActor) CallerSideMethod(org.nustaq.kontraktor.annotations.CallerSideMethod) Log(org.nustaq.kontraktor.util.Log) org.nustaq.kontraktor(org.nustaq.kontraktor) Subscriber(org.reactivestreams.Subscriber) Spliterator(java.util.Spliterator) KxSubscriber(org.nustaq.kontraktor.reactivestreams.impl.KxSubscriber) Subscriber(org.reactivestreams.Subscriber) ActorClientConnector(org.nustaq.kontraktor.remoting.base.ActorClientConnector) IOException(java.io.IOException)

Example 2 with ActorClientConnector

use of org.nustaq.kontraktor.remoting.base.ActorClientConnector in project kontraktor by RuedigerMoeller.

the class TCPNIOKStreamsTest method testClient1.

@Test
@Ignore
public void testClient1() throws InterruptedException {
    AtomicLong received = new AtomicLong(0);
    Callback<ActorClientConnector> discon = (acc, err) -> {
        System.out.println("Client disconnected");
    };
    KxPublisher<String> remote = get().connect(String.class, getRemoteConnector(), discon).await();
    RateMeasure ms = new RateMeasure("event rate");
    remote.syncMap(string -> string.length()).syncMap(number -> number > 10 ? number : number).subscribe((str, err) -> {
        if (isErrorOrComplete(err)) {
            System.out.println("complete");
        } else if (isError(err)) {
            System.out.println("ERROR");
        } else {
            received.incrementAndGet();
            ms.count();
        }
    });
    while (true) {
        Thread.sleep(100);
    }
}
Also used : ActorPublisher(org.nustaq.kontraktor.remoting.base.ActorPublisher) ActorClientConnector(org.nustaq.kontraktor.remoting.base.ActorClientConnector) org.nustaq.kontraktor.util(org.nustaq.kontraktor.util) Test(org.junit.Test) KxPublisher(org.nustaq.kontraktor.reactivestreams.KxPublisher) KxReactiveStreams(org.nustaq.kontraktor.reactivestreams.KxReactiveStreams) EventSink(org.nustaq.kontraktor.reactivestreams.EventSink) Callback(org.nustaq.kontraktor.Callback) LockSupport(java.util.concurrent.locks.LockSupport) AtomicLong(java.util.concurrent.atomic.AtomicLong) Ignore(org.junit.Ignore) ConnectableActor(org.nustaq.kontraktor.remoting.base.ConnectableActor) org.nustaq.kontraktor.remoting.tcp(org.nustaq.kontraktor.remoting.tcp) AtomicLong(java.util.concurrent.atomic.AtomicLong) ActorClientConnector(org.nustaq.kontraktor.remoting.base.ActorClientConnector) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 3 with ActorClientConnector

use of org.nustaq.kontraktor.remoting.base.ActorClientConnector in project kontraktor by RuedigerMoeller.

the class TCPNIOKStreamsTest method testClient.

@Test
@Ignore
public void testClient() throws InterruptedException {
    AtomicLong received = new AtomicLong(0);
    Callback<ActorClientConnector> discon = (acc, err) -> {
        System.out.println("Client disconnected");
    };
    KxPublisher<String> remote = get().connect(String.class, getRemoteConnector(), discon).await();
    RateMeasure ms = new RateMeasure("event rate");
    remote.subscribe((str, err) -> {
        if (isErrorOrComplete(err)) {
            System.out.println("complete e:" + err + " r:" + str);
        } else if (isError(err)) {
            System.out.println("ERROR " + err);
        } else {
            received.incrementAndGet();
            ms.count();
        }
    });
    while (true) {
        Thread.sleep(100);
    }
}
Also used : ActorPublisher(org.nustaq.kontraktor.remoting.base.ActorPublisher) ActorClientConnector(org.nustaq.kontraktor.remoting.base.ActorClientConnector) org.nustaq.kontraktor.util(org.nustaq.kontraktor.util) Test(org.junit.Test) KxPublisher(org.nustaq.kontraktor.reactivestreams.KxPublisher) KxReactiveStreams(org.nustaq.kontraktor.reactivestreams.KxReactiveStreams) EventSink(org.nustaq.kontraktor.reactivestreams.EventSink) Callback(org.nustaq.kontraktor.Callback) LockSupport(java.util.concurrent.locks.LockSupport) AtomicLong(java.util.concurrent.atomic.AtomicLong) Ignore(org.junit.Ignore) ConnectableActor(org.nustaq.kontraktor.remoting.base.ConnectableActor) org.nustaq.kontraktor.remoting.tcp(org.nustaq.kontraktor.remoting.tcp) AtomicLong(java.util.concurrent.atomic.AtomicLong) ActorClientConnector(org.nustaq.kontraktor.remoting.base.ActorClientConnector) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 4 with ActorClientConnector

use of org.nustaq.kontraktor.remoting.base.ActorClientConnector in project kontraktor by RuedigerMoeller.

the class TCPNIOKStreamsTest method testClient3.

// cleanup of async processors
@Test
// cleanup of async processors
@Ignore
public void testClient3() throws InterruptedException {
    AtomicLong received = new AtomicLong(0);
    Callback<ActorClientConnector> discon = (acc, err) -> {
        System.out.println("Client disconnected");
    };
    KxPublisher<String> remote = get().connect(String.class, getRemoteConnector(), discon).await();
    RateMeasure ms = new RateMeasure("event rate");
    remote.map(string -> string.length()).map(number -> number > 10 ? number : number).subscribe((str, err) -> {
        if (isComplete(err)) {
            System.out.println("complete");
        } else if (isError(err)) {
            System.out.println("ERROR " + err);
        } else {
            received.incrementAndGet();
            ms.count();
        }
    });
    while (true) {
        Thread.sleep(100);
    }
}
Also used : ActorPublisher(org.nustaq.kontraktor.remoting.base.ActorPublisher) ActorClientConnector(org.nustaq.kontraktor.remoting.base.ActorClientConnector) org.nustaq.kontraktor.util(org.nustaq.kontraktor.util) Test(org.junit.Test) KxPublisher(org.nustaq.kontraktor.reactivestreams.KxPublisher) KxReactiveStreams(org.nustaq.kontraktor.reactivestreams.KxReactiveStreams) EventSink(org.nustaq.kontraktor.reactivestreams.EventSink) Callback(org.nustaq.kontraktor.Callback) LockSupport(java.util.concurrent.locks.LockSupport) AtomicLong(java.util.concurrent.atomic.AtomicLong) Ignore(org.junit.Ignore) ConnectableActor(org.nustaq.kontraktor.remoting.base.ConnectableActor) org.nustaq.kontraktor.remoting.tcp(org.nustaq.kontraktor.remoting.tcp) AtomicLong(java.util.concurrent.atomic.AtomicLong) ActorClientConnector(org.nustaq.kontraktor.remoting.base.ActorClientConnector) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 5 with ActorClientConnector

use of org.nustaq.kontraktor.remoting.base.ActorClientConnector in project kontraktor by RuedigerMoeller.

the class TCPNIOKStreamsTest method testClient2.

// slowdown
@Test
// slowdown
@Ignore
public void testClient2() throws InterruptedException {
    AtomicLong received = new AtomicLong(0);
    Callback<ActorClientConnector> discon = (acc, err) -> {
        System.out.println("Client disconnected");
    };
    KxPublisher<String> remote = get().connect(String.class, getRemoteConnector(), discon).await();
    RateMeasure ms = new RateMeasure("event rate");
    remote.syncMap(string -> string.length()).syncMap(number -> number > 10 ? number : number).subscribe((str, err) -> {
        if (isErrorOrComplete(err)) {
            System.out.println("complete");
        } else if (isError(err)) {
            System.out.println("ERROR");
        } else {
            received.incrementAndGet();
            ms.count();
            try {
                Thread.sleep(1);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    });
    while (true) {
        Thread.sleep(100);
    }
}
Also used : ActorPublisher(org.nustaq.kontraktor.remoting.base.ActorPublisher) ActorClientConnector(org.nustaq.kontraktor.remoting.base.ActorClientConnector) org.nustaq.kontraktor.util(org.nustaq.kontraktor.util) Test(org.junit.Test) KxPublisher(org.nustaq.kontraktor.reactivestreams.KxPublisher) KxReactiveStreams(org.nustaq.kontraktor.reactivestreams.KxReactiveStreams) EventSink(org.nustaq.kontraktor.reactivestreams.EventSink) Callback(org.nustaq.kontraktor.Callback) LockSupport(java.util.concurrent.locks.LockSupport) AtomicLong(java.util.concurrent.atomic.AtomicLong) Ignore(org.junit.Ignore) ConnectableActor(org.nustaq.kontraktor.remoting.base.ConnectableActor) org.nustaq.kontraktor.remoting.tcp(org.nustaq.kontraktor.remoting.tcp) AtomicLong(java.util.concurrent.atomic.AtomicLong) ActorClientConnector(org.nustaq.kontraktor.remoting.base.ActorClientConnector) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

ActorClientConnector (org.nustaq.kontraktor.remoting.base.ActorClientConnector)5 ActorPublisher (org.nustaq.kontraktor.remoting.base.ActorPublisher)5 ConnectableActor (org.nustaq.kontraktor.remoting.base.ConnectableActor)5 AtomicLong (java.util.concurrent.atomic.AtomicLong)4 LockSupport (java.util.concurrent.locks.LockSupport)4 Ignore (org.junit.Ignore)4 Test (org.junit.Test)4 Callback (org.nustaq.kontraktor.Callback)4 EventSink (org.nustaq.kontraktor.reactivestreams.EventSink)4 KxPublisher (org.nustaq.kontraktor.reactivestreams.KxPublisher)4 KxReactiveStreams (org.nustaq.kontraktor.reactivestreams.KxReactiveStreams)4 org.nustaq.kontraktor.remoting.tcp (org.nustaq.kontraktor.remoting.tcp)4 org.nustaq.kontraktor.util (org.nustaq.kontraktor.util)4 IOException (java.io.IOException)1 Collection (java.util.Collection)1 Iterator (java.util.Iterator)1 Spliterator (java.util.Spliterator)1 Spliterators (java.util.Spliterators)1 Consumer (java.util.function.Consumer)1 Function (java.util.function.Function)1