use of org.nustaq.kontraktor.impl.RemoteScheduler in project kontraktor by RuedigerMoeller.
the class ActorClient method connect.
public IPromise<T> connect(int qsiz, Consumer<Actor> discon) {
Promise<T> result = new Promise<>();
try {
client.connect(writesocket -> {
Actor facadeProxy = Actors.AsActor(facadeClass, new RemoteScheduler(qsiz));
facadeProxy.__remoteId = 1;
AtomicReference<ObjectSocket> socketRef = new AtomicReference<>(writesocket);
ConnectionRegistry reg = new ConnectionRegistry(coding) {
@Override
public Actor getFacadeProxy() {
return facadeProxy;
}
@Override
public AtomicReference<ObjectSocket> getWriteObjectSocket() {
return socketRef;
}
};
reg.setDisconnectHandler(discon);
if (coding.getCrossPlatformShortClazzNames() != null)
reg.getConf().registerCrossPlatformClassMappingUseSimpleName(coding.getCrossPlatformShortClazzNames());
writesocket.setConf(reg.getConf());
// ensure running in actor thread
Actor.current();
ObjectSink objectSink = new ObjectSink() {
@Override
public void receiveObject(ObjectSink sink, Object received, List<IPromise> createdFutures, Object securityContext) {
try {
reg.receiveObject(socketRef.get(), sink, received, createdFutures, securityContext);
} catch (Exception e) {
FSTUtil.rethrow(e);
}
}
@Override
public void sinkClosed() {
reg.disconnect();
}
};
reg.registerRemoteRefDirect(facadeProxy);
poller.get().scheduleSendLoop(reg).then(() -> {
objectSink.sinkClosed();
});
result.resolve((T) facadeProxy);
return objectSink;
});
} catch (Exception e) {
if (!result.isSettled())
result.reject(e);
else
e.printStackTrace();
}
return result;
}
Aggregations