diff --git a/src/net/KNet/Specific/Replicator/KNetCompactedReplicator.cs b/src/net/KNet/Specific/Replicator/KNetCompactedReplicator.cs index 6980f23f2c..4cc9b4d11e 100644 --- a/src/net/KNet/Specific/Replicator/KNetCompactedReplicator.cs +++ b/src/net/KNet/Specific/Replicator/KNetCompactedReplicator.cs @@ -102,6 +102,11 @@ public interface IKNetCompactedReplicator : IDictionary + /// Called when a [, ] is added by consuming data from the others + /// + event Action, KeyValuePair> OnRemoteAdd; + /// /// Called when a [, ] is updated by consuming data from the others /// @@ -112,6 +117,11 @@ public interface IKNetCompactedReplicator : IDictionary event Action, KeyValuePair> OnRemoteRemove; + /// + /// Called when a [, ] is added on this + /// + event Action, KeyValuePair> OnLocalAdd; + /// /// Called when a [, ] is updated on this /// @@ -515,12 +525,18 @@ public override void OnPartitionsLost(Java.Util.Collection + public event Action, KeyValuePair> OnRemoteAdd; + /// public event Action, KeyValuePair> OnRemoteUpdate; /// public event Action, KeyValuePair> OnRemoteRemove; + /// + public event Action, KeyValuePair> OnLocalAdd; + /// public event Action, KeyValuePair> OnLocalUpdate; @@ -647,9 +663,11 @@ private void OnMessage(KNetConsumerRecord record) } else { + bool containsKey = true; ILocalDataStorage data; if (!_dictionary.TryGetValue(record.Key, out data)) { + containsKey = false; data = new LocalDataStorage(); _dictionary[record.Key] = data; } @@ -669,7 +687,14 @@ private void OnMessage(KNetConsumerRecord record) data.Value = record.Value; } } - OnRemoteUpdate?.Invoke(this, new KeyValuePair(record.Key, record.Value)); + if (containsKey) + { + OnRemoteUpdate?.Invoke(this, new KeyValuePair(record.Key, record.Value)); + } + else + { + OnRemoteAdd?.Invoke(this, new KeyValuePair(record.Key, record.Value)); + } } if (_OnConsumeSyncWaiter != null) @@ -777,9 +802,11 @@ private void AddOrUpdate(TKey key, TValue value) } else { + bool containsKey = true; ILocalDataStorage data; if (!_dictionary.TryGetValue(key, out data)) { + containsKey = false; data = new LocalDataStorage(); _dictionary[key] = data; } @@ -799,7 +826,14 @@ private void AddOrUpdate(TKey key, TValue value) data.Value = value; } } - OnLocalUpdate?.Invoke(this, new KeyValuePair(key, value)); + if (containsKey) + { + OnLocalUpdate?.Invoke(this, new KeyValuePair(key, value)); + } + else + { + OnLocalAdd?.Invoke(this, new KeyValuePair(key, value)); + } } } else if (UpdateModeOnConsume || UpdateModeOnConsumeSync)