Esempio n. 1
0
 public EventBean GetFirstNthValue(int index)
 {
     if (index < 0)
     {
         return(null);
     }
     if (RefSet.IsEmpty())
     {
         return(null);
     }
     if (index >= RefSet.Count)
     {
         return(null);
     }
     if (_array == null)
     {
         InitArray();
     }
     return(_array[index]);
 }
Esempio n. 2
0
 /// <param name="maxSize">
 /// the maximum size of the cache before returning. May be -1
 /// to evict even 0-sized elements.
 /// </param>
 private void TrimToSize(int maxSize)
 {
     while (true)
     {
         K key;
         V value;
         lock (this)
         {
             if (size < 0 || (map.IsEmpty() && size != 0))
             {
                 throw new InvalidOperationException(GetType().FullName + ".sizeOf() is reporting inconsistent results!"
                                                     );
             }
             if (size <= maxSize)
             {
                 break;
             }
             // BEGIN LAYOUTLIB CHANGE
             // get the last item in the linked list.
             // This is not efficient, the goal here is to minimize the changes
             // compared to the platform version.
             KeyValuePair <K, V> toEvict = null;
             foreach (KeyValuePair <K, V> entry in map.EntrySet())
             {
                 toEvict = entry;
             }
             // END LAYOUTLIB CHANGE
             if (toEvict == null)
             {
                 break;
             }
             key   = toEvict.Key;
             value = toEvict.Value;
             Sharpen.Collections.Remove(map, key);
             size -= SafeSizeOf(key, value);
             evictionCount++;
         }
         EntryRemoved(true, key, value, null);
     }
 }
		/// <exception cref="System.IO.IOException"></exception>
		private void ReadAdvertisedRefsImpl()
		{
			LinkedHashMap<string, Ref> avail = new LinkedHashMap<string, Ref>();
			for (; ; )
			{
				string line;
				try
				{
					line = pckIn.ReadString();
				}
				catch (EOFException eof)
				{
					if (avail.IsEmpty())
					{
						throw NoRepository();
					}
					throw;
				}
				if (line == PacketLineIn.END)
				{
					break;
				}
				if (line.StartsWith("ERR "))
				{
					// This is a customized remote service error.
					// Users should be informed about it.
					throw new RemoteRepositoryException(uri, Sharpen.Runtime.Substring(line, 4));
				}
				if (avail.IsEmpty())
				{
					int nul = line.IndexOf('\0');
					if (nul >= 0)
					{
						// The first line (if any) may contain "hidden"
						// capability values after a NUL byte.
						foreach (string c in Sharpen.Runtime.Substring(line, nul + 1).Split(" "))
						{
							remoteCapablities.AddItem(c);
						}
						line = Sharpen.Runtime.Substring(line, 0, nul);
					}
				}
				string name = Sharpen.Runtime.Substring(line, 41, line.Length);
				if (avail.IsEmpty() && name.Equals("capabilities^{}"))
				{
					// special line from git-receive-pack to show
					// capabilities when there are no refs to advertise
					continue;
				}
				ObjectId id = ObjectId.FromString(Sharpen.Runtime.Substring(line, 0, 40));
				if (name.Equals(".have"))
				{
					additionalHaves.AddItem(id);
				}
				else
				{
					if (name.EndsWith("^{}"))
					{
						name = Sharpen.Runtime.Substring(name, 0, name.Length - 3);
						Ref prior = avail.Get(name);
						if (prior == null)
						{
							throw new PackProtocolException(uri, MessageFormat.Format(JGitText.Get().advertisementCameBefore
								, name, name));
						}
						if (prior.GetPeeledObjectId() != null)
						{
							throw DuplicateAdvertisement(name + "^{}");
						}
						avail.Put(name, new ObjectIdRef.PeeledTag(RefStorage.NETWORK, name, prior.GetObjectId
							(), id));
					}
					else
					{
						Ref prior = avail.Put(name, new ObjectIdRef.PeeledNonTag(RefStorage.NETWORK, name
							, id));
						if (prior != null)
						{
							throw DuplicateAdvertisement(name);
						}
					}
				}
			}
			Available(avail);
		}
Esempio n. 4
0
        private static void AnalyzeInNodeMultiIndex(ExprInNode inNode, QueryGraph queryGraph)
        {
            ExprNode[] setExpressions = GetInNodeSetExpressions(inNode);
            if (setExpressions.Length == 0)
            {
                return;
            }

            var perStreamExprs = new LinkedHashMap <int?, IList <ExprNode> >();

            foreach (ExprNode exprNodeSet in setExpressions)
            {
                if (!(exprNodeSet is ExprIdentNode))
                {
                    continue;
                }
                var setIdent = (ExprIdentNode)exprNodeSet;
                AddToList(setIdent.StreamId, setIdent, perStreamExprs);
            }
            if (perStreamExprs.IsEmpty())
            {
                return;
            }

            var testExpr     = inNode.ChildNodes[0];
            var testExprType = testExpr.ExprEvaluator.ReturnType.GetBoxedType();

            if (perStreamExprs.Count > 1)
            {
                return;
            }
            var entry = perStreamExprs.First();

            ExprNode[] exprNodes = ExprNodeUtility.ToArray(entry.Value);
            foreach (ExprNode node in exprNodes)
            {
                var exprType = node.ExprEvaluator.ReturnType;
                if (exprType.GetBoxedType() != testExprType)
                {
                    return;
                }
            }

            int?testStreamNum;
            int setStream = entry.Key.Value;

            if (!(testExpr is ExprIdentNode))
            {
                EligibilityDesc eligibility = EligibilityUtil.VerifyInputStream(testExpr, setStream);
                if (!eligibility.Eligibility.IsEligible())
                {
                    return;
                }
                if (eligibility.Eligibility == Eligibility.REQUIRE_ONE && setStream == eligibility.StreamNum)
                {
                    return;
                }
                testStreamNum = eligibility.StreamNum;
            }
            else
            {
                testStreamNum = ((ExprIdentNode)testExpr).StreamId;
            }

            if (testStreamNum == null)
            {
                queryGraph.AddInSetMultiIndexUnkeyed(testExpr, setStream, exprNodes);
            }
            else
            {
                if (testStreamNum.Equals(entry.Key))
                {
                    return;
                }
                queryGraph.AddInSetMultiIndex(testStreamNum.Value, testExpr, setStream, exprNodes);
            }
        }
Esempio n. 5
0
        public static SubordPropPlan GetJoinProps(
            ExprNode filterExpr,
            int outsideStreamCount,
            EventType[] allStreamTypesZeroIndexed,
            ExcludePlanHint excludePlanHint)
        {
            // No filter expression means full table scan
            if (filterExpr == null) {
                return new SubordPropPlan();
            }

            // analyze query graph
            var queryGraph = new QueryGraphForge(outsideStreamCount + 1, excludePlanHint, true);
            FilterExprAnalyzer.Analyze(filterExpr, queryGraph, false);

            // Build a list of streams and indexes
            var joinProps = new LinkedHashMap<string, SubordPropHashKeyForge>();
            var rangeProps = new LinkedHashMap<string, SubordPropRangeKeyForge>();
            IDictionary<QueryGraphValueEntryCustomKeyForge, QueryGraphValueEntryCustomOperationForge> customIndexOps =
                EmptyDictionary<QueryGraphValueEntryCustomKeyForge, QueryGraphValueEntryCustomOperationForge>.Instance;

            for (var stream = 0; stream < outsideStreamCount; stream++) {
                var lookupStream = stream + 1;

                var queryGraphValue = queryGraph.GetGraphValue(lookupStream, 0);
                var hashKeysAndIndexes = queryGraphValue.HashKeyProps;

                // determine application functions
                foreach (var item in queryGraphValue.Items) {
                    if (item.Entry is QueryGraphValueEntryCustomForge) {
                        if (customIndexOps.IsEmpty()) {
                            customIndexOps =
                                new Dictionary<QueryGraphValueEntryCustomKeyForge,
                                    QueryGraphValueEntryCustomOperationForge>();
                        }

                        var custom = (QueryGraphValueEntryCustomForge) item.Entry;
                        custom.MergeInto(customIndexOps);
                    }
                }

                // handle key-lookups
                var keyPropertiesJoin = hashKeysAndIndexes.Keys;
                var indexPropertiesJoin = hashKeysAndIndexes.Indexed;
                if (!keyPropertiesJoin.IsEmpty()) {
                    if (keyPropertiesJoin.Count != indexPropertiesJoin.Length) {
                        throw new IllegalStateException(
                            "Invalid query key and index property collection for stream " + stream);
                    }

                    for (var i = 0; i < keyPropertiesJoin.Count; i++) {
                        QueryGraphValueEntryHashKeyedForge keyDesc = keyPropertiesJoin[i];
                        var compareNode = keyDesc.KeyExpr;

                        var keyPropType = compareNode.Forge.EvaluationType.GetBoxedType();
                        var indexedPropType = allStreamTypesZeroIndexed[0]
                            .GetPropertyType(indexPropertiesJoin[i])
                            .GetBoxedType();
                        var coercionType = indexedPropType;
                        if (keyPropType != indexedPropType) {
                            coercionType = keyPropType.GetCompareToCoercionType(indexedPropType);
                        }

                        SubordPropHashKeyForge desc;
                        if (keyPropertiesJoin[i] is QueryGraphValueEntryHashKeyedForgeExpr) {
                            var keyExpr = (QueryGraphValueEntryHashKeyedForgeExpr) keyPropertiesJoin[i];
                            var keyStreamNum = keyExpr.IsRequiresKey ? (int?) stream : null;
                            desc = new SubordPropHashKeyForge(keyDesc, keyStreamNum, coercionType);
                        }
                        else {
                            var prop = (QueryGraphValueEntryHashKeyedForgeProp) keyDesc;
                            desc = new SubordPropHashKeyForge(prop, stream, coercionType);
                        }

                        joinProps.Put(indexPropertiesJoin[i], desc);
                    }
                }

                // handle range lookups
                var rangeKeysAndIndexes = queryGraphValue.RangeProps;
                var rangeIndexes = rangeKeysAndIndexes.Indexed;
                var rangeDescs = rangeKeysAndIndexes.Keys;
                if (rangeDescs.IsEmpty()) {
                    continue;
                }

                // get all ranges lookups
                var count = -1;
                foreach (var rangeDesc in rangeDescs) {
                    count++;
                    var rangeIndexProp = rangeIndexes[count];

                    var subqRangeDesc = rangeProps.Get(rangeIndexProp);

                    // other streams may specify the start or end endpoint of a range, therefore this operation can be additive
                    if (subqRangeDesc != null) {
                        if (subqRangeDesc.RangeInfo.Type.IsRange()) {
                            continue;
                        }

                        // see if we can make this additive by using a range
                        var relOpOther = (QueryGraphValueEntryRangeRelOpForge) subqRangeDesc.RangeInfo;
                        var relOpThis = (QueryGraphValueEntryRangeRelOpForge) rangeDesc;

                        var opsDesc = QueryGraphRangeUtil.GetCanConsolidate(relOpThis.Type, relOpOther.Type);
                        if (opsDesc != null) {
                            ExprNode start;
                            ExprNode end;
                            if (!opsDesc.IsReverse) {
                                start = relOpOther.Expression;
                                end = relOpThis.Expression;
                            }
                            else {
                                start = relOpThis.Expression;
                                end = relOpOther.Expression;
                            }

                            var allowRangeReversal = relOpOther.IsBetweenPart && relOpThis.IsBetweenPart;
                            var rangeIn = new QueryGraphValueEntryRangeInForge(
                                opsDesc.Type,
                                start,
                                end,
                                allowRangeReversal);

                            var indexedPropType = allStreamTypesZeroIndexed[0]
                                .GetPropertyType(rangeIndexProp)
                                .GetBoxedType();
                            var coercionType = indexedPropType;
                            var proposedType = CoercionUtil.GetCoercionTypeRangeIn(
                                indexedPropType,
                                rangeIn.ExprStart,
                                rangeIn.ExprEnd);
                            if (proposedType != null && proposedType != indexedPropType) {
                                coercionType = proposedType;
                            }

                            subqRangeDesc = new SubordPropRangeKeyForge(rangeIn, coercionType);
                            rangeProps.Put(rangeIndexProp, subqRangeDesc);
                        }

                        // ignore
                        continue;
                    }

                    // an existing entry has not been found
                    if (rangeDesc.Type.IsRange()) {
                        var rangeIn = (QueryGraphValueEntryRangeInForge) rangeDesc;
                        var indexedPropType =
                            allStreamTypesZeroIndexed[0].GetPropertyType(rangeIndexProp).GetBoxedType();
                        var coercionType = indexedPropType;
                        var proposedType = CoercionUtil.GetCoercionTypeRangeIn(
                            indexedPropType,
                            rangeIn.ExprStart,
                            rangeIn.ExprEnd);
                        if (proposedType != null && proposedType != indexedPropType) {
                            coercionType = proposedType;
                        }

                        subqRangeDesc = new SubordPropRangeKeyForge(rangeDesc, coercionType);
                    }
                    else {
                        var relOp = (QueryGraphValueEntryRangeRelOpForge) rangeDesc;
                        var keyPropType = relOp.Expression.Forge.EvaluationType;
                        var indexedPropType =
                            allStreamTypesZeroIndexed[0].GetPropertyType(rangeIndexProp).GetBoxedType();
                        var coercionType = indexedPropType;
                        if (keyPropType != indexedPropType) {
                            coercionType = keyPropType.GetCompareToCoercionType(indexedPropType);
                        }

                        subqRangeDesc = new SubordPropRangeKeyForge(rangeDesc, coercionType);
                    }

                    rangeProps.Put(rangeIndexProp, subqRangeDesc);
                }
            }

            SubordPropInKeywordSingleIndex inKeywordSingleIdxProp = null;
            SubordPropInKeywordMultiIndex inKeywordMultiIdxProp = null;
            if (joinProps.IsEmpty() && rangeProps.IsEmpty()) {
                for (var stream = 0; stream < outsideStreamCount; stream++) {
                    var lookupStream = stream + 1;
                    var queryGraphValue = queryGraph.GetGraphValue(lookupStream, 0);

                    var inkwSingles = queryGraphValue.InKeywordSingles;
                    if (inkwSingles.Indexed.Length != 0) {
                        ExprNode[] keys = inkwSingles.Key[0].KeyExprs;
                        var key = inkwSingles.Indexed[0];
                        if (inKeywordSingleIdxProp != null) {
                            continue;
                        }

                        var coercionType = keys[0].Forge.EvaluationType; // for in-comparison the same type is required
                        inKeywordSingleIdxProp = new SubordPropInKeywordSingleIndex(key, coercionType, keys);
                    }

                    var inkwMultis = queryGraphValue.InKeywordMulti;
                    if (!inkwMultis.IsEmpty()) {
                        QueryGraphValuePairInKWMultiIdx multi = inkwMultis[0];
                        inKeywordMultiIdxProp = new SubordPropInKeywordMultiIndex(
                            ExprNodeUtilityQuery.GetIdentResolvedPropertyNames(multi.Indexed),
                            multi.Indexed[0].Forge.EvaluationType,
                            multi.Key.KeyExpr);
                    }

                    if (inKeywordSingleIdxProp != null && inKeywordMultiIdxProp != null) {
                        inKeywordMultiIdxProp = null;
                    }
                }
            }

            return new SubordPropPlan(
                joinProps,
                rangeProps,
                inKeywordSingleIdxProp,
                inKeywordMultiIdxProp,
                customIndexOps);
        }
Esempio n. 6
0
 /// <summary>Returns true if the window is empty, or false if not empty. </summary>
 /// <returns>true if empty</returns>
 public bool IsEmpty()
 {
     return(_currentBatch.IsEmpty());
 }
 private bool IsNewRepository()
 {
     return(GetRefsMap().IsEmpty() && packNames != null && packNames.IsEmpty());
 }
Esempio n. 8
0
        /// <exception cref="System.IO.IOException"></exception>
        private void ReadAdvertisedRefsImpl()
        {
            LinkedHashMap <string, Ref> avail = new LinkedHashMap <string, Ref>();

            for (; ;)
            {
                string line;
                try
                {
                    line = pckIn.ReadString();
                }
                catch (EOFException eof)
                {
                    if (avail.IsEmpty())
                    {
                        throw NoRepository();
                    }
                    throw;
                }
                if (line == PacketLineIn.END)
                {
                    break;
                }
                if (line.StartsWith("ERR "))
                {
                    // This is a customized remote service error.
                    // Users should be informed about it.
                    throw new RemoteRepositoryException(uri, Sharpen.Runtime.Substring(line, 4));
                }
                if (avail.IsEmpty())
                {
                    int nul = line.IndexOf('\0');
                    if (nul >= 0)
                    {
                        // The first line (if any) may contain "hidden"
                        // capability values after a NUL byte.
                        foreach (string c in Sharpen.Runtime.Substring(line, nul + 1).Split(" "))
                        {
                            remoteCapablities.AddItem(c);
                        }
                        line = Sharpen.Runtime.Substring(line, 0, nul);
                    }
                }
                string name = Sharpen.Runtime.Substring(line, 41, line.Length);
                if (avail.IsEmpty() && name.Equals("capabilities^{}"))
                {
                    // special line from git-receive-pack to show
                    // capabilities when there are no refs to advertise
                    continue;
                }
                ObjectId id = ObjectId.FromString(Sharpen.Runtime.Substring(line, 0, 40));
                if (name.Equals(".have"))
                {
                    additionalHaves.AddItem(id);
                }
                else
                {
                    if (name.EndsWith("^{}"))
                    {
                        name = Sharpen.Runtime.Substring(name, 0, name.Length - 3);
                        Ref prior = avail.Get(name);
                        if (prior == null)
                        {
                            throw new PackProtocolException(uri, MessageFormat.Format(JGitText.Get().advertisementCameBefore
                                                                                      , name, name));
                        }
                        if (prior.GetPeeledObjectId() != null)
                        {
                            throw DuplicateAdvertisement(name + "^{}");
                        }
                        avail.Put(name, new ObjectIdRef.PeeledTag(RefStorage.NETWORK, name, prior.GetObjectId
                                                                      (), id));
                    }
                    else
                    {
                        Ref prior = avail.Put(name, new ObjectIdRef.PeeledNonTag(RefStorage.NETWORK, name
                                                                                 , id));
                        if (prior != null)
                        {
                            throw DuplicateAdvertisement(name);
                        }
                    }
                }
            }
            Available(avail);
        }
Esempio n. 9
0
        public override void Update(
            EventBean[] newData,
            EventBean[] oldData)
        {
            _agentInstanceContext.AuditProvider.View(newData, oldData, _agentInstanceContext, _factory);
            _agentInstanceContext.InstrumentationProvider.QViewProcessIRStream(_factory, newData, oldData);

            if ((newData != null) && (newData.Length > 0)) {
                // If we have an empty window about to be filled for the first time, add a callback
                bool removeSchedule = false;
                bool addSchedule = false;
                long timestamp = _agentInstanceContext.StatementContext.SchedulingService.Time;

                // if the window is already filled, then we may need to reschedule
                if (!_currentBatch.IsEmpty()) {
                    // check if we need to reschedule
                    long callbackTime =
                        timestamp + _timePeriodProvide.DeltaAdd(timestamp, null, true, _agentInstanceContext);
                    if (callbackTime != _callbackScheduledTime) {
                        removeSchedule = true;
                        addSchedule = true;
                    }
                }
                else {
                    addSchedule = true;
                }

                if (removeSchedule) {
                    _agentInstanceContext.AuditProvider.ScheduleRemove(
                        _agentInstanceContext,
                        _handle,
                        ScheduleObjectType.view,
                        _factory.ViewName);
                    _agentInstanceContext.StatementContext.SchedulingService.Remove(_handle, _scheduleSlot);
                    _callbackScheduledTime = -1;
                }

                if (addSchedule) {
                    long timeIntervalSize = _timePeriodProvide.DeltaAdd(timestamp, null, true, _agentInstanceContext);
                    _agentInstanceContext.AuditProvider.ScheduleAdd(
                        timeIntervalSize,
                        _agentInstanceContext,
                        _handle,
                        ScheduleObjectType.view,
                        _factory.ViewName);
                    _agentInstanceContext.StatementContext.SchedulingService.Add(
                        timeIntervalSize,
                        _handle,
                        _scheduleSlot);
                    _callbackScheduledTime = timeIntervalSize + timestamp;
                }

                // add data points to the window
                for (int i = 0; i < newData.Length; i++) {
                    _currentBatch.Put(newData[i], timestamp);
                    _lastEvent = newData[i];
                }
            }

            if ((oldData != null) && (oldData.Length > 0)) {
                bool removedLastEvent = false;
                foreach (EventBean anOldData in oldData) {
                    _currentBatch.Remove(anOldData);
                    if (anOldData == _lastEvent) {
                        removedLastEvent = true;
                    }
                }

                // we may need to reschedule as the newest event may have been deleted
                if (_currentBatch.Count == 0) {
                    _agentInstanceContext.AuditProvider.ScheduleRemove(
                        _agentInstanceContext,
                        _handle,
                        ScheduleObjectType.view,
                        _factory.ViewName);
                    _agentInstanceContext.StatementContext.SchedulingService.Remove(_handle, _scheduleSlot);
                    _callbackScheduledTime = -1;
                    _lastEvent = null;
                }
                else {
                    // reschedule if the last event was removed
                    if (removedLastEvent) {
                        EventBean[] events = _currentBatch.Keys.ToArray();
                        _lastEvent = events[events.Length - 1];
                        long lastTimestamp = _currentBatch.Get(_lastEvent);

                        // reschedule, newest event deleted
                        long timestamp = _agentInstanceContext.StatementContext.SchedulingService.Time;
                        long callbackTime = lastTimestamp +
                                            _timePeriodProvide.DeltaAdd(
                                                lastTimestamp,
                                                null,
                                                true,
                                                _agentInstanceContext);
                        long deltaFromNow = callbackTime - timestamp;
                        if (callbackTime != _callbackScheduledTime) {
                            _agentInstanceContext.AuditProvider.ScheduleRemove(
                                _agentInstanceContext,
                                _handle,
                                ScheduleObjectType.view,
                                _factory.ViewName);
                            _agentInstanceContext.StatementContext.SchedulingService.Remove(_handle, _scheduleSlot);
                            _agentInstanceContext.AuditProvider.ScheduleAdd(
                                deltaFromNow,
                                _agentInstanceContext,
                                _handle,
                                ScheduleObjectType.view,
                                _factory.ViewName);
                            _agentInstanceContext.StatementContext.SchedulingService.Add(
                                deltaFromNow,
                                _handle,
                                _scheduleSlot);
                            _callbackScheduledTime = callbackTime;
                        }
                    }
                }
            }

            // update child views
            var child = Child;
            if (child != null) {
                _agentInstanceContext.InstrumentationProvider.QViewIndicate(_factory, newData, oldData);
                child.Update(newData, oldData);
                _agentInstanceContext.InstrumentationProvider.AViewIndicate();
            }

            _agentInstanceContext.InstrumentationProvider.AViewProcessIRStream();
        }