/// <summary> /// Finish close broker operation /// </summary> /// <param name="result">IAsyncResult instance</param> private void OnCloseBroker(IAsyncResult result) { object[] objArr = (object[])result.AsyncState; bool suspended = (bool)objArr[0]; int retry = (int)objArr[1]; BrokerManagementServiceClient client = (BrokerManagementServiceClient)objArr[2]; try { client.EndCloseBroker(result); } catch (Exception e) { TraceHelper.TraceEvent(this.sessionId, TraceEventType.Error, "[BrokerInfo] Failed to close broker: {0}\nRetryCount = {1}", e, retry); // Perform retry if retry>0 if (retry > 0) { retry--; BrokerManagementServiceClient newClient = this.CreateClient(); try { newClient.BeginCloseBroker(suspended, new AsyncCallback(this.callbackToCloseBroker), new object[] { suspended, retry, newClient }); } catch (Exception ex) { // Do not retry if BeginCloseBroker failed TraceHelper.TraceEvent(this.sessionId, TraceEventType.Error, "[BrokerInfo] Retry failed when calling BeginCloseBroker: {0}", ex); Utility.AsyncCloseICommunicationObject(newClient); } } else { // Kill broker worker process if it failed to close broker try { this.brokerProcess.KillBrokerProcess(); } catch (Exception ex) { TraceHelper.TraceError(this.sessionId, "[BrokerInfo] Failed to kill broker worker process: {0}", ex); } } } finally { Utility.AsyncCloseICommunicationObject(client); } }
/// <summary> /// Send a ctrl event to the broker process to close the broker /// </summary> /// <param name="suspended">indicating the suspended flag</param> public void CloseBroker(bool suspended) { BrokerManagementServiceClient client = this.CreateClient(); try { // Call CloseBroker asynchronously and don't care about result client.BeginCloseBroker(suspended, new AsyncCallback(this.callbackToCloseBroker), new object[] { suspended, RetryLimit, client }); } catch (Exception e) { TraceHelper.TraceEvent(this.sessionId, TraceEventType.Warning, "[BrokerInfo] Failed to close broker: {0}", e); Utility.AsyncCloseICommunicationObject(client); throw; } }