use of org.nustaq.kontraktor.Callback 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.Callback in project kontraktor by RuedigerMoeller.
the class TCPNIOKStreamsTest method testClient1.
@Test
@Ignore
public void testClient1() throws InterruptedException {
AtomicLong received = new AtomicLong(0);
Callback<ActorClientConnector> discon = (acc, err) -> {
System.out.println("Client disconnected");
};
KxPublisher<String> remote = get().connect(String.class, getRemoteConnector(), discon).await();
RateMeasure ms = new RateMeasure("event rate");
remote.syncMap(string -> string.length()).syncMap(number -> number > 10 ? number : number).subscribe((str, err) -> {
if (isErrorOrComplete(err)) {
System.out.println("complete");
} else if (isError(err)) {
System.out.println("ERROR");
} else {
received.incrementAndGet();
ms.count();
}
});
while (true) {
Thread.sleep(100);
}
}
use of org.nustaq.kontraktor.Callback in project kontraktor by RuedigerMoeller.
the class TCPNIOKStreamsTest method testClient.
@Test
@Ignore
public void testClient() throws InterruptedException {
AtomicLong received = new AtomicLong(0);
Callback<ActorClientConnector> discon = (acc, err) -> {
System.out.println("Client disconnected");
};
KxPublisher<String> remote = get().connect(String.class, getRemoteConnector(), discon).await();
RateMeasure ms = new RateMeasure("event rate");
remote.subscribe((str, err) -> {
if (isErrorOrComplete(err)) {
System.out.println("complete e:" + err + " r:" + str);
} else if (isError(err)) {
System.out.println("ERROR " + err);
} else {
received.incrementAndGet();
ms.count();
}
});
while (true) {
Thread.sleep(100);
}
}
use of org.nustaq.kontraktor.Callback in project kontraktor by RuedigerMoeller.
the class TCPNIOKStreamsTest method testClient3.
// cleanup of async processors
@Test
// cleanup of async processors
@Ignore
public void testClient3() throws InterruptedException {
AtomicLong received = new AtomicLong(0);
Callback<ActorClientConnector> discon = (acc, err) -> {
System.out.println("Client disconnected");
};
KxPublisher<String> remote = get().connect(String.class, getRemoteConnector(), discon).await();
RateMeasure ms = new RateMeasure("event rate");
remote.map(string -> string.length()).map(number -> number > 10 ? number : number).subscribe((str, err) -> {
if (isComplete(err)) {
System.out.println("complete");
} else if (isError(err)) {
System.out.println("ERROR " + err);
} else {
received.incrementAndGet();
ms.count();
}
});
while (true) {
Thread.sleep(100);
}
}
use of org.nustaq.kontraktor.Callback in project kontraktor by RuedigerMoeller.
the class TCPNIOKStreamsTest method testClient2.
// slowdown
@Test
// slowdown
@Ignore
public void testClient2() throws InterruptedException {
AtomicLong received = new AtomicLong(0);
Callback<ActorClientConnector> discon = (acc, err) -> {
System.out.println("Client disconnected");
};
KxPublisher<String> remote = get().connect(String.class, getRemoteConnector(), discon).await();
RateMeasure ms = new RateMeasure("event rate");
remote.syncMap(string -> string.length()).syncMap(number -> number > 10 ? number : number).subscribe((str, err) -> {
if (isErrorOrComplete(err)) {
System.out.println("complete");
} else if (isError(err)) {
System.out.println("ERROR");
} else {
received.incrementAndGet();
ms.count();
try {
Thread.sleep(1);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
});
while (true) {
Thread.sleep(100);
}
}
Aggregations