use of org.nustaq.fastcast.api.util.ObjectSubscriber in project fast-cast by RuedigerMoeller.
the class AsyncLatReceiver method initFastCast.
public void initFastCast() throws Exception {
fastCast = FastCast.getFastCast();
fastCast.setNodeId("SUB");
fastCast.loadConfig(AsyncLatPublisher.CFG_FILE_PATH);
backPub = new ObjectPublisher(fastCast.onTransport("back").publish("back"), AsyncLatMessage.class);
final RateMeasure measure = new RateMeasure("receive rate");
fastCast.onTransport("default").subscribe("stream", new ObjectSubscriber(AsyncLatMessage.class) {
int count = 0;
@Override
protected void objectReceived(String s, long l, Object o) {
if ("END".equals(o)) {
backPub.sendObject(null, o, true);
return;
}
AsyncLatReceiver.this.objectReceived(s, l, o);
if (++count == 10) {
// backtalk only 10%
backPub.sendObject(null, o, true);
count = 0;
}
measure.count();
}
@Override
public boolean dropped() {
System.exit(-2);
return false;
}
});
}
use of org.nustaq.fastcast.api.util.ObjectSubscriber in project fast-cast by RuedigerMoeller.
the class ProgrammaticConfiguredSubscriber method main.
public static void main(String[] arg) {
// 5 chars MAX !!
FastCast.getFastCast().setNodeId("SUBS");
ProgrammaticConfiguredPublisher.configureFastCast();
FastCast.getFastCast().onTransport("default").subscribe(// listen to topic 1
new SubscriberConf(1).receiveBufferPackets(// how many packets to buffer in case of a loss+retransmission
20000), new ObjectSubscriber() {
long lastMsg = System.currentTimeMillis();
int msgReceived = 0;
@Override
protected void objectReceived(String sender, long sequence, Object msg) {
msgReceived++;
if (System.currentTimeMillis() - lastMsg > 1000) {
System.out.println("received from " + sender + " number of msg " + msgReceived);
System.out.println("current: " + msg);
lastMsg = System.currentTimeMillis();
msgReceived = 0;
}
}
@Override
public boolean dropped() {
System.out.println("Fatal: could not keep up with send rate. exiting");
System.exit(0);
// do not attempt resync
return false;
}
});
}
use of org.nustaq.fastcast.api.util.ObjectSubscriber in project fast-cast by RuedigerMoeller.
the class ConfigFileSubscriber method main.
public static void main(String[] arg) throws Exception {
// 5 chars MAX !!
FastCast.getFastCast().setNodeId("csub");
FastCast.getFastCast().loadConfig(ConfigFilePublisher.CFG_FILE).onTransport("default").subscribe("oneAndOnlyTopic", new ObjectSubscriber() {
long lastMsg = System.currentTimeMillis();
int msgReceived = 0;
@Override
protected void objectReceived(String sender, long sequence, Object msg) {
msgReceived++;
if (System.currentTimeMillis() - lastMsg > 1000) {
System.out.println("received from " + sender + " number of msg " + msgReceived);
System.out.println("current: " + msg);
lastMsg = System.currentTimeMillis();
msgReceived = 0;
}
}
@Override
public boolean dropped() {
System.out.println("Fatal: could not keep up with send rate. exiting");
System.exit(0);
// do not attempt resync
return false;
}
});
}
use of org.nustaq.fastcast.api.util.ObjectSubscriber in project fast-cast by RuedigerMoeller.
the class TestEchoServer method startTestTopic.
public static void startTestTopic(FastCast fc, final long startUpTime) {
fc.onTransport("default").subscribe("test", new ObjectSubscriber() {
@Override
protected void objectReceived(String sender, long sequence, Object msg) {
System.out.println("received Object:" + msg);
}
});
FCPublisher testPublisher = fc.onTransport("default").publish("test");
final ObjectPublisher objectPublisher = new ObjectPublisher(testPublisher);
new Thread("sender") {
public void run() {
while (true) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
objectPublisher.sendObject(null, new SampleBroadcast(startUpTime), true);
}
}
}.start();
}
use of org.nustaq.fastcast.api.util.ObjectSubscriber in project fast-cast by RuedigerMoeller.
the class Issue4_Slow method initFC.
public void initFC() {
if (fc == null) {
fc = setupFC("t" + (int) (1000 * Math.random()), "stuff/sendreceive.kson");
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 {
Object[] i_time = (Object[]) msg;
System.out.println(fc.getNodeId() + " received " + i_time[0] + " delay: " + (System.currentTimeMillis() - (Long) i_time[1]));
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);
FCPublisher rawPublisher = fc.onTransport("default").publish(fc.getPublisherConf("sendreceive"));
publisher = new ObjectPublisher(rawPublisher);
}
}
Aggregations