public Task ScheduleProcessCommand( InfrastructureServiceCommand command, TimeSpan timeout, CancellationToken cancelToken) { var commandContext = new PendingCommandContext(command, timeout, cancelToken); return(Task.Factory.StartNew( () => this.ProcessCommand(commandContext), cancelToken, TaskCreationOptions.PreferFairness, TaskScheduler.Default)); }
public PendingCommandContext( InfrastructureServiceCommand command, TimeSpan timeout, CancellationToken cancelToken) { this.command = command; this.stopwatch = new Stopwatch(); this.timeout = timeout; this.timer = new Timer(this.OnTimeout, null, Timeout.Infinite, Timeout.Infinite); this.cancelToken = cancelToken; this.faultHandler = null; this.handlerLock = new object(); // Attempt to reply with a failure to the CM // upon first processing each notification to // cover reply notification reply logic at the CM // this.injectReplyFault = true; }
public Task <string> RunCommandAsync(bool isAdminCommand, string input, TimeSpan timeout, CancellationToken cancellationToken) { Trace.WriteInfo(TraceType, "RunCommand: {0} (isAdminCommand = {1})", input, isAdminCommand); var notPrimaryTask = this.CheckPrimary(); if (notPrimaryTask != null) { return(notPrimaryTask); } // TestFabricClient.cpp depends on this string format for verification. // If you change this string, be sure to update the test. string replyMessage = string.Format( "[TestInfrastructureCoordinator reply for RunCommandAsync({0},'{1}')]", isAdminCommand, input); if (isAdminCommand) { if (string.Equals(input, "echo", StringComparison.OrdinalIgnoreCase)) { return(Utility.CreateCompletedTask(replyMessage)); } if (string.Equals(input, "emptyresponse", StringComparison.OrdinalIgnoreCase)) { return(Utility.CreateCompletedTask <string>(null)); } var command = InfrastructureServiceCommand.TryParseCommand(this.partitionId, input); return(this.commandProcessor.ScheduleProcessCommand(command, timeout, cancellationToken) .Then(_ => replyMessage)); } else { return(Utility.CreateCompletedTask(replyMessage)); } }