本文整理汇总了C#中ConnectionMetadata.UpdateKeepAlive方法的典型用法代码示例。如果您正苦于以下问题:C# ConnectionMetadata.UpdateKeepAlive方法的具体用法?C# ConnectionMetadata.UpdateKeepAlive怎么用?C# ConnectionMetadata.UpdateKeepAlive使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ConnectionMetadata
的用法示例。
在下文中一共展示了ConnectionMetadata.UpdateKeepAlive方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddConnection
/// <summary>
/// Adds a new connection to the list of tracked connections.
/// </summary>
/// <param name="connection">The connection to be added.</param>
public bool AddConnection(ITrackingConnection connection)
{
var newMetadata = new ConnectionMetadata(connection);
ConnectionMetadata oldMetadata = null;
bool isNewConnection = true;
_connections.AddOrUpdate(connection.ConnectionId, newMetadata, (key, old) =>
{
oldMetadata = old;
return newMetadata;
});
if (oldMetadata != null)
{
// Kick out the older connection. This should only happen when
// a previous connection attempt fails on the client side (e.g. transport fallback).
oldMetadata.Connection.End();
// If we have old metadata this isn't a new connection
isNewConnection = false;
}
// Set the initial connection time
newMetadata.Initial = DateTime.UtcNow;
// Set the keep alive time
newMetadata.UpdateKeepAlive(_configurationManager.KeepAlive);
return isNewConnection;
}
示例2: AddConnection
/// <summary>
/// Adds a new connection to the list of tracked connections.
/// </summary>
/// <param name="connection">The connection to be added.</param>
public bool AddConnection(ITrackingConnection connection)
{
var newMetadata = new ConnectionMetadata(connection);
ConnectionMetadata oldMetadata = null;
bool isNewConnection = true;
_connections.AddOrUpdate(connection.ConnectionId, newMetadata, (key, old) =>
{
oldMetadata = old;
return newMetadata;
});
if (oldMetadata != null)
{
Trace.TraceInformation("Connection exists. Closing previous connection. Old=({0}, {1}) New=({2})", oldMetadata.Connection.IsAlive, oldMetadata.Connection.Url, connection.Url);
// Kick out the older connection. This should only happen when
// a previous connection attempt fails on the client side (e.g. transport fallback).
oldMetadata.Connection.End();
// If we have old metadata this isn't a new connection
isNewConnection = false;
}
else
{
Trace.TraceInformation("Connection is New=({0}).", connection.Url);
}
lock (_counterLock)
{
_counters.ConnectionsCurrent.RawValue = _connections.Count;
}
// Set the initial connection time
newMetadata.Initial = DateTime.UtcNow;
// Set the keep alive time
newMetadata.UpdateKeepAlive(_configurationManager.KeepAlive);
return isNewConnection;
}
示例3: CheckTimeoutAndKeepAlive
private void CheckTimeoutAndKeepAlive(ConnectionMetadata metadata)
{
if (RaiseTimeout(metadata))
{
// If we're past the expiration time then just timeout the connection
metadata.Connection.Timeout();
RemoveConnection(metadata.Connection);
}
else
{
// The connection is still alive so we need to keep it alive with a server side "ping".
// This is for scenarios where networing hardware (proxies, loadbalancers) get in the way
// of us handling timeout's or disconnects gracefully
if (RaiseKeepAlive(metadata))
{
metadata.Connection.KeepAlive().Catch();
metadata.UpdateKeepAlive(_configurationManager.KeepAlive);
}
MarkConnection(metadata.Connection);
}
}
示例4: CheckTimeoutAndKeepAlive
private void CheckTimeoutAndKeepAlive(ConnectionMetadata metadata)
{
if (RaiseTimeout(metadata))
{
RemoveConnection(metadata.Connection);
// If we're past the expiration time then just timeout the connection
metadata.Connection.Timeout();
// End the connection
metadata.Connection.End();
}
else
{
// The connection is still alive so we need to keep it alive with a server side "ping".
// This is for scenarios where networking hardware (proxies, loadbalancers) get in the way
// of us handling timeout's or disconnects gracefully
if (RaiseKeepAlive(metadata))
{
Trace.TraceInformation("KeepAlive(" + metadata.Connection.ConnectionId + ")");
// If the keep alive send fails then kill the connection
metadata.Connection.KeepAlive()
.Catch(ex =>
{
Trace.TraceInformation("Failed to send keep alive: " + ex.GetBaseException());
RemoveConnection(metadata.Connection);
metadata.Connection.End();
});
metadata.UpdateKeepAlive(_configurationManager.KeepAlive);
}
MarkConnection(metadata.Connection);
}
}
示例5: AddConnection
/// <summary>
/// Adds a new connection to the list of tracked connections.
/// </summary>
/// <param name="connection">The connection to be added.</param>
public bool AddConnection(ITrackingConnection connection)
{
_trace.Source.TraceInformation("TransportHeartBeat: Adding connection {0}", connection.ConnectionId);
var newMetadata = new ConnectionMetadata(connection);
ConnectionMetadata oldMetadata = null;
bool isNewConnection = true;
_connections.AddOrUpdate(connection.ConnectionId, newMetadata, (key, old) =>
{
oldMetadata = old;
return newMetadata;
});
if (oldMetadata != null)
{
_trace.Source.TraceInformation("TransportHeartBeat: Connection {0} already exists and alive={1}. Closing previous connection id.", oldMetadata.Connection.ConnectionId, oldMetadata.Connection.IsAlive);
// Kick out the older connection. This should only happen when
// a previous connection attempt fails on the client side (e.g. transport fallback).
oldMetadata.Connection.End();
// If we have old metadata this isn't a new connection
isNewConnection = false;
}
else
{
_trace.Source.TraceInformation("TransportHeartBeat: Connection {0} is new.", connection.ConnectionId);
}
// Set the initial connection time
newMetadata.Initial = DateTime.UtcNow;
// Set the keep alive time
newMetadata.UpdateKeepAlive(_configurationManager.KeepAlive);
return isNewConnection;
}