public override bool SendData(byte[] bytes, int size, Topic t) { bool result = true; if (this.topicSinkMap.ContainsKey(t.GetName())) { Dictionary<string, IpPortPair> dict = this.topicSinkMap[t.GetName()]; List<string> sinksToDelete = new List<string>(); // Loop over all sinks and send data, remove items that isn't "alive". foreach (KeyValuePair<string, IpPortPair> kvp in dict) { // Check if this sink is alive if (kvp.Value.IsAlive()) { result &= SendData(bytes, size, InetAddress.GetByName(kvp.Value.ip), kvp.Value.port); } else //Remove it. { sinksToDelete.Add(kvp.Key); } } foreach (string key in sinksToDelete) { dict.Remove(key); } } return result; }
public override bool SendData(byte[] bytes, int size, Topic t) { bool result = true; if (this.topicSinkMap.ContainsKey(t.GetName())) { Entry_T dict = this.topicSinkMap[t.GetName()]; List <string> sinksToDelete = new List <string>(); // Loop over all sinks and send data, remove items that isn't "alive". foreach (KeyValuePair <string, IpPortPair> kvp in dict.portMap) { // Check if this sink is alive if (kvp.Value.IsAlive()) { result &= SendData(bytes, size, InetAddress.GetByName(kvp.Value.Ip), kvp.Value.Port); } else //Remove it. { sinksToDelete.Add(kvp.Key); } } foreach (string key in sinksToDelete) { dict.portMap.Remove(key); } } return(result); }
public TopicInfoData(Topic topic) { AppendType("TopicInfoData"); name = topic.GetName(); type = topic.GetTypeID(); transport = topic.GetTransport(); address = topic.GetDomainAddress(); port = topic.GetPort(); //keys; }
public void ReleaseReceiveDataHandler(Topic topic) { this.receiveDataHandlerFactory.ReleaseReceiveDataHandler(topic, this); lock (partInfoData) { for (int i = 0; i < partInfoData.subscribeTopics.Count; i++) { if (partInfoData.subscribeTopics[i].name.Equals(topic.GetName())) { partInfoData.subscribeTopics.RemoveAt(i); break; } } } }
public void ReleaseSendDataHandler(Topic topic) { ///TODO this.sendDataHandlerFactory.ReleaseSendDataHandler(topic, this); lock (partInfoData) { for (int i = 0; i < partInfoData.publishTopics.Count; i++) { if (partInfoData.publishTopics[i].name.Equals(topic.GetName())) { partInfoData.publishTopics.RemoveAt(i); break; } } } }
public void NotifyNewOPSMessage(OPSMessage message) { //Check that this message is delivered on the same topic as this Subscriber use //This is needed when we allow several topics to use the same port if (message.GetTopicName() != topic.GetName()) { return; } ///For now we don't do this type check to minimize performance loss ////Check that the type of the delivered data can be interpreted as the type we expect in this Subscriber //if (message.GetData().GetTypesString().IndexOf(topic.GetTypeID()) < 0) //{ // return; //} if (messageFilters.ApplyFilter(message)) { this.message = message; this.NotifyNewOPSObject(message.GetData()); } }
private void PostSetup(Topic t, Participant participant, McUdpSendDataHandler sdh) { // If topic specifies a valid node address, add that as a static destination address for topic if (Ops.InetAddress.IsValidNodeAddress(t.GetDomainAddress())) { sdh.AddSink(t.GetName(), t.GetDomainAddress(), t.GetPort(), true); } else { if (partInfoListener == null) { // Setup a listener on the participant info data published by participants on our domain. // We use the information for topics with UDP as transport, to know the destination for UDP sends // ie. we extract ip and port from the information and add it to our McUdpSendDataHandler partInfoListener = new ParticipantInfoDataListener(participant, sdh); partInfoSub = new Subscriber(participant.CreateParticipantInfoTopic()); partInfoSub.newDataDefault += new NewDataDefaultEventHandler(partInfoListener.SubscriberNewData); partInfoSub.Start(); } } }
private void OnNewBytes(int size) { try { // Debug support if (Globals.TRACE_RECEIVE) { Logger.ExceptionLogger.LogMessage("TRACE: ReceiveDataHandler.OnNewBytes() [" + topic.GetName() + "], got " + size + " bytes"); } bytesReceived += size - headerBytes.Length; ReadByteBuffer readBuf = new ReadByteBuffer(headerBytes); if (readBuf.CheckProtocol()) { int nrOfFragments = readBuf.ReadInt(); int currentFragment = readBuf.ReadInt(); if (currentFragment == (nrOfFragments - 1) && currentFragment == expectedFragment) { // We have received a full message, let's deserialize it and send // it to subscribers. SendBytesToSubscribers(new ReadByteBuffer(bytes)); expectedFragment = 0; bytesReceived = 0; } else { if (currentFragment == expectedFragment) { expectedFragment++; } else { // Not so good. Sample will be lost here. if (Globals.REPORT_DATA_FRAGMENT_LOST_ERRORS) { Logger.ExceptionLogger.LogMessage(this.GetType().Name + ", Fragment error, sample lost"); } expectedFragment = 0; bytesReceived = 0; } } } } catch (System.IO.IOException) { expectedFragment = 0; } }