00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
| using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using com.latencybusters.lbm;
public class late_join_receiver {
static void Main(String[] args) {
LBMContext ctx = null; /* Context object: container for UM "instance". */
LBMReceiver lateRcv = null; /* Receiver object: for sending messages. */
LBMReceiverCallback cb = new LBMReceiverCallback(onReceive); /* Wrapping the onReceive functor in a callback */
LBMSource early_src = null; /* Source object: for sending messages. */
ctx = new LBMContext();
try
{
LBMTopic srcTopic = null;
LBMSourceAttributes srcAttr = null;
srcAttr = new LBMSourceAttributes();
srcAttr.setValue("late_join", "1");
srcAttr.setValue("retransmit_retention_size_threshold", "1");
srcTopic = ctx.allocTopic("test.topic", srcAttr);
early_src = new LBMSource(ctx, srcTopic);
early_src.send(Encoding.ASCII.GetBytes("test"), 4, LBM.MSG_FLUSH | LBM.SRC_NONBLOCK);
}
catch (LBMException ex)
{
System.Console.Error.WriteLine("Error initializing LBM objects: " + ex.Message);
System.Environment.Exit(1);
}
{
LBMTopic topic = null;
topic = ctx.lookupTopic("test.topic");
lateRcv = new LBMReceiver(ctx, topic, onReceive, null, null);
}
Thread.Sleep(100);
try {
early_src.close();
lateRcv.close();
ctx.close();
}
catch(LBMException ex)
{
System.Console.Error.WriteLine("Error closing LBM objects: " + ex.Message);
System.Environment.Exit(1);
}
}
static int onReceive(Object cbArg, LBMMessage msg)
{
switch (msg.type())
{
case LBM.MSG_DATA:
if((msg.flags() & LBM.MSG_FLAG_OTR)==LBM.MSG_FLAG_OTR)
System.Console.Out.WriteLine("Processing OTR Message. SQN: " + msg.sequenceNumber());
else if((msg.flags() & LBM.MSG_FLAG_RETRANSMIT)==LBM.MSG_FLAG_RETRANSMIT)
System.Console.Out.WriteLine("Processing Late Join Message. SQN: " + msg.sequenceNumber());
else
System.Console.Out.WriteLine("Processing Normal Message. SQN: " + msg.sequenceNumber());
System.Console.Out.WriteLine("Msg Received: " + msg.dataString());
break;
case LBM.MSG_BOS:
System.Console.Out.WriteLine("[" + msg.topicName() + "][" + msg.source() + "], Beginning of Transport Session");
break;
case LBM.MSG_EOS:
System.Console.Out.WriteLine("[" + msg.topicName() + "][" + msg.source() + "], End of Transport Session");
break;
default:
System.Console.Out.WriteLine("Unknown lbm_msg_t type " + msg.type() + " [" + msg.topicName() + "][" + msg.source() + "]");
break;
}
System.Console.Out.Flush();
msg.dispose();
return 0;
}
}
|