示例#1
0
 private void NotifySubscribers(OPSMessage newMessage)
 {
     foreach (Subscriber subscriber in subscribers)
     {
         if (subscriber.GetTopic().GetName().Equals(newMessage.GetTopicName()))
         {
             subscriber.NotifyNewOPSMessage(newMessage);
         }
     }
 }
示例#2
0
 public bool ApplyFilter(OPSMessage o)
 {
     foreach (IMessageFilter messageFilter in filters)
     {
         if (!messageFilter.ApplyFilter(o))
         {
             return(false);
         }
     }
     return(true);
 }
示例#3
0
 public bool ApplyFilter(OPSMessage o)
 {
     foreach (IMessageFilter messageFilter in filters)
     {
         if (!messageFilter.ApplyFilter(o))
         {
             return false;
         }
     }
     return true;
 }
示例#4
0
文件: Publisher.cs 项目: ghost66/ops
        protected void Write(OPSObject opsObject)
        {
            if (opsObject == null)
            {
                throw new CommException("Trying to send OPSObject that is null!");
            }

            if (sendDataHandler == null)
            {
                Init();
            }

            if (sendDataHandler == null)
            {
                return;
            }

            this.sampleTime2 = this.sampleTime1;
            this.sampleTime1 = System.DateTime.Now.Ticks;

            OPSMessage message = new OPSMessage();

            opsObject.SetKey(this.key);
            message.SetData(opsObject);
            message.SetPublicationID(this.currentPublicationID);
            message.SetTopicName(this.topic.GetName());
            message.SetPublisherName(this.name);

            //inProcessTransport.copyAndPutMessage(message);
            WriteByteBuffer buf = new WriteByteBuffer(this.bytes, Globals.MAX_SEGMENT_SIZE);

            try
            {
                OPSArchiverOut archiverOut = new OPSArchiverOut(buf, topic.GetOptNonVirt());

                archiverOut.Inout("message", message);

                // If o has spare bytes, write them to the end of the buf
                if (opsObject.spareBytes.Length > 0)
                {
                    buf.Write(opsObject.spareBytes, 0, opsObject.spareBytes.Length);
                }
                // Finish will fill in nrOf segments in all segments.
                buf.Finish();
                int sizeToSend = buf.Position();

                sendDataHandler.SendData(this.bytes, sizeToSend, this.topic);
            }
            catch (System.IO.IOException ex)
            {
                Logger.ExceptionLogger.LogException(ex);
            }
            IncCurrentPublicationID();
        }
示例#5
0
 protected override void Run()
 {
     keepRunning = true;
     while (keepRunning)
     {
         OPSMessage newMessage = TakeMessage();
         if (newMessage == null)
         {
             break;
         }
         newMessage.SetQosMask(1);
         NotifySubscribers(newMessage);
     }
 }
示例#6
0
        private void SendBytesToSubscribers(ReadByteBuffer readBuf)
        {
            OPSArchiverIn archiverIn = new OPSArchiverIn(readBuf, this.participant.getObjectFactory());
            OPSMessage    message    = null;

            // If the proper typesupport has not been added, the message may have content, but some fields may be null. How do we handle this
            // How do we make the user realize that he needs to add typesupport?
            message = (OPSMessage)archiverIn.Inout("message", message);

            //Console.WriteLine("Bytes received = " + bytesReceived);
            //Console.WriteLine("Bytes read     = " + readBuf.position());

            if (message == null)
            {
                Logger.ExceptionLogger.LogMessage(this.GetType().Name + ", message was unexpectedly null");
                return;
            }

            if (message.GetData() == null)
            {
                Logger.ExceptionLogger.LogMessage(this.GetType().Name + ", message.getData() was unexpectedly null");
                return;
            }

            CalculateAndSetSpareBytes(message, readBuf, FRAGMENT_HEADER_SIZE, bytesReceived);

            string IP   = "";
            int    port = 0;

            receiver.GetSource(ref IP, ref port);
            message.SetSource(IP, port);

            //TODO: error checking
            foreach (Subscriber subscriber in subscribers)
            {
                try
                {
                    subscriber.NotifyNewOPSMessage(message);
                } catch (Exception ex)
                {
                    Logger.ExceptionLogger.LogMessage(this.GetType().Name + ", Exception thrown in event notification thread " + ex.ToString());
                }
            }
        }
示例#7
0
        private void CalculateAndSetSpareBytes(OPSMessage message, ReadByteBuffer readBuf, int segmentPaddingSize, int bytesReceived)
        {
            //NOT needed since 'bytesReceived' already is compensated for all headers and 'readBuf' is all data except header data
            //// We must calculate how many unserialized segment headers we have and substract
            //// that total header size from the size of spareBytes.
            //int nrOfSerializedBytes = readBuf.Position();
            //int totalNrOfSegments = (int) (bytesReceived /fragmentSize);
            //int nrOfSerializedSegements = (int) (nrOfSerializedBytes /fragmentSize);
            //int nrOfUnserializedSegments = totalNrOfSegments - nrOfSerializedSegements;

            int nrOfSpareBytes = bytesReceived - readBuf.Position(); ///See comment above: -(nrOfUnserializedSegments * segmentPaddingSize);

            if (nrOfSpareBytes > 0)
            {
                message.GetData().spareBytes = new byte[nrOfSpareBytes];
                // This will read the rest of the bytes as raw bytes and put
                // them into spareBytes field of data.
                readBuf.ReadBytes(message.GetData().spareBytes);
            }
        }
示例#8
0
 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());
     }
 }
示例#9
0
 /// @param originalMessage will be copied and put on the underlying queue.
 public void CopyAndPutMessage(OPSMessage originalMessage)
 {
     PutMessage((OPSMessage)originalMessage.Clone());
 }
示例#10
0
 /// @param message will be out on the underlying queue
 public void PutMessage(OPSMessage message)
 {
     blockingQueue.Put(message);
 }
示例#11
0
文件: Subscriber.cs 项目: staxgr/ops
 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());
     }
 }
示例#12
0
文件: Publisher.cs 项目: staxgr/ops
        protected void Write(OPSObject opsObject)
        {
            if (opsObject == null)
            {
                throw new CommException("Trying to send OPSObject that is null!");
            }

            if (sendDataHandler == null)
            {
                Init();
            }

            if (sendDataHandler == null)
            {
                return;
            }

            this.sampleTime2 = this.sampleTime1;
            this.sampleTime1 = System.DateTime.Now.Ticks;

            OPSMessage message = new OPSMessage();
            opsObject.SetKey(this.key);
            message.SetData(opsObject);
            message.SetPublicationID(this.currentPublicationID);
            message.SetTopicName(this.topic.GetName());
            message.SetPublisherName(this.name);

            //inProcessTransport.copyAndPutMessage(message);
            WriteByteBuffer buf = new WriteByteBuffer(this.bytes, Globals.MAX_SEGMENT_SIZE);
            try
            {
                OPSArchiverOut archiverOut = new OPSArchiverOut(buf);

                archiverOut.Inout("message", message);

                // If o has spare bytes, write them to the end of the buf
                if (opsObject.spareBytes.Length > 0)
                {
                    buf.Write(opsObject.spareBytes, 0, opsObject.spareBytes.Length);
                }
                // Finish will fill in nrOf segments in all segments.
                buf.Finish();
                int sizeToSend = buf.Position();

                sendDataHandler.SendData(this.bytes, sizeToSend, this.topic);
            }
            catch (System.IO.IOException ex)
            {
                Logger.ExceptionLogger.LogException(ex);
            }
            IncCurrentPublicationID();
        }
示例#13
0
 private void NotifySubscribers(OPSMessage newMessage)
 {
     foreach (Subscriber subscriber in subscribers)
     {
         if(subscriber.GetTopic().GetName().Equals(newMessage.GetTopicName()))
         {
             subscriber.NotifyNewOPSMessage(newMessage);
         }
     }
 }
示例#14
0
 /// @param message will be out on the underlying queue
 public void PutMessage(OPSMessage message)
 {
     blockingQueue.Put(message);
 }
示例#15
0
 /// @param originalMessage will be copied and put on the underlying queue.
 public void CopyAndPutMessage(OPSMessage originalMessage)
 {
     PutMessage((OPSMessage) originalMessage.Clone());
 }
示例#16
0
        private void CalculateAndSetSpareBytes(OPSMessage message, ReadByteBuffer readBuf, int segmentPaddingSize, int bytesReceived)
        {
            //NOT needed since 'bytesReceived' already is compensated for all headers and 'readBuf' is all data except header data
            //// We must calculate how many unserialized segment headers we have and substract
            //// that total header size from the size of spareBytes.
            //int nrOfSerializedBytes = readBuf.Position();
            //int totalNrOfSegments = (int) (bytesReceived /fragmentSize);
            //int nrOfSerializedSegements = (int) (nrOfSerializedBytes /fragmentSize);
            //int nrOfUnserializedSegments = totalNrOfSegments - nrOfSerializedSegements;

            int nrOfSpareBytes = bytesReceived - readBuf.Position(); ///See comment above: -(nrOfUnserializedSegments * segmentPaddingSize);

            if (nrOfSpareBytes > 0)
            {
                message.GetData().spareBytes = new byte[nrOfSpareBytes];
                // This will read the rest of the bytes as raw bytes and put
                // them into spareBytes field of data.
                readBuf.ReadBytes(message.GetData().spareBytes);
            }
        }