Ejemplo n.º 1
0
        public override void Dispose()
        {
            using (Trace.Log())
            {
                Console.WriteLine($"Disposing {Identifier}");

                Disposed?.Invoke(this);

                disposed = true;

                activeJob?.CancelTasks(pendingTasks.Values);
                activeJob?.CancelTasks(activeTasks.Values);
                activeJob = null;

                activeTasks?.Clear();
                pendingTasks?.Clear();

                if (dispatcher != null)
                {
                    dispatcher.ActiveJobChanged -= OnActiveJobChanged;
                    dispatcher = null;
                }

                connection?.Dispose();
                connection = null;

                TaskStateChanged = null;
            }
        }
Ejemplo n.º 2
0
        public Agent(Distributed.Dispatcher dispatcher, EndpointConnectionInfo info) : base(info)
        {
            using (Trace.Log())
            {
                this.dispatcher   = dispatcher;
                this.pendingTasks = new ConcurrentDictionary <string, TaskItem>();
                this.activeTasks  = new ConcurrentDictionary <string, TaskItem>();

                this.dispatcher.ActiveJobChanged += OnActiveJobChanged;

                this.connection = new AgentConnection(dispatcher, info);
                this.connection.StateChanged += (s) =>
                {
                    //if (s.OldState == ConnectionState.Connected && s.NewState == ConnectionState.Disconnected)
                    //{
                    //    dispatcher.ReleaseAgent(Identifier);
                    //}
                };
                this.connection.SetAgentState += SetAgentState;
                this.connection.TaskCompleted += OnTaskCompleted;
                this.connection.Start();
            }
        }