use of org.nustaq.kontraktor.IPromise in project kontraktor by RuedigerMoeller.
the class BasicTest method allTest.
@Test
public void allTest() throws InterruptedException {
ArrayList<IPromise<Object>> al = new ArrayList();
al.add(new Promise());
al.add(new Promise());
new Thread(() -> {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
al.get(0).resolve();
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
al.get(1).resolve();
}).start();
Actors.all(al).await();
}
use of org.nustaq.kontraktor.IPromise in project kontraktor by RuedigerMoeller.
the class TicketMachine method getTicket.
public IPromise<IPromise> getTicket(final Object channelKey) {
List<Ticket> futures = tickets.get(channelKey);
if (futures == null) {
futures = new ArrayList<>(3);
tickets.put(channelKey, futures);
}
Promise<Object> signalFin = new Promise<>();
IPromise signalStart = new Promise();
final Ticket ticket = new Ticket(signalStart, signalFin);
futures.add(ticket);
// System.out.println("get ticket "+ticket+" "+Thread.currentThread().getName());
final List<Ticket> finalFutures = futures;
signalFin.then(new Callback() {
@Override
public void complete(Object result, Object error) {
// System.out.println("rec "+channelKey+" do remove+checknext");
boolean remove = finalFutures.remove(ticket);
if (!remove)
System.err.println("Error failed to remove " + channelKey);
checkNext(channelKey, finalFutures, ticket);
}
});
if (futures.size() == 1) {
// this is the one and only call, start immediately
signalStart.complete(signalFin, null);
}
return signalStart;
}
use of org.nustaq.kontraktor.IPromise in project kontraktor by RuedigerMoeller.
the class HttpMonitor method getMonitorables.
protected IPromise<Object[]> getMonitorables(int depth, Monitorable monitorable) {
// System.out.println("dumpmon " + monitorable);
Promise p = new Promise();
monitorable.$getReport().then((report, err) -> {
Object[] result = new Object[2];
result[0] = report;
monitorable.$getSubMonitorables().then((monitorables, errmon) -> {
if (monitorables.length > 0 && depth >= 1) {
Object[] subResult = new Object[monitorables.length];
result[1] = subResult;
IPromise[] futs = new IPromise[monitorables.length];
for (int i = 0; i < monitorables.length; i++) {
Monitorable submon = monitorables[i];
futs[i] = getMonitorables(depth - 1, submon);
}
all(futs).then((futArr, err0) -> {
IPromise[] futures = (IPromise[]) futArr;
for (int i = 0; i < futures.length; i++) {
IPromise future = futures[i];
subResult[i] = future.get();
}
p.settle(result, null);
});
} else
p.settle(result, null);
});
});
return p;
}
use of org.nustaq.kontraktor.IPromise in project kontraktor by RuedigerMoeller.
the class PromiseSampleService method getDataSimple1.
public IPromise<String> getDataSimple1() {
Promise result = new Promise();
result.resolve("Data");
return result;
}
use of org.nustaq.kontraktor.IPromise in project kontraktor by RuedigerMoeller.
the class PromiseSampleService method getDataAsync.
// //////////////////////////////////////////////////
public IPromise<String> getDataAsync() {
Promise p = new Promise();
// simulate async long running op
delayed(3000, () -> p.resolve("Data"));
// returns before result is present
return p;
}
Aggregations