Search in sources :

Example 1 with Callback

use of org.nustaq.kontraktor.Callback in project kontraktor by RuedigerMoeller.

the class TicketMachine method getTicket.

public IPromise<IPromise> getTicket(final Object channelKey) {
    List<Ticket> futures = tickets.get(channelKey);
    if (futures == null) {
        futures = new ArrayList<>(3);
        tickets.put(channelKey, futures);
    }
    Promise<Object> signalFin = new Promise<>();
    IPromise signalStart = new Promise();
    final Ticket ticket = new Ticket(signalStart, signalFin);
    futures.add(ticket);
    // System.out.println("get ticket "+ticket+" "+Thread.currentThread().getName());
    final List<Ticket> finalFutures = futures;
    signalFin.then(new Callback() {

        @Override
        public void complete(Object result, Object error) {
            // System.out.println("rec "+channelKey+" do remove+checknext");
            boolean remove = finalFutures.remove(ticket);
            if (!remove)
                System.err.println("Error failed to remove " + channelKey);
            checkNext(channelKey, finalFutures, ticket);
        }
    });
    if (futures.size() == 1) {
        // this is the one and only call, start immediately
        signalStart.complete(signalFin, null);
    }
    return signalStart;
}
Also used : IPromise(org.nustaq.kontraktor.IPromise) Promise(org.nustaq.kontraktor.Promise) IPromise(org.nustaq.kontraktor.IPromise) Callback(org.nustaq.kontraktor.Callback)

Example 2 with Callback

use of org.nustaq.kontraktor.Callback 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 Callback

use of org.nustaq.kontraktor.Callback 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 Callback

use of org.nustaq.kontraktor.Callback 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 Callback

use of org.nustaq.kontraktor.Callback 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

Callback (org.nustaq.kontraktor.Callback)7 Test (org.junit.Test)5 AtomicLong (java.util.concurrent.atomic.AtomicLong)4 LockSupport (java.util.concurrent.locks.LockSupport)4 Ignore (org.junit.Ignore)4 EventSink (org.nustaq.kontraktor.reactivestreams.EventSink)4 KxPublisher (org.nustaq.kontraktor.reactivestreams.KxPublisher)4 KxReactiveStreams (org.nustaq.kontraktor.reactivestreams.KxReactiveStreams)4 ActorClientConnector (org.nustaq.kontraktor.remoting.base.ActorClientConnector)4 ActorPublisher (org.nustaq.kontraktor.remoting.base.ActorPublisher)4 ConnectableActor (org.nustaq.kontraktor.remoting.base.ConnectableActor)4 org.nustaq.kontraktor.remoting.tcp (org.nustaq.kontraktor.remoting.tcp)4 org.nustaq.kontraktor.util (org.nustaq.kontraktor.util)4 Actor (org.nustaq.kontraktor.Actor)1 IPromise (org.nustaq.kontraktor.IPromise)1 Promise (org.nustaq.kontraktor.Promise)1 SerializerType (org.nustaq.kontraktor.remoting.encoding.SerializerType)1 WebSocketConnectable (org.nustaq.kontraktor.remoting.websockets.WebSocketConnectable)1