コード例 #1
0
ファイル: McUdpSendDataHandler.cs プロジェクト: staxgr/ops
        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;
        }
コード例 #2
0
ファイル: TcpSendDataHandler.cs プロジェクト: staxgr/ops
        public override bool SendData(byte[] bytes, int size, Topic t)
        {
            ///TODO How to handle one slow receiver when others are fast
            /// A separate thread for each connection and buffers ??

            return SendData(bytes, size, sinkIP, t.GetPort());
        }
コード例 #3
0
ファイル: SendDataHandlerFactory.cs プロジェクト: staxgr/ops
        ///LA TODO Protection ?? What if several subscribers at the same time
        /// Not needed since all calls go through the participant which is synched
        public ISendDataHandler GetSendDataHandler(Topic t, Participant participant)
        {
            // In the case that we use the same port for several topics, we need to find the sender for the transport::address::port used
            string key = t.GetTransport() + "::" + t.GetDomainAddress() + "::" + t.GetPort();

            if (SendDataHandlers.ContainsKey(key))
            {
                return SendDataHandlers[key];
            }

            try
            {
                // Get the local interface, doing a translation from subnet if necessary
                string localIF = Domain.DoSubnetTranslation(participant.getDomain().GetLocalInterface());

                ISendDataHandler sender = null;
                if (t.GetTransport().Equals(Topic.TRANSPORT_MC))
                {
                    sender = new McSendDataHandler(t, localIF);
                }
                else if (t.GetTransport().Equals(Topic.TRANSPORT_TCP))
                {
                    sender = new TcpSendDataHandler(t, localIF);
                }
                if (sender != null)
                {
                    SendDataHandlers.Add(key, sender);
                    return sender;
                }

                // We don't want to add the udp handler to the handler list, so handle this last
                if (t.GetTransport().Equals(Topic.TRANSPORT_UDP))
                {
                    if (udpSendDataHandler == null)
                    {
                        // We have only one sender for all topics, so use the domain value for buffer size
                        udpSendDataHandler = new McUdpSendDataHandler(
                            participant.getDomain().GetOutSocketBufferSize(),
                            localIF);

                        // 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, udpSendDataHandler);

                        partInfoSub = new Subscriber(participant.CreateParticipantInfoTopic());
                        partInfoSub.newDataDefault += new NewDataDefaultEventHandler(partInfoListener.SubscriberNewData);
                        partInfoSub.Start();
                    }
                    return udpSendDataHandler;
                }

                throw new CommException("No such Transport " + t.GetTransport());
            }
            catch (System.IO.IOException ex)
            {
                throw new CommException("Error creating SendDataHandler. IOException -->" + ex.Message);
            }
        }
コード例 #4
0
ファイル: Publisher.cs プロジェクト: staxgr/ops
        public Publisher(Topic topic)
        {
            this.topic = topic;
            this.bytes = new byte[topic.GetSampleMaxSize()];

            this.participant = Participant.GetInstance(topic.GetDomainID(), topic.GetParticipantID());
            this.inProcessTransport = participant.GetInProcessTransport();
            Init();
        }
コード例 #5
0
ファイル: ReceiveDataHandler.cs プロジェクト: staxgr/ops
 public ReceiveDataHandler(Topic t, Participant part, IReceiver receiver)
 {
     topic = t;
     bytes = new byte[t.GetSampleMaxSize()];
     headerBytes = new byte[FRAGMENT_HEADER_SIZE];
     participant = part;
     fragmentSize = Globals.MAX_SEGMENT_SIZE;
     this.receiver = receiver;
 }
コード例 #6
0
ファイル: TopicInfoData.cs プロジェクト: staxgr/ops
 public TopicInfoData(Topic topic)
 {
     AppendType("TopicInfoData");
     name = topic.GetName();
     type = topic.GetTypeID();
     transport = topic.GetTransport();
     address = topic.GetDomainAddress();
     port = topic.GetPort();
     //keys;
 }
コード例 #7
0
ファイル: Subscriber.cs プロジェクト: staxgr/ops
 public Subscriber(Topic t)
 {
     if (t == null)
     {
         throw new OPSInvalidTopicException("Not possible to create Subscriber with null Topic!");
     }
     this.topic = t;
     this.participant = Participant.GetInstance(topic.GetDomainID(), topic.GetParticipantID());
     deadlineNotifier = DeadlineNotifier.GetInstance();
     inProcessTransport = participant.GetInProcessTransport();
 }
コード例 #8
0
        /// Protection is not needed since all calls go through the participant which is synched
        public ReceiveDataHandler GetReceiveDataHandler(Topic top, Participant participant)
        {
            // In the case that we use the same port for several topics, we need to find the receiver for the transport::address::port used
            string key = MakeKey(top);

            if (ReceiveDataHandlers.ContainsKey(key))
            {
                ReceiveDataHandler rdh = ReceiveDataHandlers[key];

                // Check if any of the topics have a sample size larger than MAX_SEGMENT_SIZE
                // This will lead to a problem when using the same port, if samples becomes > MAX_SEGMENT_SIZE
                if ((rdh.GetSampleMaxSize() > Globals.MAX_SEGMENT_SIZE) || (top.GetSampleMaxSize() > Globals.MAX_SEGMENT_SIZE))
                {
                    if (top.GetTransport().Equals(Topic.TRANSPORT_UDP))
                    {
                        Logger.ExceptionLogger.LogMessage("Warning: UDP transport is used with Topics with 'sampleMaxSize' > " + Globals.MAX_SEGMENT_SIZE);
                    }
                    else
                    {
                        Logger.ExceptionLogger.LogMessage("Warning: Same port (" + top.GetPort() + ") is used with Topics with 'sampleMaxSize' > " + Globals.MAX_SEGMENT_SIZE);
                    }
                }
                return rdh;
            }

            // Get the local interface, doing a translation from subnet if necessary
            string localIF = Domain.DoSubnetTranslation(participant.getDomain().GetLocalInterface());

            // Didn't exist, create one if transport is known
            if ( (top.GetTransport().Equals(Topic.TRANSPORT_MC)) || (top.GetTransport().Equals(Topic.TRANSPORT_TCP)) )
            {
                ReceiveDataHandlers.Add(key,
                    new ReceiveDataHandler(top, participant, ReceiverFactory.CreateReceiver(top, localIF)));
                return ReceiveDataHandlers[key];
            }
            else if (top.GetTransport().Equals(Topic.TRANSPORT_UDP))
            {
                IReceiver rec = ReceiverFactory.CreateReceiver(top, localIF);
                ReceiveDataHandlers.Add(key, new ReceiveDataHandler(top, participant, rec));

                participant.SetUdpTransportInfo(((UdpReceiver)rec).IP, ((UdpReceiver)rec).Port);

                return ReceiveDataHandlers[key];
            }
            return null;
        }
コード例 #9
0
        /// Protection is not needed since all calls go through the participant which is synched
        public void ReleaseReceiveDataHandler(Topic top, Participant participant)
        {
            // In the case that we use the same port for several topics, we need to find the receiver for the transport::address::port used
            string key = MakeKey(top);

            if (ReceiveDataHandlers.ContainsKey(key))
            {
                ReceiveDataHandler rdh = ReceiveDataHandlers[key];

                if (rdh.GetNrOfSubscribers() == 0)
                {
                    ReceiveDataHandlers.Remove(key);

                    if (rdh.GetTransport().Equals(Topic.TRANSPORT_UDP))
                    {
                        participant.SetUdpTransportInfo("", 0);
                    }
                }

            }
        }
コード例 #10
0
ファイル: ReceiverFactory.cs プロジェクト: staxgr/ops
 public static IReceiver CreateReceiver(Topic topic, String localInterface)
 {
     try
     {
         if (topic.GetTransport().Equals(Topic.TRANSPORT_MC))
         {
             return new MulticastReceiver(topic.GetDomainAddress(), topic.GetPort(), localInterface, topic.GetInSocketBufferSize());
         }
         else if (topic.GetTransport().Equals(Topic.TRANSPORT_TCP))
         {
             return new TcpClientReceiver(topic.GetDomainAddress(), topic.GetPort(), topic.GetInSocketBufferSize());
         }
         else if (topic.GetTransport().Equals(Topic.TRANSPORT_UDP))
         {
             return new UdpReceiver(0, localInterface, topic.GetInSocketBufferSize());
         }
     }
     catch (System.IO.IOException ex)
     {
         Logger.ExceptionLogger.LogMessage("CreateReceiver " + ex.ToString());
     }
     return null;
 }
コード例 #11
0
ファイル: Participant.cs プロジェクト: staxgr/ops
 public ReceiveDataHandler GetReceiveDataHandler(Topic topic)
 {
     ReceiveDataHandler rdh = this.receiveDataHandlerFactory.GetReceiveDataHandler(topic, this);
     if (rdh != null)
     {
         lock (partInfoData)
         {
             partInfoData.subscribeTopics.Add(new TopicInfoData(topic));
         }
     }
     return rdh;
 }
コード例 #12
0
 // Since topics can use the same port for transports multicast & tcp, or
 // use transport udp which always use a single ReceiveDataHandler,
 // we need to return the same ReceiveDataHandler in these cases.
 // Make a key with the transport info that uniquely defines the receiver.
 private string MakeKey(Topic top)
 {
     if (top.GetTransport().Equals(Topic.TRANSPORT_UDP))
     {
         return top.GetTransport();
     }
     else
     {
         return top.GetTransport() + "::" + top.GetDomainAddress() + "::" + top.GetPort();
     }
 }
コード例 #13
0
ファイル: Participant.cs プロジェクト: staxgr/ops
 public ISendDataHandler GetSendDataHandler(Topic topic)
 {
     return this.sendDataHandlerFactory.GetSendDataHandler(topic, this);
 }
コード例 #14
0
ファイル: McSendDataHandler.cs プロジェクト: staxgr/ops
 public override bool SendData(byte[] bytes, int size, Topic t)
 {
     return SendData(bytes, size, sinkIP, t.GetPort());
 }
コード例 #15
0
ファイル: Participant.cs プロジェクト: staxgr/ops
        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;
                    }
                }
            }
        }
コード例 #16
0
ファイル: Cheese.cs プロジェクト: staxgr/ops
 public CheesePublisher(Topic t)
     : base(t)
 {
     CheckTypeString(Cheese.GetTypeName());
 }
コード例 #17
0
ファイル: McSendDataHandler.cs プロジェクト: staxgr/ops
 public McSendDataHandler(Topic t, string localInterface)
 {
     sender = new MulticastSender(0, localInterface, 1, t.GetOutSocketBufferSize());     // Make ttl configurable
     sinkIP = InetAddress.GetByName(t.GetDomainAddress());
 }
コード例 #18
0
ファイル: ExtraAllt.cs プロジェクト: staxgr/ops
 public ExtraAlltSubscriber(Topic t)
     : base(t)
 {
     CheckTypeString(ExtraAllt.GetTypeName());
 }
コード例 #19
0
ファイル: PizzaData.cs プロジェクト: staxgr/ops
 public PizzaDataPublisher(Topic t)
     : base(t)
 {
     CheckTypeString(PizzaData.GetTypeName());
 }
コード例 #20
0
ファイル: CapricosaData.cs プロジェクト: staxgr/ops
 public CapricosaDataSubscriber(Topic t)
     : base(t)
 {
     CheckTypeString(CapricosaData.GetTypeName());
 }
コード例 #21
0
ファイル: ExtraAllt.cs プロジェクト: staxgr/ops
 public ExtraAlltPublisher(Topic t)
     : base(t)
 {
     CheckTypeString(ExtraAllt.GetTypeName());
 }
コード例 #22
0
ファイル: Participant.cs プロジェクト: staxgr/ops
 /**
  * Creates a Topic that can be used to Subscribe to the participant info data
  * @return a new Topic for the participant info data.
  */
 public Topic CreateParticipantInfoTopic()
 {
     Topic infoTopic = new Topic("ops.bit.ParticipantInfoTopic", domain.GetMetaDataMcPort(), "ops.ParticipantInfoData", domain.GetDomainAddress());
     infoTopic.SetDomainID(domainID);
     infoTopic.SetParticipantID(participantID);
     infoTopic.SetTransport(Topic.TRANSPORT_MC);
     return infoTopic;
 }
コード例 #23
0
ファイル: CapricosaData.cs プロジェクト: staxgr/ops
 public CapricosaDataPublisher(Topic t)
     : base(t)
 {
     CheckTypeString(CapricosaData.GetTypeName());
 }
コード例 #24
0
ファイル: TcpSendDataHandler.cs プロジェクト: staxgr/ops
 public TcpSendDataHandler(Topic t, string localInterface)
 {
     sender = new TcpServerSender(t.GetDomainAddress(), t.GetPort(), t.GetOutSocketBufferSize());
     sinkIP = InetAddress.GetByName(t.GetDomainAddress());
 }
コード例 #25
0
ファイル: TestData.cs プロジェクト: staxgr/ops
 public TestDataSubscriber(Topic t)
     : base(t)
 {
     CheckTypeString(TestData.GetTypeName());
 }
コード例 #26
0
ファイル: PizzaData.cs プロジェクト: staxgr/ops
 public PizzaDataSubscriber(Topic t)
     : base(t)
 {
     CheckTypeString(PizzaData.GetTypeName());
 }
コード例 #27
0
ファイル: TestData.cs プロジェクト: staxgr/ops
 public TestDataPublisher(Topic t)
     : base(t)
 {
     CheckTypeString(TestData.GetTypeName());
 }
コード例 #28
0
ファイル: Cheese.cs プロジェクト: staxgr/ops
 public CheeseSubscriber(Topic t)
     : base(t)
 {
     CheckTypeString(Cheese.GetTypeName());
 }