use of org.nustaq.kontraktor.remoting.websockets.WebSocketConnectable in project kontraktor by RuedigerMoeller.
the class MyServiceClient method main.
public static void main(String[] args) {
if (args == null || args.length == 0) {
MyServiceClient cl = AsActor(MyServiceClient.class);
cl.init(new WebSocketConnectable().url("ws://localhost:6667/myservice/v1/bin").serType(SerializerType.FSTSer).actorClass(IMyService.class)).then((r, e) -> {
if (e != null) {
Log.Error(MyServiceClient.class, (Throwable) e);
}
});
} else {
MyServiceClient cl = AsActor(MyServiceClient.class);
cl.init(new WebSocketConnectable().url("ws://localhost:6667/myservice/v1/json").serType(SerializerType.JsonNoRef).actorClass(IMyService.class)).then((r, e) -> {
if (e != null) {
Log.Error(MyServiceClient.class, (Throwable) e);
}
});
}
}
use of org.nustaq.kontraktor.remoting.websockets.WebSocketConnectable in project kontraktor by RuedigerMoeller.
the class UntypedGreeterClient method main.
// NOTE: due to a temporary bug in 4.03, untyped java clients DO NOT WORK
// with Java-implemented Servers. Use typed clients meanwhile
public static void main(String[] args) {
Actor remote = (Actor) new WebSocketConnectable().actorClass(Actor.class).url("ws://localhost:3999").serType(SerializerType.JsonNoRef).connect((x, y) -> System.out.println("disconnect " + x + " " + y)).await();
remote.ask("greet", "Kontraktor", 1000).then((r, e) -> System.out.println(r));
}
use of org.nustaq.kontraktor.remoting.websockets.WebSocketConnectable in project kontraktor by RuedigerMoeller.
the class MyService method main.
public static void main(String[] args) {
MyServiceArgs conf = new MyServiceArgs();
JCommander.newBuilder().addObject(conf).build().parse(args);
MyService serv = AsActor(MyService.class);
serv.init();
conf.connectUrls.forEach(url -> {
Routing.registerService(new WebSocketConnectable().url(url).serType(url.endsWith("/bin") ? SerializerType.FSTSer : SerializerType.JsonNoRef), serv, x -> serv.disconnedtedCB(x), true).then((r, e) -> {
if (e != null) {
Log.Info(MyService.class, "error connecting krouter " + e);
if (e instanceof Throwable)
Log.Info(MyService.class, (Throwable) e);
} else
Log.Info(MyService.class, "MyService connected krouter " + url);
});
});
}
use of org.nustaq.kontraktor.remoting.websockets.WebSocketConnectable in project kontraktor by RuedigerMoeller.
the class RemotingTest method testWSJSR.
// fixme: add connect-from-actor tests
// fixme: add minbin tests
// fixme: increase basic test coverage
@Test
@Ignore
public void testWSJSR() throws Exception {
checkSequenceErrors = true;
RemotingTestService service = Actors.AsActor(RemotingTestService.class, Q_SIZE);
ActorServer publisher = _JSR356ServerConnector.Publish(service, "ws://localhost:8081/ws", null).await();
RemotingTestService client = (RemotingTestService) new WebSocketConnectable(RemotingTestService.class, "ws://localhost:8081/ws").connect().await(9999999);
CountDownLatch latch = new CountDownLatch(1);
runWithClient(client, latch);
latch.await();
// wait for outstanding callbacks
Thread.sleep(2000);
publisher.close();
}
use of org.nustaq.kontraktor.remoting.websockets.WebSocketConnectable in project kontraktor by RuedigerMoeller.
the class AkkaInterop method serveAkka_RemoteToKontraktor.
@Test
public void serveAkka_RemoteToKontraktor() throws InterruptedException {
final int NUM_MSG = 50_000_000;
final ActorSystem system = ActorSystem.create("reactive-interop");
final Materializer mat = ActorMaterializer.create(system);
KxReactiveStreams kxStreams = KxReactiveStreams.get();
RateMeasure rm = new RateMeasure("rate");
CountDownLatch count = new CountDownLatch(NUM_MSG);
Iterable it = () -> IntStream.range(0, NUM_MSG).mapToObj(x -> x).iterator();
Publisher<Integer> pub = (Publisher<Integer>) Source.from(it).runWith(Sink.publisher(), mat);
kxStreams.asKxPublisher(pub).serve(new WebSocketPublisher().hostName("localhost").port(6790).urlPath("akka"));
// subscribe with kontraktor client
new KxReactiveStreams(true).connect(Integer.class, new WebSocketConnectable().url("ws://localhost:6790/akka")).subscribe((res, err) -> {
if (Actors.isResult(err)) {
rm.count();
count.countDown();
}
});
int secondsWait = 50;
while (count.getCount() > 0 && secondsWait-- > 0) {
System.out.println("count:" + count.getCount());
Thread.sleep(1000);
}
system.shutdown();
Assert.assertTrue(count.getCount() == 0);
// give time closing stuff
Thread.sleep(1000);
}
Aggregations