Skip to content

Commit

Permalink
Improved subscription tracking, zyanfx#3.
Browse files Browse the repository at this point in the history
  • Loading branch information
yallie committed Feb 20, 2019
1 parent e7ab2e3 commit 9e61ef6
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
12 changes: 6 additions & 6 deletions source/Zyan.Communication/ServerSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,19 +91,19 @@ internal SubscriptionTracker RemoteSubscriptionTracker
}

/// <summary>
/// Adds remote subscription to the trackers.
/// Adds remote subscriptions to the tracker.
/// </summary>
internal string AddRemoteSubscription(DelegateCorrelationInfo delegateCorrelationInfo)
internal string TrackRemoteSubscriptions(IEnumerable<DelegateCorrelationInfo> delegateCorrelationSet)
{
return RemoteSubscriptionTracker.Add(new[] { delegateCorrelationInfo });
return RemoteSubscriptionTracker.Add(delegateCorrelationSet);
}

/// <summary>
/// Removes remote subscription from the tracker.
/// Removes remote subscriptions from the tracker.
/// </summary>
internal string RemoveRemoteSubscription(DelegateCorrelationInfo delegateCorrelationInfo)
internal string UntrackRemoteSubscriptions(IEnumerable<DelegateCorrelationInfo> delegateCorrelationSet)
{
return RemoteSubscriptionTracker.Remove(new[] { delegateCorrelationInfo });
return RemoteSubscriptionTracker.Remove(delegateCorrelationSet);
}

/// <summary>
Expand Down
1 change: 1 addition & 0 deletions source/Zyan.Communication/ZyanConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -993,6 +993,7 @@ private void ReconnectRemoteEventsCore()
{
var subscriptions = AliveProxies.Select(p => p.GetActiveSubscriptions()).Where(s => !s.DelegateCorrelationSet.IsNullOrEmpty()).ToArray();
var correlationSets = subscriptions.SelectMany(s => s.DelegateCorrelationSet).ToArray();
PrepareCallContext(false);
RemoteDispatcher.ReconnectEventHandlers(subscriptions);
_localSubscriptionTracker.Reset(correlationSets);
}
Expand Down
14 changes: 8 additions & 6 deletions source/Zyan.Communication/ZyanDispatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ private void CreateClientServerWires(Type type, EventStub eventStub, IEnumerable
{
eventStub.RemoveHandler(correlationInfo.DelegateMemberName, dynamicEventWire.InDelegate);
wiringList.Remove(correlationInfo.CorrelationID);
currentSession.RemoveRemoteSubscription(correlationInfo);
currentSession.UntrackRemoteSubscriptions(new[] { correlationInfo });
}

_host.OnSubscriptionCanceled(new SubscriptionEventArgs
Expand All @@ -108,14 +108,15 @@ private void CreateClientServerWires(Type type, EventStub eventStub, IEnumerable
}
}

currentSession.AddRemoteSubscription(correlationInfo);
_host.OnSubscriptionAdded(new SubscriptionEventArgs
{
ComponentType = type,
DelegateMemberName = correlationInfo.DelegateMemberName,
CorrelationID = correlationInfo.CorrelationID,
});
}

currentSession.TrackRemoteSubscriptions(delegateCorrelationSet);
}

/// <summary>
Expand Down Expand Up @@ -143,10 +144,6 @@ private void RemoveClientServerWires(Type type, EventStub eventStub, IEnumerable
var dynamicWireDelegate = wiringList[correlationInfo.CorrelationID];
eventStub.RemoveHandler(correlationInfo.DelegateMemberName, dynamicWireDelegate);
wiringList.Remove(correlationInfo.CorrelationID);
if (currentSession != null)
{
currentSession.RemoveRemoteSubscription(correlationInfo);
}
}

_host.OnSubscriptionRemoved(new SubscriptionEventArgs
Expand All @@ -157,6 +154,11 @@ private void RemoveClientServerWires(Type type, EventStub eventStub, IEnumerable
});
}
}

if (currentSession != null)
{
currentSession.UntrackRemoteSubscriptions(delegateCorrelationSet);
}
}

/// <summary>
Expand Down

0 comments on commit 9e61ef6

Please sign in to comment.