/// <summary> /// Add a statement, inspecting the statement name and adding it to a statement group or the default group, if none. /// </summary> /// <param name="statement">name to inspect</param> /// <returns>handle for statement</returns> public StatementMetricHandle AddStatement(DeploymentIdNamePair statement) { // determine group var countGroups = 1; var groupNumber = -1; foreach (var entry in specification.StatementGroups) { var patterns = entry.Value.Patterns; var result = StringPatternSetUtil.Evaluate(entry.Value.IsDefaultInclude, patterns, statement.Name); if (result) { groupNumber = countGroups; break; } countGroups++; } // assign to default group if none other apply if (groupNumber == -1) { groupNumber = 0; } var index = groupMetrics[groupNumber].AddStatementGetIndex(statement); statementGroups.Put(statement, groupNumber); return new StatementMetricHandle(groupNumber, index); }
public StatementEntry( DeploymentIdNamePair statement, RowRecogStatePoolStmtHandler stmtCounts) { Statement = statement; StmtCounts = stmtCounts; }
public void Run(RegressionEnvironment env) { var path = new RegressionPath(); env.CompileDeploy( "create context MyCtx as initiated by SupportBean_S0 S0 terminated after 24 hours", path); env.CompileDeploy("@Name('var') context MyCtx create variable int mycontextvar = 5", path); env.CompileDeploy( "context MyCtx on SupportBean(TheString = context.S0.P00) set mycontextvar = IntPrimitive", path); var namePairVariable = new DeploymentIdNamePair(env.DeploymentId("var"), "mycontextvar"); env.SendEventBean(new SupportBean_S0(0, "P1")); // allocate partition P1 AssertVariableValues(env, 0, 5); env.Runtime.VariableService.SetVariableValue( Collections.SingletonMap<DeploymentIdNamePair, object>(namePairVariable, 10), 0); AssertVariableValues(env, 0, 10); env.SendEventBean(new SupportBean_S0(0, "P2")); // allocate partition P2 AssertVariableValues(env, 1, 5); env.Runtime.VariableService.SetVariableValue( Collections.SingletonMap<DeploymentIdNamePair, object>(namePairVariable, 11), 1); AssertVariableValues(env, 1, 11); // global variable - trying to set via context partition selection env.CompileDeploy("@Name('globalvar') create variable int myglobarvar = 0"); var nameGlobalVar = new DeploymentIdNamePair(env.DeploymentId("globalvar"), "myglobarvar"); try { env.Runtime.VariableService.SetVariableValue( Collections.SingletonMap<DeploymentIdNamePair, object>(nameGlobalVar, 11), 0); Assert.Fail(); } catch (VariableNotFoundException ex) { Assert.AreEqual( "Variable by name 'myglobarvar' is a global variable and not context-partitioned", ex.Message); } // global variable - trying to get via context partition selection try { env.Runtime.VariableService.GetVariableValue( Collections.SingletonSet(nameGlobalVar), new SupportSelectorById(1)); Assert.Fail(); } catch (VariableNotFoundException ex) { Assert.AreEqual( "Variable by name 'myglobarvar' is a global variable and not context-partitioned", ex.Message); } env.UndeployAll(); }
public void OnUndeployment(DeploymentStateEventUndeployed @event) { if (!specification.IsEnableMetricsReporting) { return; } foreach (EPStatement stmt in @event.Statements) { var pair = new DeploymentIdNamePair(stmt.DeploymentId, stmt.Name); stmtMetricRepository.RemoveStatement(pair); statementMetricHandles.Remove(pair); } }
public void RemoveStatement(DeploymentIdNamePair statement) { // counts get reduced upon view stop ISet<StatementEntry> removed = new HashSet<StatementEntry>(); foreach (var context in matchRecognizeContexts) { if (context.Statement.Equals(statement)) { removed.Add(context); } } matchRecognizeContexts.RemoveAll(removed); }
public StatementMetricHandle GetStatementHandle( int statementId, string deploymentId, string statementName) { if (!specification.IsEnableMetricsReporting) { return new StatementMetricHandle(false); } var statement = new DeploymentIdNamePair(deploymentId, statementName); var handle = stmtMetricRepository.AddStatement(statement); statementMetricHandles.Put(statement, handle); return handle; }
private static void AssertVariableValues( RegressionEnvironment env, int agentInstanceId, int expected) { var namePairVariable = new DeploymentIdNamePair(env.DeploymentId("var"), "mycontextvar"); var states = env.Runtime.VariableService.GetVariableValue( Collections.SingletonSet(namePairVariable), new SupportSelectorById(agentInstanceId)); Assert.AreEqual(1, states.Count); var list = states.Get(namePairVariable); Assert.AreEqual(1, list.Count); Assert.AreEqual(expected, list[0].State); }
/// <summary> /// Remove a statement. /// <para /> /// Next flush actually frees the slot that this statement occupied. /// </summary> /// <param name="statement">to remove</param> public void RemoveStatement(DeploymentIdNamePair statement) { using (RWLock.AcquireWriteLock()) { removedStatementNames.Add(statement); if (removedStatementNames.Count > 1000) { for (var i = 0; i <= currentLastElement; i++) { if (removedStatementNames.Contains(statementNames[i])) { statementNames[i] = null; } } removedStatementNames.Clear(); } } }
/// <summary> /// Adds a statement and returns the index added at. /// <para /> /// May reuse an empty slot, grow the underlying array, or append to the end. /// </summary> /// <param name="statement">deployment-id and name pair</param> /// <returns>index added to</returns> public int AddStatementGetIndex(DeploymentIdNamePair statement) { using (RWLock.AcquireWriteLock()) { // see if there is room if (currentLastElement + 1 < metrics.Length) { currentLastElement++; statementNames[currentLastElement] = statement; return currentLastElement; } // no room, try to use an existing slot of a removed statement for (var i = 0; i < statementNames.Length; i++) { if (statementNames[i] == null) { statementNames[i] = statement; if (i + 1 > currentLastElement) { currentLastElement = i; } return i; } } // still no room, expand storage by 50% var newSize = (int) (metrics.Length * 1.5); var newStatementNames = new DeploymentIdNamePair[newSize]; var newMetrics = new StatementMetric[newSize]; Array.Copy(statementNames, 0, newStatementNames, 0, statementNames.Length); Array.Copy(metrics, 0, newMetrics, 0, metrics.Length); statementNames = newStatementNames; metrics = newMetrics; currentLastElement++; statementNames[currentLastElement] = statement; return currentLastElement; } }
public void TestFlowReportActive() { var rep = new StatementMetricArray("uri", "name", 3, false, container.RWLockManager()); var d001 = new DeploymentIdNamePair("A", "001"); var d002 = new DeploymentIdNamePair("A", "002"); var d003 = new DeploymentIdNamePair("A", "003"); var d004 = new DeploymentIdNamePair("A", "004"); var d005 = new DeploymentIdNamePair("A", "005"); var d006 = new DeploymentIdNamePair("A", "006"); var d007 = new DeploymentIdNamePair("A", "007"); var d008 = new DeploymentIdNamePair("A", "008"); var d009 = new DeploymentIdNamePair("A", "009"); Assert.AreEqual(0, rep.SizeLastElement()); Assert.AreEqual(0, rep.AddStatementGetIndex(d001)); Assert.AreEqual(1, rep.SizeLastElement()); Assert.AreEqual(1, rep.AddStatementGetIndex(d002)); Assert.AreEqual(2, rep.AddStatementGetIndex(d003)); Assert.AreEqual(3, rep.SizeLastElement()); rep.RemoveStatement(d002); Assert.AreEqual(3, rep.AddStatementGetIndex(d004)); Assert.AreEqual(4, rep.AddStatementGetIndex(d005)); rep.RemoveStatement(d005); Assert.AreEqual(5, rep.AddStatementGetIndex(d006)); var metrics = new StatementMetric[6]; for (var i = 0; i < 6; i++) { metrics[i] = rep.GetAddMetric(i); } var flushed = rep.FlushMetrics(); EPAssertionUtil.AssertSameExactOrder(metrics, flushed); Assert.AreEqual(1, rep.AddStatementGetIndex(d007)); Assert.AreEqual(4, rep.AddStatementGetIndex(d008)); rep.RemoveStatement(d001); rep.RemoveStatement(d003); rep.RemoveStatement(d004); rep.RemoveStatement(d006); rep.RemoveStatement(d007); Assert.AreEqual(6, rep.SizeLastElement()); rep.RemoveStatement(d008); Assert.AreEqual(6, rep.SizeLastElement()); flushed = rep.FlushMetrics(); Assert.AreEqual(6, flushed.Length); Assert.AreEqual(0, rep.SizeLastElement()); flushed = rep.FlushMetrics(); Assert.IsNull(flushed); Assert.AreEqual(0, rep.SizeLastElement()); Assert.AreEqual(0, rep.AddStatementGetIndex(d009)); Assert.AreEqual(1, rep.SizeLastElement()); flushed = rep.FlushMetrics(); Assert.AreEqual(6, flushed.Length); for (var i = 0; i < flushed.Length; i++) { Assert.IsNull(flushed[i]); } Assert.AreEqual(1, rep.SizeLastElement()); }
/// <summary> /// Remove statement. /// </summary> /// <param name="statement">to remove</param> public void RemoveStatement(DeploymentIdNamePair statement) { if (statementGroups.TryRemove(statement, out var group)) { groupMetrics[group].RemoveStatement(statement); } }
public void AddPatternContext( DeploymentIdNamePair statement, RowRecogStatePoolStmtHandler stmtCounts) { matchRecognizeContexts.Add(new StatementEntry(statement, stmtCounts)); }