use of org.nustaq.kontraktor.remoting.base.ConnectableActor 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;
}
use of org.nustaq.kontraktor.remoting.base.ConnectableActor in project kontraktor by RuedigerMoeller.
the class Basics method testConnectionCloseOnCompleteWS.
@Test
public void testConnectionCloseOnCompleteWS() throws InterruptedException {
WebSocketPublisher publisher = new WebSocketPublisher().hostName("localhost").urlPath("/ws").port(8082);
ConnectableActor connectable = new WebSocketConnectable().url("ws://localhost:8082/ws");
concloseTest(publisher, connectable);
}
use of org.nustaq.kontraktor.remoting.base.ConnectableActor in project kontraktor by RuedigerMoeller.
the class KLoadTest method run.
public void run() {
boolean http = false;
ConnectableActor connectable;
if (!http) {
connectable = new WebSocketConnectable(MyHttpApp.class, "ws://localhost:8080/ws").serType(SerializerType.JsonNoRef);
} else {
connectable = new HttpConnectable(MyHttpApp.class, "http://localhost:8080/api").serType(SerializerType.JsonNoRef);
}
connectable.connect((connector, error) -> {
System.out.println("connection lost " + connector);
}).then((res, err) -> {
myApp = (MyHttpApp) res;
myApp.login("dummy", "dummy").then((s, err1) -> {
session = s;
System.out.println("session connected " + session);
session.subscribe((result, e) -> {
count++;
lastBcast.set(System.currentTimeMillis());
});
});
});
}
use of org.nustaq.kontraktor.remoting.base.ConnectableActor in project kontraktor by RuedigerMoeller.
the class TestCrashClose method main.
public static void main(String[] args) {
boolean http = false;
ConnectableActor connectable;
if (!http) {
connectable = new WebSocketConnectable(MyHttpApp.class, "ws://localhost:8080/ws").serType(SerializerType.JsonNoRef);
} else {
connectable = new HttpConnectable(MyHttpApp.class, "http://localhost:8080/api").serType(SerializerType.JsonNoRef);
}
connectable.connect((connector, error) -> {
System.out.println("connection lost " + connector);
}).then((res, err) -> {
MyHttpApp myApp = (MyHttpApp) res;
myApp.login("dummy", "dummy").then((s, err1) -> {
MyHttpAppSession session = s;
System.out.println("session connected " + session);
session.subscribe((result, e) -> {
System.exit(0);
});
});
});
}
use of org.nustaq.kontraktor.remoting.base.ConnectableActor in project kontraktor by RuedigerMoeller.
the class RemotingTest method fromRemote.
private void fromRemote(ConnectableActor con) {
RemotingTA remote = (RemotingTA) con.connect().await();
IPromise fin = new Promise();
AtomicInteger count = new AtomicInteger();
Integer expect = remote.sayHello(10, (str, err) -> {
if (Actors.isCont(err)) {
System.out.println("received:" + str);
count.incrementAndGet();
} else {
fin.complete();
}
}).await();
fin.await();
Assert.assertTrue(expect.intValue() == count.intValue());
}
Aggregations