protected override StatementAgentInstanceFactoryResult NewContextInternal(AgentInstanceContext agentInstanceContext, bool isRecoveringResilient) { StopCallback stopCallback = () => _services.VariableService.DeallocateVariableState(_variableMetaData.VariableName, agentInstanceContext.AgentInstanceId); _services.VariableService.AllocateVariableState(_variableMetaData.VariableName, agentInstanceContext.AgentInstanceId, _statementContext.StatementExtensionServicesContext); return(new StatementAgentInstanceFactoryCreateVariableResult(new ViewableDefaultImpl(_eventType), stopCallback, agentInstanceContext)); }
public static void Stop(StopCallback stopCallback, AgentInstanceContext agentInstanceContext, Viewable finalView, EPServicesContext servicesContext, bool isStatementStop, bool leaveLocksAcquired) { using (Instrument.With( i => i.QContextPartitionDestroy(agentInstanceContext), i => i.AContextPartitionDestroy())) { // obtain statement lock var iLock = agentInstanceContext.EpStatementAgentInstanceHandle.StatementAgentInstanceLock; using (var iLockEnd = iLock.WriteLock.Acquire(!leaveLocksAcquired)) { try { if (finalView is OutputProcessViewTerminable && !isStatementStop) { var terminable = (OutputProcessViewTerminable)finalView; terminable.Terminated(); } StopSafe(stopCallback, agentInstanceContext.StatementContext); if (servicesContext.SchedulableAgentInstanceDirectory != null) { servicesContext.SchedulableAgentInstanceDirectory.Remove( agentInstanceContext.StatementContext.StatementId, agentInstanceContext.AgentInstanceId); } // indicate method resolution agentInstanceContext.StatementContext.MethodResolutionService.DestroyedAgentInstance( agentInstanceContext.AgentInstanceId); // release resource agentInstanceContext.StatementContext.StatementAgentInstanceRegistry.Deassign( agentInstanceContext.AgentInstanceId); // cause any remaining schedules, that may concide with the caller's schedule, to be ignored agentInstanceContext.EpStatementAgentInstanceHandle.IsDestroyed = true; // cause any filters, that may concide with the caller's filters, to be ignored agentInstanceContext.EpStatementAgentInstanceHandle.StatementFilterVersion.StmtFilterVersion = Int64.MaxValue; if (agentInstanceContext.StatementContext.StatementExtensionServicesContext != null && agentInstanceContext.StatementContext.StatementExtensionServicesContext.StmtResources != null) { agentInstanceContext.StatementContext.StatementExtensionServicesContext.StmtResources .DeallocatePartitioned(agentInstanceContext.AgentInstanceId); } } finally { if (!leaveLocksAcquired) { if (agentInstanceContext.StatementContext.EpStatementHandle.HasTableAccess) { agentInstanceContext.TableExprEvaluatorContext.ReleaseAcquiredLocks(); } } } } } }
public StatementAgentInstanceFactorySelectResult( Viewable finalView, StopCallback stopCallback, AgentInstanceContext agentInstanceContext, AggregationService optionalAggegationService, IDictionary <ExprSubselectNode, SubSelectStrategyHolder> subselectStrategies, IDictionary <ExprPriorNode, ExprPriorEvalStrategy> priorNodeStrategies, IDictionary <ExprPreviousNode, ExprPreviousEvalStrategy> previousNodeStrategies, RegexExprPreviousEvalStrategy regexExprPreviousEvalStrategy, IDictionary <ExprTableAccessNode, ExprTableAccessEvalStrategy> tableAccessStrategies, IList <StatementAgentInstancePreload> preloadList, EvalRootState[] patternRoots, StatementAgentInstancePostLoad optionalPostLoadJoin, Viewable[] topViews, Viewable[] eventStreamViewables, ViewableActivationResult[] viewableActivationResults) : base( finalView, stopCallback, agentInstanceContext, optionalAggegationService, subselectStrategies, priorNodeStrategies, previousNodeStrategies, regexExprPreviousEvalStrategy, tableAccessStrategies, preloadList) { TopViews = topViews; PatternRoots = patternRoots; OptionalPostLoadJoin = optionalPostLoadJoin; EventStreamViewables = eventStreamViewables; ViewableActivationResults = viewableActivationResults; }
/// <summary> /// Default constructor /// </summary> //////////////////////////////////////////////////////////// protected SoundRecorder() : base(IntPtr.Zero) { myStartCallback = new StartCallback(OnStart); myProcessCallback = new ProcessCallback(ProcessSamples); myStopCallback = new StopCallback(OnStop); SetThis(sfSoundRecorder_Create(myStartCallback, myProcessCallback, myStopCallback, IntPtr.Zero)); }
public AgentInstance(StopCallback stopCallback, AgentInstanceContext agentInstanceContext, Viewable finalView) { StopCallback = stopCallback; AgentInstanceContext = agentInstanceContext; FinalView = finalView; }
//////////////////////////////////////////////////////////// /// <summary> /// Default constructor /// </summary> //////////////////////////////////////////////////////////// public SoundRecorder() : base(IntPtr.Zero) { myStartCallback = new StartCallback(OnStart); myProcessCallback = new ProcessCallback(ProcessSamples); myStopCallback = new StopCallback(OnStop); CPointer = sfSoundRecorder_create(myStartCallback, myProcessCallback, myStopCallback, IntPtr.Zero); }
//////////////////////////////////////////////////////////// /// <summary> /// Default constructor /// </summary> //////////////////////////////////////////////////////////// public SoundRecorder() : base(IntPtr.Zero) { myStartCallback = new StartCallback(OnStart); myProcessCallback = new ProcessCallback(ProcessSamples); myStopCallback = new StopCallback(OnStop); SetThis(sfSoundRecorder_Create(myStartCallback, myProcessCallback, myStopCallback, IntPtr.Zero)); }
public void Stop() { StopCallback?.Invoke(this, new EventArgs()); _IsPlaying = false; _IsDone = true; synchronizationContext.Post((o) => { timer1.Enabled = false; }, null); }
public StatementAgentInstanceFactoryCreateIndexResult(Viewable finalView, StopCallback stopCallback, AgentInstanceContext agentInstanceContext) : base(finalView, stopCallback, agentInstanceContext, null, Collections.GetEmptyMap <ExprSubselectNode, SubSelectStrategyHolder>(), Collections.GetEmptyMap <ExprPriorNode, ExprPriorEvalStrategy>(), Collections.GetEmptyMap <ExprPreviousNode, ExprPreviousEvalStrategy>(), null, Collections.GetEmptyMap <ExprTableAccessNode, ExprTableAccessEvalStrategy>(), Collections.GetEmptyList <StatementAgentInstancePreload>()) { }
public static void StopSafe(StopCallback stopMethod, StatementContext statementContext) { try { stopMethod.Invoke(); } catch (Exception e) { Log.Warn("Failed to perform statement stop for statement '" + statementContext.StatementName + "' expression '" + statementContext.Expression + "' : " + e.Message, e); } }
public static void StopSafe(StopCallback stopMethod, StatementContext statementContext) { try { stopMethod.Stop(); } catch (Exception e) { statementContext.ExceptionHandlingService.HandleException(e, statementContext.StatementName, statementContext.Expression, ExceptionHandlerExceptionType.STOP, null); } }
/// <summary> /// Stops the thread /// </summary> public void Stop(StopCallback callback) { lock (this) { if (!_running) { return; } _callback = callback; _running = false; } }
private void StopCallbackHandler() { if (this.lblMsg.InvokeRequired) { StopCallback d = new StopCallback(StopCallbackHandler); this.Invoke(d); } else { SetControlsStop(); } }
public void ClearCallback() { if (StartDelayChanged != null) { foreach (Delegate d in StartDelayChanged.GetInvocationList()) { StartDelayChanged -= (EventHandler)d; } } if (DurationChanged != null) { foreach (Delegate d in DurationChanged.GetInvocationList()) { DurationChanged -= (EventHandler)d; } } if (PositionRequest != null) { foreach (Delegate d in PositionRequest.GetInvocationList()) { PositionRequest -= (EventHandler)d; } } if (StartCallback != null) { foreach (Delegate d in StartCallback.GetInvocationList()) { StartCallback -= (EventHandler)d; } } if (StopCallback != null) { foreach (Delegate d in StopCallback.GetInvocationList()) { StopCallback -= (EventHandler)d; } } if (NextCallback != null) { foreach (Delegate d in NextCallback.GetInvocationList()) { NextCallback -= (EventHandler)d; } } if (PrevCallback != null) { foreach (Delegate d in PrevCallback.GetInvocationList()) { PrevCallback -= (EventHandler)d; } } }
public void RemoveTerminationCallback(StopCallback callback) { if (_terminationCallbacks == null) { } else if (_terminationCallbacks is ICollection <StopCallback> ) { ((ICollection <StopCallback>)_terminationCallbacks).Remove(callback); } else if (ReferenceEquals(_terminationCallbacks, callback)) { _terminationCallbacks = null; } }
public StatementAgentInstanceFactoryCreateWindowResult(Viewable finalView, StopCallback stopCallback, AgentInstanceContext agentInstanceContext, Viewable eventStreamParentViewable, StatementAgentInstancePostLoad postLoad, Viewable topView, NamedWindowProcessorInstance processorInstance, ViewableActivationResult viewableActivationResult) : base(finalView, stopCallback, agentInstanceContext, null, Collections.GetEmptyMap <ExprSubselectNode, SubSelectStrategyHolder>(), Collections.GetEmptyMap <ExprPriorNode, ExprPriorEvalStrategy>(), Collections.GetEmptyMap <ExprPreviousNode, ExprPreviousEvalStrategy>(), null, Collections.GetEmptyMap <ExprTableAccessNode, ExprTableAccessEvalStrategy>(), Collections.GetEmptyList <StatementAgentInstancePreload>()) { EventStreamParentViewable = eventStreamParentViewable; PostLoad = postLoad; TopView = topView; ProcessorInstance = processorInstance; ViewableActivationResult = viewableActivationResult; }
public void AddTerminationCallback(StopCallback callback) { if (_terminationCallbacks == null) { _terminationCallbacks = callback; } else if (_terminationCallbacks is ICollection <StopCallback> ) { ((ICollection <StopCallback>)_terminationCallbacks).Add(callback); } else { var cb = (StopCallback)_terminationCallbacks; var q = new HashSet <StopCallback>(); q.Add(cb); q.Add(callback); _terminationCallbacks = q; } }
public ViewableActivationResult( Viewable viewable, StopCallback stopCallback, IReaderWriterLock optionalLock, EvalRootState optionalPatternRoot, EvalRootMatchRemover optEvalRootMatchRemover, bool suppressSameEventMatches, bool discardPartialsOnMatch, ViewableActivationResultExtension viewableActivationResultExtension) { Viewable = viewable; StopCallback = stopCallback; OptionalLock = optionalLock; OptionalPatternRoot = optionalPatternRoot; OptEvalRootMatchRemover = optEvalRootMatchRemover; IsSuppressSameEventMatches = suppressSameEventMatches; IsDiscardPartialsOnMatch = discardPartialsOnMatch; ViewableActivationResultExtension = viewableActivationResultExtension; }
protected StatementAgentInstanceFactoryResult( Viewable finalView, StopCallback stopCallback, AgentInstanceContext agentInstanceContext, AggregationService optionalAggegationService, IDictionary <ExprSubselectNode, SubSelectStrategyHolder> subselectStrategies, IDictionary <ExprPriorNode, ExprPriorEvalStrategy> priorNodeStrategies, IDictionary <ExprPreviousNode, ExprPreviousEvalStrategy> previousNodeStrategies, RegexExprPreviousEvalStrategy regexExprPreviousEvalStrategy, IDictionary <ExprTableAccessNode, ExprTableAccessEvalStrategy> tableAccessStrategies, IList <StatementAgentInstancePreload> preloadList) { FinalView = finalView; StopCallback = stopCallback; AgentInstanceContext = agentInstanceContext; OptionalAggegationService = optionalAggegationService; SubselectStrategies = subselectStrategies; PriorNodeStrategies = priorNodeStrategies; PreviousNodeStrategies = previousNodeStrategies; RegexExprPreviousEvalStrategy = regexExprPreviousEvalStrategy; TableAccessEvalStrategies = tableAccessStrategies; PreloadList = preloadList; }
/// <summary> /// Stops and closes the progress dialog /// </summary> public static void Stop() { if (instance != null) { if (instance.InvokeRequired) { StopCallback s = new StopCallback(Stop); instance.Invoke(s); } else { instance.Close(); instance.Dispose(); instance = null; } } if (thread != null) { Thread.Sleep(0); thread = null; } }
public StatementAgentInstanceFactoryOnTriggerResult( Viewable finalView, StopCallback stopCallback, AgentInstanceContext agentInstanceContext, AggregationService aggregationService, IDictionary <ExprSubselectNode, SubSelectStrategyHolder> subselectStrategies, EvalRootState optPatternRoot, IDictionary <ExprTableAccessNode, ExprTableAccessEvalStrategy> tableAccessStrategies, ViewableActivationResult viewableActivationResult) : base( finalView, stopCallback, agentInstanceContext, aggregationService, subselectStrategies, Collections.GetEmptyMap <ExprPriorNode, ExprPriorEvalStrategy>(), Collections.GetEmptyMap <ExprPreviousNode, ExprPreviousEvalStrategy>(), null, tableAccessStrategies, Collections.GetEmptyList <StatementAgentInstancePreload>()) { OptPatternRoot = optPatternRoot; ViewableActivationResult = viewableActivationResult; }
static extern IntPtr sfSoundRecorder_Create(StartCallback OnStart, ProcessCallback OnProcess, StopCallback OnStop, IntPtr UserData);
static CollectionUtil() { SINGLE_NULL_ROW_EVENT_SET.Add(null); STOP_CALLBACK_NONE = () => { }; }
public void AddTerminationCallback(StopCallback callback) { _agentInstanceContext.AddTerminationCallback(callback); }
public void RemoveTerminationCallback(StopCallback callback) { _agentInstanceContext.RemoveTerminationCallback(callback); }
static CollectionUtil() { SINGLE_NULL_ROW_EVENT_SET.Add(null); STOP_CALLBACK_NONE = new ProxyStopCallback(() => { }); }
protected override StatementAgentInstanceFactoryResult NewContextInternal(AgentInstanceContext agentInstanceContext, bool isRecoveringResilient) { var stopCallbacks = new List <StopCallback>(); String windowName = _statementSpec.CreateWindowDesc.WindowName; Viewable finalView; Viewable eventStreamParentViewable; StatementAgentInstancePostLoad postLoad; Viewable topView; NamedWindowProcessorInstance processorInstance; ViewableActivationResult viewableActivationResult; try { // Register interest viewableActivationResult = _activator.Activate(agentInstanceContext, false, isRecoveringResilient); stopCallbacks.Add(viewableActivationResult.StopCallback); eventStreamParentViewable = viewableActivationResult.Viewable; // Obtain processor for this named window var processor = _services.NamedWindowMgmtService.GetProcessor(windowName); if (processor == null) { throw new Exception("Failed to obtain named window processor for named window '" + windowName + "'"); } // Allocate processor instance processorInstance = processor.AddInstance(agentInstanceContext); var rootView = processorInstance.RootViewInstance; eventStreamParentViewable.AddView(rootView); // Materialize views var viewFactoryChainContext = new AgentInstanceViewFactoryChainContext(agentInstanceContext, true, null, null); var createResult = _services.ViewService.CreateViews(rootView, _unmaterializedViewChain.FactoryChain, viewFactoryChainContext, false); topView = createResult.TopViewable; finalView = createResult.FinalViewable; // add views to stop callback if applicable StatementAgentInstanceFactorySelect.AddViewStopCallback(stopCallbacks, createResult.NewViews); // If this is a virtual data window implementation, bind it to the context for easy lookup StopCallback envStopCallback = null; if (finalView is VirtualDWView) { var objectName = "/virtualdw/" + windowName; var virtualDWView = (VirtualDWView)finalView; _services.EngineEnvContext.Bind(objectName, virtualDWView.VirtualDataWindow); envStopCallback = new ProxyStopCallback(() => { virtualDWView.Dispose(); _services.EngineEnvContext.Unbind(objectName); }); } StopCallback environmentStopCallback = envStopCallback; // Only if we are context-allocated: destroy the instance var contextName = processor.ContextName; var agentInstanceId = agentInstanceContext.AgentInstanceId; var allInOneStopMethod = new ProxyStopCallback(() => { var windowNameX = _statementSpec.CreateWindowDesc.WindowName; var processorX = _services.NamedWindowMgmtService.GetProcessor(windowNameX); if (processorX == null) { Log.Warn("Named window processor by name '" + windowNameX + "' has not been found"); } else { NamedWindowProcessorInstance instance = processorX.GetProcessorInstanceAllowUnpartitioned(agentInstanceId); if (instance != null) { if (contextName != null) { instance.Dispose(); } else { instance.Stop(); } } } if (environmentStopCallback != null) { environmentStopCallback.Stop(); } }); stopCallbacks.Add(allInOneStopMethod); // Attach tail view NamedWindowTailViewInstance tailView = processorInstance.TailViewInstance; finalView.AddView(tailView); finalView = tailView; // obtain result set processor ResultSetProcessor resultSetProcessor = EPStatementStartMethodHelperAssignExpr.GetAssignResultSetProcessor(agentInstanceContext, _resultSetProcessorPrototype, false, null, false); // Attach output view View outputView = _outputProcessViewFactory.MakeView(resultSetProcessor, agentInstanceContext); finalView.AddView(outputView); finalView = outputView; // obtain post load postLoad = processorInstance.PostLoad; // Handle insert case if (_statementSpec.CreateWindowDesc.IsInsert && !_isRecoveringStatement) { String insertFromWindow = _statementSpec.CreateWindowDesc.InsertFromWindow; NamedWindowProcessor namedWindowProcessor = _services.NamedWindowMgmtService.GetProcessor(insertFromWindow); NamedWindowProcessorInstance sourceWindowInstances = namedWindowProcessor.GetProcessorInstance(agentInstanceContext); IList <EventBean> events = new List <EventBean>(); if (_statementSpec.CreateWindowDesc.InsertFilter != null) { var eventsPerStream = new EventBean[1]; var filter = _statementSpec.CreateWindowDesc.InsertFilter.ExprEvaluator; for (IEnumerator <EventBean> it = sourceWindowInstances.TailViewInstance.GetEnumerator(); it.MoveNext();) { var candidate = it.Current; eventsPerStream[0] = candidate; var result = filter.Evaluate(new EvaluateParams(eventsPerStream, true, agentInstanceContext)); if ((result == null) || (false.Equals(result))) { continue; } events.Add(candidate); } } else { for (IEnumerator <EventBean> it = sourceWindowInstances.TailViewInstance.GetEnumerator(); it.MoveNext();) { events.Add(it.Current); } } if (events.Count > 0) { EventType rootViewType = rootView.EventType; EventBean[] convertedEvents = _services.EventAdapterService.TypeCast(events, rootViewType); rootView.Update(convertedEvents, null); } } } catch (Exception) { StopCallback callback = StatementAgentInstanceUtil.GetStopCallback(stopCallbacks, agentInstanceContext); StatementAgentInstanceUtil.StopSafe(callback, _statementContext); throw; } var createWindowResult = new StatementAgentInstanceFactoryCreateWindowResult( finalView, null, agentInstanceContext, eventStreamParentViewable, postLoad, topView, processorInstance, viewableActivationResult); if (_statementContext.StatementExtensionServicesContext != null) { _statementContext.StatementExtensionServicesContext.ContributeStopCallback(createWindowResult, stopCallbacks); } Log.Debug(".start Statement start completed"); StopCallback stopCallback = StatementAgentInstanceUtil.GetStopCallback(stopCallbacks, agentInstanceContext); createWindowResult.StopCallback = stopCallback; return(createWindowResult); }
static extern IntPtr sfSoundRecorder_create(StartCallback OnStart, ProcessCallback OnProcess, StopCallback OnStop, IntPtr UserData);
private static extern IntPtr VidyoVirtualWindowShareConstructNative(IntPtr id, IntPtr windowName, IntPtr applicationName, StartCallback onStart, ReconfigureCallback onReconfigure, StopCallback onStop);
private void RunLoop() { // TO DO make the following not hard coded? // Variables for csv reading; bool header = true; int lineNo = 1; int columnIndividual = 1; int columnDate = 3; int columnEvent = 6; int columnComment = 7; List <IndividualReproductiveState> statesToInsert = new List <IndividualReproductiveState>(); List <ReproductiveState> validReproductiveStates = new List <ReproductiveState>(Session .CreateQuery("select s from ReproductiveState as s") .List <ReproductiveState>()); while (this.state != State.Stopped && this.fileStream != null && !this.fileStream.EndOfStream) { if (header) { this.fileStream.ReadLine(); header = false; } // Do processing // Get the csv row string[] row = this.fileStream.ReadLine().Split(new char[] { ',' }); lineNo++; // Find the event from the event column string demographyEvent = row[columnEvent]; // Check to see if the event is in the list of reproductive states; // is so select it bool validEvent = false; ReproductiveState state = null; foreach (ReproductiveState rs in validReproductiveStates) { if (rs.State == demographyEvent) { validEvent = true; state = rs; break; } } if (validEvent) { IndividualReproductiveState reproductiveState = new IndividualReproductiveState(); // Set the state reproductiveState.State = state; // Find the individual from the id column reproductiveState.Individual = Session.Get <Individual>(row[columnIndividual]); if (reproductiveState.Individual != null) { // Find the troop visit from the date column and the individual DateTime date = DateTime.Parse(row[columnDate]); Troop troop = reproductiveState.Individual.CurrentTroop(date); if (troop != null) { string query = "Select tv from TroopVisit as tv where Troop = :troop and Date = :date"; reproductiveState.TroopVisit = Session .CreateQuery(query) .SetParameter <DateTime>("date", date) .SetParameter <Troop>("troop", troop) .UniqueResult <TroopVisit>(); // Find the comment from the comment column reproductiveState.Comments = row[columnComment]; // INTEGRITY CHECK // Quick check to make sure it is valid if (reproductiveState.TroopVisit != null) { // Print some text and add the state to those to be inserted. AddText("Found entry: " + reproductiveState.Individual.ToString() + " " + reproductiveState.ToString() + " " + reproductiveState.TroopVisit.ToString()); statesToInsert.Add(reproductiveState); } else { this.AddText("Could not find TroopVisit for " + troop + " on date " + date.ToShortDateString() + " at line " + lineNo); } } else { this.AddText("Could not find Troop for '" + reproductiveState.Individual.Name + "(" + reproductiveState.ID + ") on date " + date.ToShortDateString() + " at line " + lineNo); } } else { this.AddText("Could not find individual with ID '" + row[columnIndividual] + "' at line " + lineNo); } } // Don't hog cpu Thread.Sleep(100); // Wait on paused while (this.state == State.Paused) { Thread.Sleep(50); } } // Ask to begin insertion if (DialogResult.OK == MessageBox.Show("Found " + statesToInsert.Count + " valid entries from selected file. Click Ok to begin insert." , "Finished reading file", MessageBoxButtons.OKCancel, MessageBoxIcon.Information , MessageBoxDefaultButton.Button2)) { InsertEntries(statesToInsert); } StopCallback d = new StopCallback(Stop); Invoke(d); }