use of org.nustaq.kontraktor.IPromise in project kontraktor by RuedigerMoeller.
the class TCPConnectable method connect.
@Override
public <T extends Actor> IPromise<T> connect(Callback<ActorClientConnector> disconnectCallback, Consumer<Actor> actorDisconnecCB) {
Promise result = new Promise();
Runnable connect = () -> {
TCPClientConnector client = new TCPClientConnector(port, host, disconnectCallback);
ActorClient connector = new ActorClient(client, actorClz, coding);
connector.connect(inboundQueueSize, actorDisconnecCB).then(result);
};
if (!Actor.inside()) {
TCPClientConnector.get().execute(() -> Thread.currentThread().setName("tcp singleton remote client actor polling"));
TCPClientConnector.get().execute(connect);
} else
connect.run();
return result;
}
use of org.nustaq.kontraktor.IPromise in project kontraktor by RuedigerMoeller.
the class HttpMonitor method getMonitorableKeys.
public IPromise<String[]> getMonitorableKeys(String simpleClzName) {
ArrayList<String> result = new ArrayList();
monitored.entrySet().forEach((entry) -> {
Monitorable mon = entry.getValue();
if (mon instanceof Actor)
mon = ((Actor) mon).getActor();
if (entry.getValue() != null && mon.getClass().getSimpleName().equals(simpleClzName)) {
result.add(entry.getKey());
}
});
String[] res = new String[result.size()];
result.toArray(res);
return new Promise(res);
}
use of org.nustaq.kontraktor.IPromise in project kontraktor by RuedigerMoeller.
the class AsyncSocketConnection method directWrite.
protected IPromise directWrite(ByteBuffer buf) {
checkThread();
if (myActor == null)
myActor = Actor.current();
if (writePromise != null)
throw new RuntimeException("concurrent write con:" + chan.isConnected() + " open:" + chan.isOpen());
writePromise = new Promise();
writingBuffer = buf;
Promise res = writePromise;
try {
int written = 0;
written = chan.write(buf);
if (written < 0) {
// TODO:closed
writeFinished(new IOException("connection closed"));
}
if (buf.remaining() > 0) {
// key.interestOps(SelectionKey.OP_WRITE);
} else {
writeFinished(null);
}
} catch (Exception e) {
res.reject(e);
FSTUtil.rethrow(e);
}
return res;
}
use of org.nustaq.kontraktor.IPromise in project kontraktor by RuedigerMoeller.
the class QueuingAsyncSocketConnection method tryFlush.
public void tryFlush() {
checkThread();
if (canWrite()) {
qWriteTmp.position(0);
qWriteTmp.limit(qWriteTmp.capacity());
tmp.setBuffer(qWriteTmp);
long poll = writeQueue.poll(tmp, 0, tmp.length());
// System.out.println("try write "+poll+" avail:"+writeQueue.available()+" cap:"+writeQueue.capacity());
if (poll > 0) {
qWriteTmp.limit((int) poll);
IPromise queueDataAvailablePromise = directWrite(qWriteTmp);
queueDataAvailablePromise.then((res, err) -> {
if (err != null) {
if (err instanceof Throwable) {
Log.Lg.error(this, (Throwable) err, "write failure");
closed((Throwable) err);
} else {
Log.Lg.error(this, null, "write failure:" + err);
closed(new IOException("" + err));
}
} else {
tryFlush();
}
});
}
}
}
use of org.nustaq.kontraktor.IPromise in project kontraktor by RuedigerMoeller.
the class PlainService method initPlainService.
public IPromise<PlainService> initPlainService(String name, String[] requiredServices, ServiceArgs options) {
if (requiredServices == null) {
this.requiredServices = new String[0];
} else {
this.requiredServices = requiredServices;
}
this.serviceName = name;
Promise p = new Promise();
self().init(new TCPConnectable(ServiceRegistry.class, options.getRegistryHost(), options.getRegistryPort()), options, true).then((r, e) -> {
if (e == null) {
p.resolve(self());
} else {
p.reject(e);
}
});
return p;
}
Aggregations