public void AddValueSetEntry(ValueSetEntry valueSetEntry, IElementSet elementSet)
        {
            // add the element set (before adding the entry in case it
            // gets sent right away)
            if (elementSetsPut.Contains(elementSet.ID) == false)
            {
                elementSetsPut.Add(elementSet.ID);
                var elementSetMap = client.getMap<String, ElementSetEntry>("elementSet");
                elementSetMap.put(elementSet.ID, new ElementSetEntry(elementSet));
            }

            var queueValueSet = client.getQueue<ValueSetEntry>("valueSet");

            // POLLING WITH EXP BACKOFF - too much backoff to keep the queue filled with i1c200p1
            /*int delay = 2000;
            while (true)
            {
                bool inserted = queueValueSet.offer(valueSetEntry);
                if (inserted == true)
                {
                    break;
                }
                else
                {
                    // if the queue is full then the instance is overloaded so
                    // back off for awhile
                    this.traceFile.Append(String.Format("Waiting ({0}) To Insert ValueSet: {1}", delay, valueSetEntry.ToString()));
                    System.Threading.Thread.Sleep(delay);
                    delay *= 2;
                }
            }*/

            // OR

            // blocking put operation so that the put goes through as soon as there
            // is space
            queueValueSet.put(valueSetEntry);
        }
        public void OnEvent(IEvent e)
        {
            try
            {
                traceFile.Append("OnEvent:From:" + e.Sender.ModelID);

                var component = e.Sender;

                // look through all the input links and call getvalues on all input
                // links connected to the event's sender component
                foreach (DataInputLink link in dataInputLinks)
                {
                    // see if this link is from the component that raised the event
                    if (link.link.SourceComponent.ModelID == component.ModelID)
                    {
                        // get the new valueset
                        var valueSet = e.Sender.GetValues(e.SimulationTime, link.link.ID);

                        // log it
                        traceFile.Append("OnEvent:ValueSet(" + valueSet.Count + ")");

                        // create a value set entry
                        var scalarSet = (ScalarSet)valueSet;
                        var values = scalarSet.data;
                        var entry = new ValueSetEntry(webServiceManager.FindServiceIdForQuantity(link.link.SourceQuantity.ID), link.link.SourceQuantity.ID, link.link.SourceElementSet.ID, e.SimulationTime, scenarioId, values, true);

                        // measure how long it takes to insert the value set
                        var insertStopwatch = Stopwatch.StartNew();

                        // inser the value set
                        AddValueSetEntry(entry, link.link.SourceElementSet);

                        // record the insert time
                        statistics.Add("EntryInsertTimeMS", insertStopwatch.ElapsedMilliseconds);

                        // log the insert time
                        traceFile.Append("EntryInsertTimeMS:" + insertStopwatch.ElapsedMilliseconds);
                    }
                }
            }
            catch (Exception exception)
            {
                var message = "Exception in DataCollectorComponent:OnEvent:" + e;
                throw new Exception(message, exception);
            }
        }
 public static string CreateKey(ValueSetEntry bufferEntry)
 {
     return CreateKey(bufferEntry.WebServiceId, bufferEntry.QuantityId, bufferEntry.ElementSetId, bufferEntry.TimeStamp, bufferEntry.ScenarioId);
 }