コード例 #1
0
        public StatementAgentInstanceFactoryResult NewContext(AgentInstanceContext agentInstanceContext, bool isRecoveringResilient)
        {
            StopCallback stopCallback;

            if (namedWindowProcessor != null)
            {
                // handle named window index
                NamedWindowProcessorInstance processorInstance = namedWindowProcessor.GetProcessorInstance(agentInstanceContext);

                if (namedWindowProcessor.IsVirtualDataWindow)
                {
                    VirtualDWView virtualDWView = processorInstance.RootViewInstance.VirtualDataWindow;
                    virtualDWView.HandleStartIndex(spec);
                    stopCallback = () => {
                        virtualDWView.HandleStopIndex(spec);
                    };
                }
                else
                {
                    try {
                        processorInstance.RootViewInstance.AddExplicitIndex(spec.IsUnique, spec.IndexName, spec.Columns);
                    }
                    catch (ExprValidationException e) {
                        throw new EPException("Failed to create index: " + e.Message, e);
                    }
                    stopCallback = () => {
                    };
                }
            }
            else
            {
                // handle table access
                try {
                    TableStateInstance instance = services.TableService.GetState(tableName, agentInstanceContext.AgentInstanceId);
                    instance.AddExplicitIndex(spec);
                }
                catch (ExprValidationException ex) {
                    throw new EPException("Failed to create index: " + ex.Message, ex);
                }
                stopCallback = () => {
                };
            }

            return(new StatementAgentInstanceFactoryCreateIndexResult(finalView, stopCallback, agentInstanceContext));
        }
コード例 #2
0
        public StatementAgentInstanceFactoryResult NewContext(AgentInstanceContext agentInstanceContext, bool isRecoveringResilient)
        {
            StopCallback stopCallback;

            int agentInstanceId = agentInstanceContext.AgentInstanceId;

            if (namedWindowProcessor != null)
            {
                // handle named window index
                NamedWindowProcessorInstance processorInstance = namedWindowProcessor.GetProcessorInstance(agentInstanceContext);

                if (namedWindowProcessor.IsVirtualDataWindow)
                {
                    VirtualDWView virtualDWView = processorInstance.RootViewInstance.VirtualDataWindow;
                    virtualDWView.HandleStartIndex(spec);
                    stopCallback = new ProxyStopCallback(() => virtualDWView.HandleStopIndex(spec));
                }
                else
                {
                    try {
                        processorInstance.RootViewInstance.AddExplicitIndex(spec.IsUnique, spec.IndexName, spec.Columns, isRecoveringResilient);
                    }
                    catch (ExprValidationException e) {
                        throw new EPException("Failed to create index: " + e.Message, e);
                    }
                    stopCallback = new ProxyStopCallback(() => {
                        // we remove the index when context partitioned.
                        // when not context partition the index gets removed when the last reference to the named window gets destroyed.
                        if (contextName != null)
                        {
                            var instance = namedWindowProcessor.GetProcessorInstance(agentInstanceId);
                            if (instance != null)
                            {
                                instance.RemoveExplicitIndex(spec.IndexName);
                            }
                        }
                    });
                }
            }
            else
            {
                // handle table access
                try {
                    TableStateInstance instance = services.TableService.GetState(tableName, agentInstanceContext.AgentInstanceId);
                    instance.AddExplicitIndex(spec, isRecoveringResilient, contextName != null);
                }
                catch (ExprValidationException ex) {
                    throw new EPException("Failed to create index: " + ex.Message, ex);
                }
                stopCallback = new ProxyStopCallback(() => {
                    // we remove the index when context partitioned.
                    // when not context partition the index gets removed when the last reference to the table gets destroyed.
                    if (contextName != null)
                    {
                        TableStateInstance instance = services.TableService.GetState(tableName, agentInstanceId);
                        if (instance != null)
                        {
                            instance.RemoveExplicitIndex(spec.IndexName);
                        }
                    }
                });
            }

            return(new StatementAgentInstanceFactoryCreateIndexResult(finalView, stopCallback, agentInstanceContext));
        }