Example #1
0
        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();
        }