use of org.nustaq.fastcast.api.util.ObjectSubscriber in project fast-cast by RuedigerMoeller.
the class Issue4 method initFC.
public void initFC() {
if (fc == null) {
fc = setupFC("t" + (int) (1000 * Math.random()), "stuff/sendreceive.kson");
FCPublisher rawPublisher = fc.onTransport("default").publish(fc.getPublisherConf("sendreceive"));
publisher = new ObjectPublisher(rawPublisher);
FCSubscriber sub = new ObjectSubscriber() {
int count = 0;
@Override
protected void objectReceived(String sender, long sequence, Object msg) {
if (msg instanceof String) {
System.out.println(fc.getNodeId() + " received: " + count);
count = 0;
} else {
count++;
}
}
@Override
public boolean dropped() {
System.out.println("FATAL ERROR. Enlarge send history");
System.exit(0);
return false;
}
@Override
public void senderTerminated(String senderNodeId) {
System.out.println(senderNodeId + " terminated");
}
@Override
public void senderBootstrapped(String receivesFrom, long seqNo) {
System.out.println("bootstrap " + receivesFrom);
}
};
fc.onTransport("default").subscribe(fc.getSubscriberConf("sendreceive"), sub);
}
}
use of org.nustaq.fastcast.api.util.ObjectSubscriber in project fast-cast by RuedigerMoeller.
the class AsyncLatPublisher method initFastCast.
public void initFastCast() throws Exception {
fastCast = FastCast.getFastCast();
fastCast.setNodeId("PUB");
fastCast.loadConfig(CFG_FILE_PATH);
pub = new ObjectPublisher(fastCast.onTransport("default").publish("stream"), AsyncLatMessage.class);
fastCast.onTransport("back").subscribe("back", new ObjectSubscriber(false, AsyncLatMessage.class) {
@Override
protected void objectReceived(String s, long l, Object o) {
if ("END".equals(o)) {
final Histogram oldHi = hi;
hi = new Histogram(TimeUnit.SECONDS.toNanos(2), 3);
// no lambdas to stay 1.7 compatible
// move printing out of the receiving thread
dumper.execute(new Runnable() {
@Override
public void run() {
oldHi.outputPercentileDistribution(System.out, 1000.0);
}
});
// hi.reset();
return;
}
final long value = System.nanoTime() - ((AsyncLatMessage) o).getSendTimeStampNanos();
if (value < 1_000_000_000)
hi.recordValue(value);
}
@Override
public boolean dropped() {
System.exit(-2);
return false;
}
});
}
Aggregations