use of org.nustaq.kontraktor.remoting.base.ActorServer in project kontraktor by RuedigerMoeller.
the class Basics method concloseTest.
public void concloseTest(ActorPublisher publisher, ConnectableActor connectable) throws InterruptedException {
ActorServer server = KxReactiveStreams.get().produce(IntStream.range(0, NETWORK_MSG)).serve(publisher);
AtomicInteger cnt = new AtomicInteger(0);
KxReactiveStreams.get().connect(Integer.class, connectable).subscribe((r, e) -> {
if (Actors.isResult(e)) {
cnt.incrementAndGet();
} else {
System.out.println("not result r,e = " + r + "," + e);
}
});
System.out.println("thread:" + DispatcherThread.activeDispatchers.get());
int count = 0;
while (count < 10 && cnt.get() != NETWORK_MSG) {
Thread.sleep(1000);
System.out.println("received msg:" + cnt.get());
count++;
}
Assert.assertTrue(cnt.get() == NETWORK_MSG);
System.out.println("thread:" + DispatcherThread.activeDispatchers.get());
}
use of org.nustaq.kontraktor.remoting.base.ActorServer in project kontraktor by RuedigerMoeller.
the class TCPServerConnector method Publish.
public static Promise<ActorServer> Publish(Actor facade, int port, Coding coding, Consumer<Actor> disconnectCB) {
Promise finished = new Promise();
try {
ActorServer publisher = new ActorServer(new TCPServerConnector(port), facade, coding);
facade.execute(() -> {
try {
publisher.start(disconnectCB);
finished.resolve(publisher);
} catch (Exception e) {
finished.reject(e);
}
});
} catch (Exception e) {
e.printStackTrace();
return new Promise(null, e);
}
return finished;
}
use of org.nustaq.kontraktor.remoting.base.ActorServer in project kontraktor by RuedigerMoeller.
the class RemotingTest method testHttpMany.
@Test
public void testHttpMany() throws Exception {
checkSequenceErrors = false;
RemotingTestService service = Actors.AsActor(RemotingTestService.class, Q_SIZE);
ActorServer publisher = new HttpPublisher(service, "localhost", "/lp", 8082).publish().await();
RemotingTestService client = (RemotingTestService) new HttpConnectable(RemotingTestService.class, "http://localhost:8082/lp").connect().await(9999999);
ExecutorService exec = Executors.newCachedThreadPool();
CountDownLatch latch = new CountDownLatch(10);
for (int i = 0; i < 10; i++) {
exec.execute(() -> {
try {
runWithClient(client, latch);
} catch (Exception e) {
e.printStackTrace();
}
});
}
latch.await();
// wait for outstanding callbacks
Thread.sleep(2000);
publisher.close();
}
use of org.nustaq.kontraktor.remoting.base.ActorServer in project kontraktor by RuedigerMoeller.
the class RemotingTest method runtHttp.
public void runtHttp(Coding coding) throws InterruptedException {
checkSequenceErrors = true;
RemotingTestService service = Actors.AsActor(RemotingTestService.class, Q_SIZE);
ActorServer publisher = new HttpPublisher(service, "localhost", "/lp", 8082).coding(coding).publish().await();
RemotingTestService client = (RemotingTestService) new HttpConnectable(RemotingTestService.class, "http://localhost:8082/lp").coding(coding).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.base.ActorServer in project kontraktor by RuedigerMoeller.
the class RemotingTest method runWS.
public void runWS(Coding coding) throws InterruptedException {
checkSequenceErrors = true;
RemotingTestService service = Actors.AsActor(RemotingTestService.class, Q_SIZE);
ActorServer publisher = new WebSocketPublisher(service, "localhost", "/ws", 8081).coding(coding).publish().await();
RemotingTestService client = (RemotingTestService) new WebSocketConnectable(RemotingTestService.class, "ws://localhost:8081/ws").coding(coding).connect().await(9999999);
CountDownLatch latch = new CountDownLatch(1);
runWithClient(client, latch);
latch.await();
// wait for outstanding callbacks
Thread.sleep(2000);
publisher.close();
}
Aggregations