Search in sources :

Example 1 with ObjectSubscriber

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;
        }
    });
}
Also used : ObjectPublisher(org.nustaq.fastcast.api.util.ObjectPublisher) RateMeasure(org.nustaq.fastcast.util.RateMeasure) ObjectSubscriber(org.nustaq.fastcast.api.util.ObjectSubscriber)

Example 2 with ObjectSubscriber

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;
        }
    });
}
Also used : SubscriberConf(org.nustaq.fastcast.config.SubscriberConf) ObjectSubscriber(org.nustaq.fastcast.api.util.ObjectSubscriber)

Example 3 with ObjectSubscriber

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;
        }
    });
}
Also used : ObjectSubscriber(org.nustaq.fastcast.api.util.ObjectSubscriber)

Example 4 with ObjectSubscriber

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();
}
Also used : FCPublisher(org.nustaq.fastcast.api.FCPublisher) ObjectPublisher(org.nustaq.fastcast.api.util.ObjectPublisher) ObjectSubscriber(org.nustaq.fastcast.api.util.ObjectSubscriber)

Example 5 with ObjectSubscriber

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);
    }
}
Also used : FCPublisher(org.nustaq.fastcast.api.FCPublisher) ObjectPublisher(org.nustaq.fastcast.api.util.ObjectPublisher) ObjectSubscriber(org.nustaq.fastcast.api.util.ObjectSubscriber) FCSubscriber(org.nustaq.fastcast.api.FCSubscriber)

Aggregations

ObjectSubscriber (org.nustaq.fastcast.api.util.ObjectSubscriber)7 ObjectPublisher (org.nustaq.fastcast.api.util.ObjectPublisher)5 FCPublisher (org.nustaq.fastcast.api.FCPublisher)3 FCSubscriber (org.nustaq.fastcast.api.FCSubscriber)2 Histogram (org.HdrHistogram.Histogram)1 SubscriberConf (org.nustaq.fastcast.config.SubscriberConf)1 RateMeasure (org.nustaq.fastcast.util.RateMeasure)1