public virtual RegisterResponseInfo Update(UpdateInfo updateInfo)
{
if (updateInfo == null)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument("updateInfo", SR.GetString(SR.PeerNullRegistrationInfo));
}
ThrowIfClosed("Update");
if (!updateInfo.HasBody() || String.IsNullOrEmpty(updateInfo.MeshId) || updateInfo.NodeAddress == null)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument("updateInfo", SR.GetString(SR.PeerInvalidMessageBody, updateInfo));
}
Guid registrationId = updateInfo.RegistrationId;
RegistrationEntry entry;
MeshEntry meshEntry = GetMeshEntry(updateInfo.MeshId);
LiteLock ll = null;
//handle cases when Update ----s with Register.
if (updateInfo.RegistrationId == Guid.Empty || meshEntry == null)
{
return(Register(updateInfo.ClientId, updateInfo.MeshId, updateInfo.NodeAddress));
}
//
// preserve locking order between ThisLock and the LiteLock.
lock (ThisLock)
{
try
{
LiteLock.Acquire(out ll, meshEntry.Gate);
if (!meshEntry.EntryTable.TryGetValue(updateInfo.RegistrationId, out entry))
{
try
{
// upgrade to writer lock
ll.UpgradeToWriterLock();
return(Register(updateInfo.ClientId, updateInfo.MeshId, updateInfo.NodeAddress));
}
finally
{
ll.DowngradeFromWriterLock();
}
}
lock (entry)
{
entry.Address = updateInfo.NodeAddress;
entry.Expires = DateTime.UtcNow + this.RefreshInterval;
}
}
finally
{
LiteLock.Release(ll);
}
}
return(new RegisterResponseInfo(registrationId, RefreshInterval));
}