|
|
@ -46,7 +46,7 @@ namespace ZeroLevel.Network
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Remove(endpoint);
|
|
|
|
RemoveLocked(endpoint);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
AppendByKeys(key, endpoint);
|
|
|
|
AppendByKeys(key, endpoint);
|
|
|
|
_endpoints.Add(endpoint, new string[3] { $"{endpoint.Address}:{endpoint.Port}", null, null });
|
|
|
|
_endpoints.Add(endpoint, new string[3] { $"{endpoint.Address}:{endpoint.Port}", null, null });
|
|
|
@ -80,10 +80,10 @@ namespace ZeroLevel.Network
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Remove(endpoint);
|
|
|
|
RemoveLocked(endpoint);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
AppendByKeys(key, endpoint);
|
|
|
|
AppendByKeys(key, endpoint);
|
|
|
|
_endpoints.Add(endpoint, new string[3] { key, null, null });
|
|
|
|
_endpoints.Add(endpoint, new string[3] { key.ToUpperInvariant(), null, null });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
finally
|
|
|
|
finally
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -105,12 +105,12 @@ namespace ZeroLevel.Network
|
|
|
|
var drop = _tableByKey[key].Source.ToArray();
|
|
|
|
var drop = _tableByKey[key].Source.ToArray();
|
|
|
|
for (int i = 0; i < drop.Length; i++)
|
|
|
|
for (int i = 0; i < drop.Length; i++)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Remove(drop[i]);
|
|
|
|
RemoveLocked(drop[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
foreach (var ep in endpoints)
|
|
|
|
foreach (var ep in endpoints)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
_endpoints.Add(ep, new string[3] { key, null, null });
|
|
|
|
_endpoints.Add(ep, new string[3] { key.ToUpperInvariant(), null, null });
|
|
|
|
AppendByKeys(key, ep);
|
|
|
|
AppendByKeys(key, ep);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -125,7 +125,7 @@ namespace ZeroLevel.Network
|
|
|
|
_lock.EnterWriteLock();
|
|
|
|
_lock.EnterWriteLock();
|
|
|
|
try
|
|
|
|
try
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Remove(endpoint);
|
|
|
|
RemoveLocked(endpoint);
|
|
|
|
if (key == null)
|
|
|
|
if (key == null)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
key = $"{endpoint.Address}:{endpoint.Port}";
|
|
|
|
key = $"{endpoint.Address}:{endpoint.Port}";
|
|
|
@ -139,7 +139,7 @@ namespace ZeroLevel.Network
|
|
|
|
{
|
|
|
|
{
|
|
|
|
AppendByGroup(key, endpoint);
|
|
|
|
AppendByGroup(key, endpoint);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_endpoints.Add(endpoint, new string[3] { key, null, null });
|
|
|
|
_endpoints.Add(endpoint, new string[3] { key.ToUpperInvariant(), type.ToUpperInvariant(), group.ToUpperInvariant() });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
finally
|
|
|
|
finally
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -148,16 +148,21 @@ namespace ZeroLevel.Network
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void Set(string key, string type, string group, IEnumerable<IPEndPoint> endpoints)
|
|
|
|
public void Set(string key, string type, string group, IEnumerable<IPEndPoint> endpoints)
|
|
|
|
{
|
|
|
|
|
|
|
|
_lock.EnterWriteLock();
|
|
|
|
|
|
|
|
try
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
foreach (var ep in endpoints)
|
|
|
|
foreach (var ep in endpoints)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Remove(ep);
|
|
|
|
RemoveLocked(ep);
|
|
|
|
Set(key, type, group, ep);
|
|
|
|
Set(key, type, group, ep);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void Remove(IPEndPoint endpoint)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
_lock.EnterWriteLock();
|
|
|
|
|
|
|
|
try
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
RemoveLocked(endpoint);
|
|
|
|
|
|
|
|
}
|
|
|
|
finally
|
|
|
|
finally
|
|
|
|
{
|
|
|
|
{
|
|
|
|
_lock.ExitWriteLock();
|
|
|
|
_lock.ExitWriteLock();
|
|
|
@ -167,6 +172,7 @@ namespace ZeroLevel.Network
|
|
|
|
#region GET
|
|
|
|
#region GET
|
|
|
|
public InvokeResult<IPEndPoint> Get(string key)
|
|
|
|
public InvokeResult<IPEndPoint> Get(string key)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
key = key.ToUpperInvariant();
|
|
|
|
if (_tableByKey.ContainsKey(key))
|
|
|
|
if (_tableByKey.ContainsKey(key))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (_tableByKey[key].MoveNext())
|
|
|
|
if (_tableByKey[key].MoveNext())
|
|
|
@ -176,6 +182,7 @@ namespace ZeroLevel.Network
|
|
|
|
}
|
|
|
|
}
|
|
|
|
public InvokeResult<IEnumerable<IPEndPoint>> GetAll(string key)
|
|
|
|
public InvokeResult<IEnumerable<IPEndPoint>> GetAll(string key)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
key = key.ToUpperInvariant();
|
|
|
|
if (_tableByKey.ContainsKey(key))
|
|
|
|
if (_tableByKey.ContainsKey(key))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (_tableByKey[key].MoveNext())
|
|
|
|
if (_tableByKey[key].MoveNext())
|
|
|
@ -185,6 +192,7 @@ namespace ZeroLevel.Network
|
|
|
|
}
|
|
|
|
}
|
|
|
|
public InvokeResult<IPEndPoint> GetByType(string type)
|
|
|
|
public InvokeResult<IPEndPoint> GetByType(string type)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
type = type.ToUpperInvariant();
|
|
|
|
if (_tableByTypes.ContainsKey(type))
|
|
|
|
if (_tableByTypes.ContainsKey(type))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (_tableByTypes[type].MoveNext())
|
|
|
|
if (_tableByTypes[type].MoveNext())
|
|
|
@ -194,6 +202,7 @@ namespace ZeroLevel.Network
|
|
|
|
}
|
|
|
|
}
|
|
|
|
public InvokeResult<IEnumerable<IPEndPoint>> GetAllByType(string type)
|
|
|
|
public InvokeResult<IEnumerable<IPEndPoint>> GetAllByType(string type)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
type = type.ToUpperInvariant();
|
|
|
|
if (_tableByTypes.ContainsKey(type))
|
|
|
|
if (_tableByTypes.ContainsKey(type))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (_tableByTypes[type].MoveNext())
|
|
|
|
if (_tableByTypes[type].MoveNext())
|
|
|
@ -203,6 +212,7 @@ namespace ZeroLevel.Network
|
|
|
|
}
|
|
|
|
}
|
|
|
|
public InvokeResult<IPEndPoint> GetByGroup(string group)
|
|
|
|
public InvokeResult<IPEndPoint> GetByGroup(string group)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
group = group.ToUpperInvariant();
|
|
|
|
if (_tableByGroups.ContainsKey(group))
|
|
|
|
if (_tableByGroups.ContainsKey(group))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (_tableByGroups[group].MoveNext())
|
|
|
|
if (_tableByGroups[group].MoveNext())
|
|
|
@ -212,6 +222,7 @@ namespace ZeroLevel.Network
|
|
|
|
}
|
|
|
|
}
|
|
|
|
public InvokeResult<IEnumerable<IPEndPoint>> GetAllByGroup(string group)
|
|
|
|
public InvokeResult<IEnumerable<IPEndPoint>> GetAllByGroup(string group)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
group = group.ToUpperInvariant();
|
|
|
|
if (_tableByGroups.ContainsKey(group))
|
|
|
|
if (_tableByGroups.ContainsKey(group))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (_tableByGroups[group].MoveNext())
|
|
|
|
if (_tableByGroups[group].MoveNext())
|
|
|
@ -224,15 +235,15 @@ namespace ZeroLevel.Network
|
|
|
|
#region Private
|
|
|
|
#region Private
|
|
|
|
private void AppendByKeys(string key, IPEndPoint endpoint)
|
|
|
|
private void AppendByKeys(string key, IPEndPoint endpoint)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Append(key, endpoint, _tableByKey);
|
|
|
|
Append(key.ToUpperInvariant(), endpoint, _tableByKey);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
private void AppendByType(string type, IPEndPoint endpoint)
|
|
|
|
private void AppendByType(string type, IPEndPoint endpoint)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Append(type, endpoint, _tableByTypes);
|
|
|
|
Append(type.ToUpperInvariant(), endpoint, _tableByTypes);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
private void AppendByGroup(string group, IPEndPoint endpoint)
|
|
|
|
private void AppendByGroup(string group, IPEndPoint endpoint)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Append(group, endpoint, _tableByGroups);
|
|
|
|
Append(group.ToUpperInvariant(), endpoint, _tableByGroups);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
private void Append(string key, IPEndPoint value, Dictionary<string, RoundRobinCollection<IPEndPoint>> dict)
|
|
|
|
private void Append(string key, IPEndPoint value, Dictionary<string, RoundRobinCollection<IPEndPoint>> dict)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -243,7 +254,9 @@ namespace ZeroLevel.Network
|
|
|
|
dict[key].Add(value);
|
|
|
|
dict[key].Add(value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void Remove(IPEndPoint endpoint)
|
|
|
|
private void RemoveLocked(IPEndPoint endpoint)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (_endpoints.ContainsKey(endpoint))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var refs = _endpoints[endpoint];
|
|
|
|
var refs = _endpoints[endpoint];
|
|
|
|
if (refs[0] != null && _tableByKey.ContainsKey(refs[0])) _tableByKey[refs[0]].Remove(endpoint);
|
|
|
|
if (refs[0] != null && _tableByKey.ContainsKey(refs[0])) _tableByKey[refs[0]].Remove(endpoint);
|
|
|
@ -251,6 +264,7 @@ namespace ZeroLevel.Network
|
|
|
|
if (refs[2] != null && _tableByGroups.ContainsKey(refs[2])) _tableByGroups[refs[2]].Remove(endpoint);
|
|
|
|
if (refs[2] != null && _tableByGroups.ContainsKey(refs[2])) _tableByGroups[refs[2]].Remove(endpoint);
|
|
|
|
_endpoints.Remove(endpoint);
|
|
|
|
_endpoints.Remove(endpoint);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|