Esempio n. 1
0
        /// <summary>
        /// Schedules transfer unit provided for sending
        /// </summary>
        /// <param name="tu"></param>
        public void sendTransferUnit(TransferUnit tu)
        {
            if (!is_running)
            {
                throw new Exception("Sending of messages has been interrupted. Probably no receiver");
            }
            bool should_yeld;

            //try {
            lock (transfer_units_queue) {
                transfer_units_queue.Enqueue(tu);
                should_yeld = shouldYeld();
                if (transfer_units_queue.Count > MAX_QUEUE_LENGTH)
                {
                    should_yeld = true;
                }
            }
            //} catch (System.AccessViolationException e) {
            //    Console.WriteLine(e);
            //    should_yeld = true;
            //}
            if (should_yeld)
            {
                Thread.Sleep(YELD_PERIOD_TIME);
            }
        }
Esempio n. 2
0
 /// <summary>
 /// This method loads into current transfer unit vaule of fields from transfer unit specified in parameters.
 /// In case there is a field with the same name in current transfer unit its value will be overwritten.
 /// </summary>
 /// <param name="field_names">list of filed names to load</param>
 /// <param name="prefix">prefix to append to filed name in new transfer unit. For example: prefix="file." then field "name" will be stored as "file.name"</param>
 /// <param name="tu"> transfer unit from where to load fields</param>
 public void loadFields(IEnumerable <string> field_names, string prefix, TransferUnit tu)
 {
     foreach (String key in field_names)
     {
         try {
             field_storage.Add(prefix + key, tu[key]);
         } catch (ArgumentException) {
             Console.WriteLine("The field [" + prefix + key + "] has been overwritten");
             field_storage[prefix + key] = tu[key];
         }
     }
 }
Esempio n. 3
0
 /// <summary>
 /// This method loads into current transfer unit value of fields from the transfer unit specified in parameters.
 /// In case there is a field with the same name in current transfer unit its value will be overwritten.
 /// </summary>
 /// <param name="prefix">prefix to append to filed name in new transfer unit. For example: prefix="file" then field "name" will be stored as "file.name"</param>
 /// <param name="tu"> transfer unit from where to load fields</param>
 public void loadAllFields(string prefix, TransferUnit tu)
 {
     loadFields(tu.field_storage.Keys, prefix, tu);
     //foreach (String key in tu.field_storage.Keys) {
     //    try {
     //        field_storage.Add(key, tu[key]);
     //    } catch (ArgumentException) {
     //        Console.WriteLine("The field [" + key + "] has been overwritten");
     //        field_storage[key] = tu[key];
     //    }
     //}
 }
Esempio n. 4
0
        /// <summary>
        /// Tries to create a block of transfer units
        /// </summary>
        /// <returns>null when nothing to send. Or array of TranferUnits to send</returns>
        private Queue <TransferUnit> getBlockToSend()
        {
            //check how many tu-s we have
            int queue_count = transfer_units_blocking_queue.Count;

            if (queue_count <= 0)
            {
                return(null);
            }
            Queue <TransferUnit> tu_block = new Queue <TransferUnit>(queue_count + 1);

            for (int i = 0; (i < MAX_SEND_BLOCK_SIZE) && (i < queue_count); i++)
            {
                //we don't expect it to block here since it is guaranteed that we have enough tu-s
                TransferUnit tu = (TransferUnit)transfer_units_blocking_queue.Dequeue(MAX_WAIT_FOR_BLOCK_FILL_TIMEOUT);
                tu_block.Enqueue(tu);
            }
            return(tu_block);
        }
Esempio n. 5
0
        private void ThreadJob()
        {
            int fail_count = 0;

            while (keep_running)
            {
                try {
                    TransferUnit tu = (TransferUnit)blocking_queue.Dequeue();
                    _receiveTransferUnit(tu);
                } catch (Exception e) {
                    Console.WriteLine("Exception while processing received information.");
                    Console.WriteLine(e);
                    fail_count++;
                    if (fail_count >= MAX_PROCESSING_FAIL_COUNT)
                    {
                        Console.WriteLine("Error count: " + fail_count + " is too high. Processing stopped.");
                        break;
                    }
                }
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Schedules transfer unit for sending.
        /// Sending of transfer units should be enabled  by enableTransferUnitSend before sending.
        /// Any thread that attemts to send something before enabling will be blacklisted.
        /// </summary>
        /// <param name="tu"></param>
        public void sendTransferUnit(TransferUnit tu)
        {
            if (!sending_enabled)
            {
                Console.WriteLine("Sending is not enabled. Blacklisting current thread ID=" + blacklistCurrentThread());
                return;
            }
            if (!is_running)
            {
                throw new Exception("Sending of messages has been interrupted. Probably no receiver");
            }

            try {
                transfer_units_blocking_queue.Enqueue(tu, TU_BUFFER_TIMEOUT);
            } catch (QueueTimeoutException qe) {
                throw new ProcessingException("Queueing timeout. Sending of messages has been interrupted. Probably no receiver", qe);
            }
            catch (AccessViolationException ave) {
                Console.WriteLine("++++++++++++++++++++++++++++++++++++Access violation++++++++++++++++++++++++++++++++");
                //Console.WriteLine("Blacklisting current thread ID=" + blacklistCurrentThread()+" due to memory access error");
                Console.WriteLine(ave);
            }
        }
Esempio n. 7
0
 public TransferUnit(TransferUnit tu)
 {
     field_storage = new SortedDictionary <string, object>(tu.field_storage);
 }