예제 #1
0
        /// <summary>
        ///         连接
        /// </summary>
        /// <returns>操作结果</returns>
        public bool StartDispatch()
        {
            lock (_lockFlag)
            {
                lock (_lockFlag)
                {
                    if (ConnectState != ConnectState.Connected)
                    {
                        return(false);
                    }

                    if (DispatchState == DispatchState.Established)
                    {
                        return(true);
                    }

                    DispatchState = DispatchState.Establishing;

                    if (!IsEnable)
                    {
                        this.Warn("未启用");

                        DispatchState = DispatchState.Terminated;
                        return(false);
                    }

                    var result = StartDispatchCore();

                    DispatchState = result ? DispatchState.Established : DispatchState.Terminated;

                    return(result);
                }
            }
        }
예제 #2
0
        internal void RestoreDispatchState(DispatchState DispatchState)
        {
            IntPtr[] stackTrace = DispatchState.StackTrace;
            int      idxFirstFreeStackTraceEntry = 0;

            if (stackTrace != null)
            {
                IntPtr[] newStackTrace = new IntPtr[stackTrace.Length + 1];
                Array.Copy(stackTrace, 0, newStackTrace, 0, stackTrace.Length);
                stackTrace = newStackTrace;
                while (stackTrace[idxFirstFreeStackTraceEntry] != (IntPtr)0)
                {
                    idxFirstFreeStackTraceEntry++;
                }
                stackTrace[idxFirstFreeStackTraceEntry++] = EdiSeparator;
            }

            // Since EDI can be created at various points during exception dispatch (e.g. at various frames on the stack) for the same exception instance,
            // they can have different data to be restored. Thus, to ensure atomicity of restoration from each EDI, perform the restore under a lock.
            lock (s_DispatchStateLock)
            {
                _corDbgStackTrace            = stackTrace;
                _idxFirstFreeStackTraceEntry = idxFirstFreeStackTraceEntry;
            }
        }
예제 #3
0
 private void EventPumpStateChanged(DispatchState state)
 {
     if (state == DispatchState.Idle)
     {
         EventPump.Instance.EventPumpStateChanged -= EventPumpStateChanged;
     }
 }
예제 #4
0
        /// <summary>
        /// Asynchronously creates a new search <see cref="Job"/>.
        /// </summary>
        /// <remarks>
        /// This method uses the <a href="http://goo.gl/JZcPEb">POST search/jobs</a>
        /// endpoint to start a new search <see cref="Job"/> as specified by
        /// <paramref name="args"/>.
        /// </remarks>
        /// <param name="search">
        /// Search string.
        /// </param>
        /// <param name="count">
        ///
        /// </param>
        /// <param name="mode">
        ///
        /// </param>
        /// <param name="args">
        /// Optional search arguments.
        /// </param>
        /// <param name="customArgs">
        ///
        /// </param>
        /// <param name="requiredState">
        ///
        /// </param>
        /// <returns>
        /// An object representing the search job that was created.
        /// </returns>
        public virtual async Task <Job> CreateAsync(string search, int count    = 100,
                                                    ExecutionMode mode          = ExecutionMode.Normal, JobArgs args = null,
                                                    CustomJobArgs customArgs    = null,
                                                    DispatchState requiredState = DispatchState.Running)
        {
            var arguments = new Argument[]
            {
                new Argument("search", search),
                new Argument("count", count)
            }
            .AsEnumerable();

            if (args != null)
            {
                arguments = arguments.Concat(args);
            }

            if (customArgs != null)
            {
                arguments = arguments.Concat(customArgs);
            }

            var job = await this.CreateAsync(arguments, requiredState).ConfigureAwait(false);

            return(job);
        }
예제 #5
0
        /// <inheritdoc/>
        public virtual async Task GetAsync(DispatchState dispatchState, int delay = 30000, int retryInterval = 250)
        {
            using (var cancellationTokenSource = new CancellationTokenSource())
            {
                // Timeout if Job is never at least the requiredState
                cancellationTokenSource.CancelAfter(delay);
                var token = cancellationTokenSource.Token;

                for (int i = 0; ; i++)
                {
                    using (var response = await this.Context.GetAsync(this.Namespace, this.ResourceName, token).ConfigureAwait(false))
                    {
                        if (response.Message.StatusCode != HttpStatusCode.NoContent)
                        {
                            await response.EnsureStatusCodeAsync(HttpStatusCode.OK).ConfigureAwait(false);

                            await this.ReconstructSnapshotAsync(response).ConfigureAwait(false);

                            // None or Parsing are the only states to continue checking status for
                            if (this.DispatchState >= dispatchState || this.DispatchState == DispatchState.Queued)
                            {
                                break;
                            }
                        }
                    }

                    await Task.Delay(retryInterval).ConfigureAwait(false);

                    retryInterval += retryInterval / 2;
                }
            }
        }
예제 #6
0
 public Task <TJob> CreateAsync(string search, int count    = 100, ExecutionMode mode        = ExecutionMode.Normal,
                                JobArgs args                = null, CustomJobArgs customArgs = null,
                                DispatchState requiredState = DispatchState.Running)
 {
     Contract.Requires <ArgumentNullException>(search != null);
     return(default(Task <TJob>));
 }
예제 #7
0
        /// <summary>
        ///         连接
        /// </summary>
        /// <returns>操作结果</returns>
        public Result StartDispatch()
        {
            lock (_lockFlag)
            {
                lock (_lockFlag)
                {
                    if (ConnectState != ConnectState.Connected)
                    {
                        return(Result.Failed);
                    }

                    if (DispatchState == DispatchState.Established)
                    {
                        return(Result.Successed);
                    }

                    DispatchState = DispatchState.Establishing;

                    if (!IsEnable)
                    {
                        this.Warn("未启用");

                        DispatchState = DispatchState.Terminated;
                        return(Result.Failed);
                    }

                    var result = StartDispatchCore();

                    DispatchState = result.IsSuccessed ? DispatchState.Established : DispatchState.Terminated;

                    return(result);
                }
            }
        }
예제 #8
0
        /// <inheritdoc/>
        public virtual async Task GetAsync(DispatchState dispatchState, int delay = 30000, int retryInterval = 250)
        {
            using (var cancellationTokenSource = new CancellationTokenSource())
            {
                cancellationTokenSource.CancelAfter(delay);
                var token = cancellationTokenSource.Token;

                for (int i = 0; ; i++)
                {
                    using (var response = await this.Context.GetAsync(this.Namespace, this.ResourceName, token).ConfigureAwait(false))
                    {
                        if (response.Message.StatusCode != HttpStatusCode.NoContent)
                        {
                            await response.EnsureStatusCodeAsync(HttpStatusCode.OK).ConfigureAwait(false);

                            await this.ReconstructSnapshotAsync(response).ConfigureAwait(false);

                            if (this.DispatchState >= dispatchState)
                            {
                                break;
                            }
                        }
                    }

                    await Task.Delay(retryInterval).ConfigureAwait(false);

                    retryInterval += retryInterval / 2;
                }
            }
        }
예제 #9
0
        /// <summary>
        ///         断开连接
        /// </summary>
        /// <returns>操作结果</returns>
        public bool StopDispatch()
        {
            lock (_lockFlag)
            {
                if (DispatchState == DispatchState.Terminated)
                {
                    return(true);
                }

                DispatchState = DispatchState.Terminating;

                if (!IsEnable)
                {
                    this.Warn("未启用");

                    DispatchState = DispatchState.Terminated;
                    return(true);
                }

                var result = StopDispatchCore();

                DispatchState = DispatchState.Terminated;

                return(result);
            }
        }
예제 #10
0
        private void Update(IRFWorkQueueableItem i, DispatchState state, long?weight, RFProcessingResult result)
        {
            var processName  = (i as RFProcessInstruction)?.ProcessName;
            var instanceName = (i as RFGraphProcessInstruction)?.Instance?.Name;
            var instanceDate = (i as RFGraphProcessInstruction)?.Instance?.ValueDate;

            Update(i.DispatchKey(), processName, instanceName, instanceDate, state, weight, result, i as RFInstruction);
        }
예제 #11
0
        /// <inheritdoc/>
        public virtual async Task TransitionAsync(DispatchState dispatchState, int delay = 30000, int retryInterval = 250)
        {
            if (this.DispatchState >= dispatchState)
            {
                return;
            }

            await this.GetAsync(dispatchState, delay, retryInterval).ConfigureAwait(false);
        }
예제 #12
0
        async Task TransitionAsync(DispatchState requiredState)
        {
            while (this.DispatchState < requiredState)
            {
                await Task.Delay(500);

                await this.GetAsync();
            }
        }
예제 #13
0
    public static void RemoveLinkedState(string name, DispatchState linkedState)
    {
        var ss = m_linkedStates.Get(name);

        if (ss == null || ss.Count < 1)
        {
            return;
        }
        ss.Remove(linkedState);
    }
예제 #14
0
        private void Dispatch(DispatchState state)
        {
            if (state == null)
            {
                return;
            }

            //foreach(var channel in _channels)
            //{
            //    channel.Dispatch(state.SourceData);
            //}
        }
예제 #15
0
        async Task<SearchResultStream> GetSearchResultsAsync(DispatchState dispatchState, string endpoint, IEnumerable<Argument> args)
        {
            await this.TransitionAsync(dispatchState).ConfigureAwait(false);

            var resourceName = new ResourceName(this.ResourceName, endpoint);
            var response = await this.Context.GetAsync(this.Namespace, resourceName, args).ConfigureAwait(false);

            try
            {
                var searchResults = await SearchResultStream.CreateAsync(response).ConfigureAwait(false);
                return searchResults;
            }
            catch 
            {
                response.Dispose();
                throw;
            }
        }
예제 #16
0
        async Task <Job> CreateAsync(IEnumerable <Argument> arguments, DispatchState requiredState)
        {
            string searchId;

            using (var response = await this.Context.PostAsync(this.Namespace, ClassResourceName, arguments).ConfigureAwait(false))
            {
                await response.EnsureStatusCodeAsync(HttpStatusCode.Created).ConfigureAwait(false);

                searchId = await response.XmlReader.ReadResponseElementAsync("sid").ConfigureAwait(false);
            }

            Job job = new Job(this.Context, this.Namespace, name: searchId);

            await job.GetAsync().ConfigureAwait(false);

            await job.TransitionAsync(requiredState).ConfigureAwait(false);

            return(job);
        }
예제 #17
0
        public static Result Dispatch(OpaqueMessageQueue Source, IAsyncQueueDispatcher Destination)
        {
            var msg = Source.WindowPeek(0);

            if (msg == null)
            {
                return(Result.SourceEmpty);
            }
            if (!Destination.CanPush)
            {
                return(Result.DestinationLocked);
            }
            var state = new DispatchState {
                LookupId = msg.Id, Source = Source
            };

            if (!Destination.BeginPush(msg, AsyncDispatched, state))
            {
                return(Result.DestinationFailure);
            }
            return(Result.Deferred);
        }
예제 #18
0
        private void OnEventPumpStateChanged(DispatchState state)
        {
            if (currentState == state)
            {
                return;
            }

            // state change is occuring
            switch (state)
            {
            case DispatchState.Running:
                currentState = state;
                StartContext();

                break;

            case DispatchState.Idle:
                currentState = state;
                StopContext();

                break;
            }
        }
예제 #19
0
 public abstract Task GetAsync(DispatchState dispatchState, int delay, int retryInterval);
예제 #20
0
 internal void RestoreDispatchState(DispatchState state)
 {
 }
예제 #21
0
        private void Update(string dispatchKey, string processName, string instanceName, RFDate?valueDate, DispatchState state, long?weight, RFProcessingResult result, RFInstruction instruction)
        {
            try
            {
                using (var conn = new SqlConnection(_context.SystemConfig.DocumentStoreConnectionString))
                {
                    conn.Open();
                    using (var cmd = new SqlCommand("RIFF.UpdateDispatchQueue", conn))
                    {
                        cmd.CommandType = System.Data.CommandType.StoredProcedure;
                        cmd.Parameters.AddWithValue("@Environment", RFStringHelpers.StringToSQL(_context.SystemConfig.Environment, false, 10, false));
                        cmd.Parameters.AddWithValue("@ItemType", (int)ItemType.GraphProcessInstruction);
                        cmd.Parameters.AddWithValue("@DispatchKey", RFStringHelpers.StringToSQL(dispatchKey, false, 140, false));
                        cmd.Parameters.AddWithValue("@ProcessName", RFStringHelpers.StringToSQL(processName, true, 100, false));
                        cmd.Parameters.AddWithValue("@GraphInstance", RFStringHelpers.StringToSQL(instanceName, true, 20, false));
                        if (valueDate != null && valueDate.Value.IsValid())
                        {
                            cmd.Parameters.AddWithValue("@ValueDate", valueDate.Value.Date);
                        }
                        else
                        {
                            cmd.Parameters.AddWithValue("@ValueDate", DBNull.Value);
                        }
                        if (weight.HasValue)
                        {
                            cmd.Parameters.AddWithValue("@Weight", weight.Value);
                        }
                        else
                        {
                            cmd.Parameters.AddWithValue("@Weight", DBNull.Value);
                        }
                        cmd.Parameters.AddWithValue("@DispatchState", (int)state);
                        if (state == DispatchState.Started)
                        {
                            cmd.Parameters.AddWithValue("@LastStart", DateTimeOffset.Now);
                        }
                        else
                        {
                            cmd.Parameters.AddWithValue("@LastStart", DBNull.Value);
                        }
                        if (result?.Messages != null)
                        {
                            cmd.Parameters.AddWithValue("@Message", RFStringHelpers.StringToSQL(String.Join("|", result.Messages), true, 200, false));
                        }
                        else if (state == DispatchState.Finished || state == DispatchState.Skipped || state == DispatchState.Started)
                        {
                            cmd.Parameters.AddWithValue("@Message", String.Empty); // clear past error messages
                        }
                        else
                        {
                            cmd.Parameters.AddWithValue("@Message", DBNull.Value);
                        }
                        if (result != null)
                        {
                            cmd.Parameters.AddWithValue("@ShouldRetry", result.ShouldRetry);
                        }
                        else
                        {
                            cmd.Parameters.AddWithValue("@ShouldRetry", false);
                        }
                        if (state == DispatchState.Queued && instruction != null)
                        {
                            cmd.Parameters.AddWithValue("@InstructionType", RFStringHelpers.StringToSQL(instruction.GetType().FullName, false, 200, false));
                            cmd.Parameters.AddWithValue("@InstructionContent", RFXMLSerializer.SerializeContract(instruction));
                        }
                        else
                        {
                            cmd.Parameters.AddWithValue("@InstructionType", DBNull.Value);
                            cmd.Parameters.AddWithValue("@InstructionContent", DBNull.Value);
                        }

                        cmd.ExecuteNonQuery();
                    }
                }
            }
            catch (Exception ex)
            {
                _context.Log.Exception(this, "Error updating Dispatch Store", ex);
            }
        }
예제 #22
0
 public static void AddLinkedState(string name, DispatchState linkedState)
 {
     m_linkedStates[name].Add(linkedState);
 }
예제 #23
0
        /// <summary>
        /// Touches the job after it is queryable.
        /// </summary>
        /// <param name="job">The job</param>
        async Task CheckJobAsync(Job job, Service service)
        {
            string dummyString;
            //string[] dummyList;
            long     dummyInt;
            bool     dummyBool;
            DateTime dummyDateTime;
            double   dummyDouble;

            dummyDateTime = job.CursorTime;
            //dummyString = job.Delegate;
            dummyInt = job.DiskUsage;
            DispatchState dummyDispatchState = job.DispatchState;

            dummyDouble   = job.DoneProgress;
            dummyInt      = job.DropCount;
            dummyDateTime = job.EarliestTime;
            dummyInt      = job.EventAvailableCount;
            dummyInt      = job.EventCount;
            dummyInt      = job.EventFieldCount;
            dummyBool     = job.EventIsStreaming;
            dummyBool     = job.EventIsTruncated;
            dummyString   = job.EventSearch;
            SortDirection sordirection      = job.EventSorting;
            long          indexEarliestTime = job.IndexEarliestTime;
            long          indexLatestTime   = job.IndexLatestTime;

            dummyString = job.Keywords;
            //dummyString = job.Label;

            ServerInfo serverInfo = await service.Server.GetInfoAsync();

            if (serverInfo.Version.CompareTo(new Version(6, 0)) < 0)
            {
                dummyDateTime = job.LatestTime;
            }

            dummyInt    = job.NumPreviews;
            dummyInt    = job.Priority;
            dummyString = job.RemoteSearch;
            //dummyString = job.ReportSearch;
            dummyInt    = job.ResultCount;
            dummyBool   = job.ResultIsStreaming;
            dummyInt    = job.ResultPreviewCount;
            dummyDouble = job.RunDuration;
            dummyInt    = job.ScanCount;
            dummyString = job.EventSearch;               // Search;
            DateTime jobearliestTime = job.EarliestTime; //SearchEarliestTime;
            DateTime joblatestTime   = job.LatestTime;
            ReadOnlyCollection <string> providers = job.SearchProviders;

            dummyString = job.Sid;
            dummyInt    = job.StatusBuckets;
            dummyInt    = job.Ttl;
            dummyBool   = job.IsDone;
            dummyBool   = job.IsFailed;
            dummyBool   = job.IsFinalized;
            dummyBool   = job.IsPaused;
            dummyBool   = job.IsPreviewEnabled;
            dummyBool   = job.IsRealTimeSearch;
            dummyBool   = job.IsRemoteTimeline;
            dummyBool   = job.IsSaved;
            dummyBool   = job.IsSavedSearch;
            dummyBool   = job.IsZombie;
            Assert.Equal(job.Name, job.Sid);
        }
예제 #24
0
 public abstract Task GetAsync(DispatchState dispatchState, int delay, int retryInterval);
예제 #25
0
 public abstract Task TransitionAsync(DispatchState dispatchState, int delay, int retryInterval);
예제 #26
0
    private void _DispatchEvent(string name, ref bool pool, ref Event_ e)
    {
        if (destroyed)
        {
            return;
        }

        var queue = m_states.Get(name);

        if (queue >= EventManager.MAX_ALLOWED_QUEUE)
        {
            Logger.LogError("EventDispatcher event [{0}] reached the max allowed event recursion queue size, this may cause stack overflow, ignored. Max allowed queue size: [{1}]", name, EventManager.MAX_ALLOWED_QUEUE);
#if UNITY_EDITOR
            UnityEditor.EditorApplication.isPaused = true;
#endif
            return;
        }

        var glss = EventManager.GetGlobalListeners(name);
        var lss  = m_listeners.Get(name);

        int size = lss == null ? 0 : lss.Count, gsize = glss == null ? 0 : glss.Count, total = size + gsize;
        if (total < 1)
        {
            return;
        }

        m_states[name] = queue + 1;

        var ss = m_dispatchStates.Get(name);
        if (ss == null)
        {
            ss = new DispatchState[EventManager.MAX_ALLOWED_QUEUE];
            for (var i = 0; i < ss.Length; ++i)
            {
                ss[i] = new DispatchState();
            }
            m_dispatchStates.Add(name, ss);
        }

        var s = ss[queue];
        s.Set(size, gsize, total, 0);

        if (gsize > 0)
        {
            EventManager.AddLinkedState(name, s);
        }

        dispatchCount++;
        dispatching = true;

        if (e == null)
        {
            e = Event_.defaultEvent; pool = true;
        }
        e.SetInfo(name, this, false, true);

        for (; s.i < s.t; ++s.i)
        {
            var ls = s.i < s.s ? lss[s.i] : glss[s.i - s.s];
            if (!ls || !ls.Invoke(e))
            {
                continue;
            }

            if (destroyed || e.cancle)
            {
                break;
            }
        }

        if (gsize > 0)
        {
            EventManager.RemoveLinkedState(name, s);
        }

        glss        = null;
        dispatching = --dispatchCount < 1;

        if (destroyed)
        {
            return;
        }

        queue          = m_states[name] - 1;
        m_states[name] = queue;
    }
예제 #27
0
 public abstract Task TransitionAsync(DispatchState dispatchState, int delay, int retryInterval);
예제 #28
0
        /// <summary>
        /// Touches the job after it is queryable.
        /// </summary>
        /// <param name="job">The job</param>
        private void CheckJob(Job job, Service service)
        {
            string dummyString;

            string[] dummyList;
            long     dummyInt;
            bool     dummyBool;
            DateTime dummyDateTime;
            double   dummyDouble;

            // wait until job is queryable
            this.Ready(job);
            dummyDateTime = job.CursorTime;
            //dummyString = job.Delegate;
            dummyInt = job.DiskUsage;
            DispatchState dummyDispatchState = job.DispatchState;

            dummyDouble   = job.DoneProgress;
            dummyInt      = job.DropCount;
            dummyDateTime = job.EarliestTime;
            dummyInt      = job.EventAvailableCount;
            dummyInt      = job.EventCount;
            dummyInt      = job.EventFieldCount;
            dummyBool     = job.EventIsStreaming;
            dummyBool     = job.EventIsTruncated;
            dummyString   = job.EventSearch;
            SortDirection sordirection      = job.EventSorting;
            long          indexEarliestTime = job.IndexEarliestTime;
            long          indexLatestTime   = job.IndexLatestTime;

            dummyString = job.Keywords;
            //dummyString = job.Label;

            if (this.VersionCompare(service, "6.0") < 0)
            {
                dummyDateTime = job.LatestTime;
            }

            dummyInt    = job.NumPreviews;
            dummyInt    = job.Priority;
            dummyString = job.RemoteSearch;
            //dummyString = job.ReportSearch;
            dummyInt    = job.ResultCount;
            dummyBool   = job.ResultIsStreaming;
            dummyInt    = job.ResultPreviewCount;
            dummyDouble = job.RunDuration;
            dummyInt    = job.ScanCount;
            dummyString = job.EventSearch;// Search;
            //dummyString = job.SearchEarliestTime;
            //dummyString = job.SearchLatestTime;
            //dummyList = job.SearchProviders;
            dummyString = job.Sid;
            dummyInt    = job.StatusBuckets;
            dummyInt    = job.Ttl;
            dummyBool   = job.IsDone;
            dummyBool   = job.IsFailed;
            dummyBool   = job.IsFinalized;
            dummyBool   = job.IsPaused;
            dummyBool   = job.IsPreviewEnabled;
            dummyBool   = job.IsRealTimeSearch;
            dummyBool   = job.IsRemoteTimeline;
            dummyBool   = job.IsSaved;
            dummyBool   = job.IsSavedSearch;
            dummyBool   = job.IsZombie;
            Assert.Equal(job.Name, job.Sid);
        }