static void Main(string[] args) { OsplConfiguration.SetOsplConfiguration(); DDSEntityManager mgr = new DDSEntityManager("HelloWorld"); String partitionName = "HelloWorld example"; // create Domain Participant mgr.createParticipant(partitionName); // create Type MsgTypeSupport msgTS = new MsgTypeSupport(); mgr.registerType(msgTS); // create Topic mgr.createTopic("HelloWorldData_Msg"); // create Subscriber mgr.createSubscriber(); // create DataReader mgr.createReader(false); IDataReader dreader = mgr.getReader(); MsgDataReader HelloWorldDataReader = dreader as MsgDataReader; Msg[] msgSeq = null; DDS.SampleInfo[] infoSeq = null; Boolean terminate = false; ReturnCode status; Console.WriteLine("=== [Subscriber] Ready ..."); int count = 0; while (!terminate && count < 1500) { status = HelloWorldDataReader.Take(ref msgSeq, ref infoSeq, Length.Unlimited, SampleStateKind.Any, ViewStateKind.Any, InstanceStateKind.Any); ErrorHandler.checkStatus(status, "DataReader.Take"); for (int i = 0; i < msgSeq.Length; i++) { if (infoSeq[i].ValidData) { Console.WriteLine("=== [Subscriber] message received :"); Console.WriteLine(" userID : {0}", msgSeq[i].userID); Console.WriteLine(" Message : \"" + msgSeq[i].message + "\""); terminate = true; } } status = HelloWorldDataReader.ReturnLoan(ref msgSeq, ref infoSeq); ErrorHandler.checkStatus(status, "DataReader.ReturnLoan"); Thread.Sleep(200); ++count; } Thread.Sleep(2); // clean up mgr.getSubscriber().DeleteDataReader(HelloWorldDataReader); mgr.deleteSubscriber(); mgr.deleteTopic(); mgr.deleteParticipant(); }
static void Main(string[] args) { if (args.Length != 1) { Console.WriteLine("Insufficient number of arguments."); usage(); Environment.Exit(-1); } else { DDSEntityManager mgr = new DDSEntityManager("Durability"); String partitionName = "Durability Example"; String durabilityKind = args[0]; // create Domain Participant mgr.createParticipant(partitionName); // set the durability kind mgr.setDurabilityKind(durabilityKind); // create Type MsgTypeSupport msgTS = new MsgTypeSupport(); mgr.registerType(msgTS); // create Topic mgr.createTopic("DurabilityData_Msg"); // create Subscriber mgr.createSubscriber(); mgr.createReader(false); IDataReader dreader = mgr.getReader(); MsgDataReader DurabilityDataReader = dreader as MsgDataReader; Msg[] msgSeq = null; DDS.SampleInfo[] infoSeq = null; Boolean terminate = false; ReturnCode status; Console.WriteLine("=== [Subscriber] Ready ..."); while (!terminate) { status = DurabilityDataReader.Take(ref msgSeq, ref infoSeq, Length.Unlimited, SampleStateKind.Any, ViewStateKind.Any, InstanceStateKind.Any); ErrorHandler.checkStatus(status, "DataReader.Take"); for (int i = 0; i < msgSeq.Length; i++) { if (infoSeq[i].ValidData) { Console.WriteLine("{0} : {1}", msgSeq[i].id, msgSeq[i].content); if (msgSeq[i].content.Equals("9")) { terminate = true; break; } } } status = DurabilityDataReader.ReturnLoan(ref msgSeq, ref infoSeq); ErrorHandler.checkStatus(status, "MsgDataReader.ReturnLoan"); } // clean up mgr.getSubscriber().DeleteDataReader(DurabilityDataReader); mgr.deleteSubscriber(); mgr.deleteTopic(); mgr.deleteParticipant(); } }
static void Main(string[] args) { if (args.Length != 1) { Console.WriteLine("Insufficient number of arguments."); usage(); } else { DDSEntityManager mgr = new DDSEntityManager("Durability"); String partitionName = "Durability Example"; DDS.Duration timeout = new DDS.Duration(40, 0); ReturnCode status; String durabilityKind = args[0]; // create Domain Participant mgr.createParticipant(partitionName); // set the durability kind mgr.setDurabilityKind(durabilityKind); // create Type MsgTypeSupport msgTS = new MsgTypeSupport(); mgr.registerType(msgTS); // create Topic if (args[0].Equals("persistent")) { mgr.createTopic("PersistentCSDurabilityData_Msg"); } else { mgr.createTopic("CSDurabilityData_Msg"); } // create Subscriber mgr.createSubscriber(); mgr.createReader(false); IDataReader dreader = mgr.getReader(); MsgDataReader DurabilityDataReader = dreader as MsgDataReader; status = DurabilityDataReader.WaitForHistoricalData(timeout); ErrorHandler.checkStatus(status, "DurabilityDataReader.WaitForHistoricalData"); Msg[] msgSeq = null; DDS.SampleInfo[] infoSeq = null; Boolean terminate = false; Console.WriteLine("=== [Subscriber] Ready ..."); while (!terminate) { status = DurabilityDataReader.Take(ref msgSeq, ref infoSeq, Length.Unlimited, SampleStateKind.Any, ViewStateKind.Any, InstanceStateKind.Any); ErrorHandler.checkStatus(status, "DataReader.Take"); for (int i = 0; i < msgSeq.Length; i++) { if (infoSeq[i].ValidData) { Console.WriteLine(msgSeq[i].content); if (msgSeq[i].content.Equals("9")) { terminate = true; break; } } } status = DurabilityDataReader.ReturnLoan(ref msgSeq, ref infoSeq); ErrorHandler.checkStatus(status, "MsgDataReader.ReturnLoan"); } // For single process mode wait some time to ensure persistent data is stored to disk Thread.Sleep(2000); // clean up mgr.getSubscriber().DeleteDataReader(DurabilityDataReader); mgr.deleteSubscriber(); mgr.deleteTopic(); mgr.deleteParticipant(); } }