public void RecoverBundles() { long id, maxId = ID_NOT_RECEIVED_AT_BACKEND; bool responseAvailable, localRecoveryDone, remoteRecoveryDone; DateTime?selfLastUpdate; MessageQueue[] controlQueuesOpen, controlQueues = null; MessageQueue recoveryQueue = null; var ttrqBundleControl = TimeSpan.FromSeconds(Kiss.GetTimeout(KissTimeout.BUNDLE_CONTROL_TTRQ)); var ttbrBundleControl = TimeSpan.FromSeconds(Kiss.GetTimeout(KissTimeout.BUNDLE_CONTROL_TTBR)); try { controlQueues = new Neighborhood(_sql, FORMAT_BUNDLE_CONTROL_POSTFIX).GetOthersQueues().ToArray(); controlQueuesOpen = new MessageQueue[controlQueues.Length]; controlQueues.CopyTo(controlQueuesOpen, 0); recoveryQueue = new Neighborhood(_sql, FORMAT_BUNDLE_RECOVERY_POSTFIX).GetLocalQueue(); localRecoveryDone = !(controlQueues.Length > 0); while (!localRecoveryDone) { for (var i = 0; i < controlQueues.Length; i++) { if (controlQueuesOpen[i] == null) { continue; } using (var msg = new Message(_clientId) { ResponseQueue = recoveryQueue, Formatter = controlQueues[i].Formatter, TimeToReachQueue = ttrqBundleControl, TimeToBeReceived = ttbrBundleControl, Extension = LargeMessage.ToMessageExtension(Guid.NewGuid()) }) { responseAvailable = false; controlQueues[i].Send(msg, MessageQueueTransactionType.Single); for (var j = 0; j < MAX_RETRY_BUNDLE_RECOVERY && !responseAvailable; j++) { Thread.Sleep(SLEEP_BUNDLE_RECOVERY); responseAvailable = LargeMessage.IsCorrelationAvailable(recoveryQueue, msg.Id); } if (responseAvailable) { using (var response = recoveryQueue. ReceiveByCorrelationId(msg.Id, MessageQueueTransactionType.Single)) { id = (long)response.Body; if (id > maxId) { maxId = id; } } controlQueuesOpen[i] = null; } } } localRecoveryDone = Array.TrueForAll(controlQueuesOpen, q => q == null); } RemoveAllBundlesAndStages(); do { QueryStageList(true); WaitForSelfStage(true, null, out id, out selfLastUpdate); remoteRecoveryDone = id != ID_NO_ANSWER_FROM_BACKEND; if (!remoteRecoveryDone) { Thread.Sleep(SLEEP_BUNDLE_RECOVERY); } } while (!remoteRecoveryDone); if (id > maxId) { maxId = id; } if (maxId != ID_NOT_RECEIVED_AT_BACKEND) { new Bundle(_sql, maxId, _clientId, _msmqCapacity).Recover(); } } finally { if (recoveryQueue != null) { recoveryQueue.Dispose(); } if (controlQueues != null) { foreach (var queue in controlQueues) { queue.Dispose(); } } } }
public void RecoverPersistentObjects() { bool localRecoveryDone; List <MessageQueue> controlQueues = null; MessageQueue recoveryQueue = null; var poListener = new PersistentObjectListener(_sql, _msmqCapacity); var ttrqPoControl = TimeSpan.FromSeconds(Kiss.GetTimeout(KissTimeout.PO_CONTROL_TTRQ)); var ttbrPoControl = TimeSpan.FromSeconds(Kiss.GetTimeout(KissTimeout.PO_CONTROL_TTBR)); try { controlQueues = new Neighborhood(_sql, FORMAT_PO_CONTROL_POSTFIX).GetOthersQueues(); recoveryQueue = new Neighborhood(_sql, FORMAT_PO_RECOVERY_POSTFIX).GetLocalQueue(); localRecoveryDone = !(controlQueues.Count > 0); if (localRecoveryDone) { poListener.Recover(recoveryQueue, string.Empty); } while (!localRecoveryDone) { foreach (var controlQueue in controlQueues) { using (var msg = new Message { ResponseQueue = recoveryQueue, Formatter = controlQueue.Formatter, TimeToReachQueue = ttrqPoControl, TimeToBeReceived = ttbrPoControl, Extension = LargeMessage.ToMessageExtension(Guid.NewGuid()) }) { controlQueue.Send(msg, MessageQueueTransactionType.Single); for (var i = 0; i < MAX_RETRY_PO_RECOVERY && !localRecoveryDone; i++) { Thread.Sleep(SLEEP_PO_RECOVERY); localRecoveryDone = LargeMessage.IsCorrelationAvailable(recoveryQueue, msg.Id); } if (localRecoveryDone) { poListener.Recover(recoveryQueue, msg.Id); break; } } } } } finally { if (recoveryQueue != null) { recoveryQueue.Dispose(); } if (controlQueues != null) { foreach (var queue in controlQueues) { queue.Dispose(); } } } }