private void CleanupEventHandlers(ClientConnection connection)
{
var keys = new List<long>();
foreach (var entry in _listenerInvocations)
{
if (entry.Value.SentConnection == connection && entry.Value.BoundConnection == null)
{
keys.Add(entry.Key);
}
}
foreach (var key in keys)
{
ClientListenerInvocation invocation;
_listenerInvocations.TryRemove(key, out invocation);
if (invocation.Future.IsComplete && invocation.Future.Result != null)
{
//re-register listener on a new node
if (!_isShutDown)
{
_client.GetClientExecutionService().Schedule(() =>
{
ReregisterListener(invocation)
.ToTask()
.ContinueWith(t => { Logger.Warning("Cannot reregister listener.", t.Exception); },
TaskContinuationOptions.OnlyOnFaulted |
TaskContinuationOptions.ExecuteSynchronously);
}, RetryWaitTime, TimeUnit.Milliseconds);
}
}
}
}