use of org.nustaq.kontraktor.Promise in project kontraktor by RuedigerMoeller.
the class DeadLocks method main.
public static void main(String[] arg) {
SelfDeadLocker dl = Actors.AsActor(SelfDeadLocker.class, 1000);
Promise end = new Promise();
dl.deadLock(end, true);
end.then((r, e) -> {
System.out.println("control finished: " + dl.getActor().msgcount);
dl.stop();
});
SelfDeadLocker dl1 = Actors.AsActor(SelfDeadLocker.class, 1000);
Promise end1 = new Promise();
dl1.deadLock(end1, false);
end1.then((r, e) -> {
System.out.println("nocontrol finished: " + dl1.getActor().msgcount);
dl1.stop();
});
}
use of org.nustaq.kontraktor.Promise 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.Promise 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.Promise 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;
}
use of org.nustaq.kontraktor.Promise in project kontraktor by RuedigerMoeller.
the class RemoteRefPolling method scheduleSendLoop.
/**
* return a future which is completed upon connection close
*
* @param reg
*
* @return future completed upon termination of scheduling (disconnect)
*/
public IPromise scheduleSendLoop(ConnectionRegistry reg) {
Promise promise = new Promise();
sendJobs.add(new ScheduleEntry(reg, promise));
synchronized (this) {
if (!loopStarted) {
loopStarted = true;
Actor.current().execute(this);
}
}
return promise;
}
Aggregations