Search in sources :

Example 1 with ObjectPublisher

use of org.nustaq.fastcast.api.util.ObjectPublisher 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 ObjectPublisher

use of org.nustaq.fastcast.api.util.ObjectPublisher in project fast-cast by RuedigerMoeller.

the class ConfigFilePublisher method main.

public static void main(String[] arg) throws Exception {
    // max 5 chars !
    FastCast.getFastCast().setNodeId("CPUB");
    // note this configuration is far below possible limits regarding throughput and rate
    if (!new File(CFG_FILE).exists()) {
        CFG_FILE = "./examples/" + CFG_FILE;
    }
    FastCast fc = FastCast.getFastCast().loadConfig(CFG_FILE);
    FCPublisher pub = FastCast.getFastCast().onTransport("default").publish("oneAndOnlyTopic");
    // use a helper for fast-serialized messages
    ObjectPublisher opub = new ObjectPublisher(pub);
    RateMeasure measure = new RateMeasure("msg/s");
    while (true) {
        measure.count();
        opub.sendObject(// all listeners should receive this (by specifying a nodeId, a specific subscriber can be targeted)
        null, // serializable object
        "Hello " + System.currentTimeMillis(), // allow for 'batching' several messages into one (will create slight latency)
        false);
    }
}
Also used : FastCast(org.nustaq.fastcast.api.FastCast) FCPublisher(org.nustaq.fastcast.api.FCPublisher) ObjectPublisher(org.nustaq.fastcast.api.util.ObjectPublisher) RateMeasure(org.nustaq.fastcast.util.RateMeasure) File(java.io.File)

Example 3 with ObjectPublisher

use of org.nustaq.fastcast.api.util.ObjectPublisher 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 4 with ObjectPublisher

use of org.nustaq.fastcast.api.util.ObjectPublisher 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)

Example 5 with ObjectPublisher

use of org.nustaq.fastcast.api.util.ObjectPublisher in project fast-cast by RuedigerMoeller.

the class SendReceive method sendUnreliable.

@Test
public void sendUnreliable() throws InterruptedException {
    initFC();
    final FCPublisher publish = fc.onTransport("default").publish("unreliable");
    final ObjectPublisher objectPublisher = new ObjectPublisher(publish).batchOnLimit(false);
    for (int i = 0; i < 100_000; i++) {
        objectPublisher.sendObject(null, new TestEchoServer.UnreliableMessage(i), true);
    }
}
Also used : ObjectPublisher(org.nustaq.fastcast.api.util.ObjectPublisher) Test(org.junit.Test)

Aggregations

ObjectPublisher (org.nustaq.fastcast.api.util.ObjectPublisher)8 FCPublisher (org.nustaq.fastcast.api.FCPublisher)5 ObjectSubscriber (org.nustaq.fastcast.api.util.ObjectSubscriber)5 RateMeasure (org.nustaq.fastcast.util.RateMeasure)3 FCSubscriber (org.nustaq.fastcast.api.FCSubscriber)2 File (java.io.File)1 Histogram (org.HdrHistogram.Histogram)1 Test (org.junit.Test)1 FastCast (org.nustaq.fastcast.api.FastCast)1 PublisherConf (org.nustaq.fastcast.config.PublisherConf)1