Search in sources :

Example 6 with TCPNIOPublisher

use of org.nustaq.kontraktor.remoting.tcp.TCPNIOPublisher in project kontraktor by RuedigerMoeller.

the class HelloActor method main.

public static void main(String[] a) {
    HelloActor myService = AsActor(HelloActor.class);
    // as websocket service fast serialialized
    new WebSocketPublisher().facade(myService).hostName("localhost").urlPath("/hello").port(8080).serType(SerializerType.FSTSer).publish();
    // as http long poll service, json encoding
    new HttpPublisher().facade(myService).hostName("localhost").urlPath("/hellohttp").port(8080).serType(SerializerType.JsonNoRefPretty).publish();
    // as tcp nio service, fast serialized
    new TCPNIOPublisher().facade(myService).port(6789).serType(SerializerType.FSTSer).publish().await();
}
Also used : WebSocketPublisher(org.nustaq.kontraktor.remoting.http.undertow.WebSocketPublisher) HttpPublisher(org.nustaq.kontraktor.remoting.http.undertow.HttpPublisher) TCPNIOPublisher(org.nustaq.kontraktor.remoting.tcp.TCPNIOPublisher)

Example 7 with TCPNIOPublisher

use of org.nustaq.kontraktor.remoting.tcp.TCPNIOPublisher in project kontraktor by RuedigerMoeller.

the class ServiceActor method publishSelf.

protected void publishSelf() {
    int defaultPort = getPort();
    // service does not expose itself
    if (defaultPort <= 0) {
        Log.Warn(this, "Service " + getServiceDescription().getName() + " has no port and host configured. Unpublished.");
        return;
    }
    Log.Info(this, "publishing self at " + defaultPort);
    new TCPNIOPublisher(self(), defaultPort).publish(actor -> {
        Log.Info(null, actor + " has disconnected");
    });
}
Also used : TCPNIOPublisher(org.nustaq.kontraktor.remoting.tcp.TCPNIOPublisher)

Example 8 with TCPNIOPublisher

use of org.nustaq.kontraktor.remoting.tcp.TCPNIOPublisher in project kontraktor by RuedigerMoeller.

the class ServiceRegistry method main.

public static void main(String[] args) {
    options = parseCommandLine(args, new ServiceArgs());
    if (!options.isSysoutlog()) {
        Log.SetSynchronous();
    // Log.Lg.setLogWrapper(new Log4j2LogWrapper(Log.Lg.getSeverity()));
    }
    ServiceRegistry serviceRegistry = Actors.AsActor(ServiceRegistry.class);
    serviceRegistry.init();
    new TCPNIOPublisher(serviceRegistry, options.getRegistryPort()).publish(actor -> {
        Log.Info(null, actor + " has disconnected");
    });
    // log service activity
    serviceRegistry.subscribe((pair, err) -> {
        Log.Info(serviceRegistry.getClass(), pair.car() + " " + pair.cdr());
    });
}
Also used : TCPNIOPublisher(org.nustaq.kontraktor.remoting.tcp.TCPNIOPublisher)

Example 9 with TCPNIOPublisher

use of org.nustaq.kontraktor.remoting.tcp.TCPNIOPublisher 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 10 with TCPNIOPublisher

use of org.nustaq.kontraktor.remoting.tcp.TCPNIOPublisher in project kontraktor by RuedigerMoeller.

the class KxStreamServer method main.

public static void main(String[] args) {
    // give fat queue
    KxStreamServer server = Actors.AsActor(KxStreamServer.class, 256000);
    server.init();
    TCPNIOPublisher publisher = new TCPNIOPublisher(server, 7890);
    publisher.publish(actor -> System.out.println("actor " + actor + " disconnected")).await();
    System.out.println("server started at " + publisher);
}
Also used : IntStream(java.util.stream.IntStream) IPromise(org.nustaq.kontraktor.IPromise) Actor(org.nustaq.kontraktor.Actor) Actors(org.nustaq.kontraktor.Actors) TCPNIOPublisher(org.nustaq.kontraktor.remoting.tcp.TCPNIOPublisher) Promise(org.nustaq.kontraktor.Promise) KxPublisher(org.nustaq.kontraktor.reactivestreams.KxPublisher) HashMap(java.util.HashMap) KxReactiveStreams(org.nustaq.kontraktor.reactivestreams.KxReactiveStreams) Pair(org.nustaq.kontraktor.util.Pair) EventSink(org.nustaq.kontraktor.reactivestreams.EventSink) TCPNIOPublisher(org.nustaq.kontraktor.remoting.tcp.TCPNIOPublisher)

Aggregations

TCPNIOPublisher (org.nustaq.kontraktor.remoting.tcp.TCPNIOPublisher)17 Test (org.junit.Test)8 TCPConnectable (org.nustaq.kontraktor.remoting.tcp.TCPConnectable)8 Actors (org.nustaq.kontraktor.Actors)4 Promise (org.nustaq.kontraktor.Promise)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 Actor (org.nustaq.kontraktor.Actor)3 WebSocketPublisher (org.nustaq.kontraktor.remoting.http.undertow.WebSocketPublisher)3 RateMeasure (org.nustaq.kontraktor.util.RateMeasure)3 CountDownLatch (java.util.concurrent.CountDownLatch)2 TimeUnit (java.util.concurrent.TimeUnit)2 Ignore (org.junit.Ignore)2 IPromise (org.nustaq.kontraktor.IPromise)2 KxPublisher (org.nustaq.kontraktor.reactivestreams.KxPublisher)2 KxReactiveStreams (org.nustaq.kontraktor.reactivestreams.KxReactiveStreams)2 HttpPublisher (org.nustaq.kontraktor.remoting.http.undertow.HttpPublisher)2 WebSocketConnectable (org.nustaq.kontraktor.remoting.websockets.WebSocketConnectable)2 TableSpaceActor (org.nustaq.reallive.impl.tablespace.TableSpaceActor)2 JCommander (com.beust.jcommander.JCommander)1 MyEvent (examples.MyEvent)1