本文整理汇总了C#中ClusterDescription类的典型用法代码示例。如果您正苦于以下问题:C# ClusterDescription类的具体用法?C# ClusterDescription怎么用?C# ClusterDescription使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ClusterDescription类属于命名空间,在下文中一共展示了ClusterDescription类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ClusterSelectedServerEvent
/// <summary>
/// Initializes a new instance of the <see cref="ClusterSelectedServerEvent" /> struct.
/// </summary>
/// <param name="clusterDescription">The cluster description.</param>
/// <param name="serverSelector">The server selector.</param>
/// <param name="selectedServer">The selected server.</param>
/// <param name="duration">The duration of time it took to select the server.</param>
public ClusterSelectedServerEvent(ClusterDescription clusterDescription, IServerSelector serverSelector, ServerDescription selectedServer, TimeSpan duration)
{
_clusterDescription = clusterDescription;
_serverSelector = serverSelector;
_selectedServer = selectedServer;
_duration = duration;
}
示例2: SelectServers
// methods
/// <inheritdoc/>
public IEnumerable<ServerDescription> SelectServers(ClusterDescription cluster, IEnumerable<Servers.ServerDescription> servers)
{
return servers.Where(x =>
x.Type == ServerType.ReplicaSetPrimary ||
x.Type == ServerType.ShardRouter ||
x.Type == ServerType.Standalone);
}
示例3: SelectServers
// methods
/// <inheritdoc/>
public IEnumerable<ServerDescription> SelectServers(ClusterDescription cluster, IEnumerable<ServerDescription> servers)
{
if (_maxStaleness.HasValue)
{
if (cluster.Servers.Any(s => s.Type != ServerType.Unknown && !Feature.MaxStaleness.IsSupported(s.Version)))
{
throw new NotSupportedException("All servers must be version 3.4 or newer to use max staleness.");
}
}
if (cluster.ConnectionMode == ClusterConnectionMode.Direct)
{
return servers;
}
switch (cluster.Type)
{
case ClusterType.ReplicaSet: return SelectForReplicaSet(cluster, servers);
case ClusterType.Sharded: return SelectForShardedCluster(servers);
case ClusterType.Standalone: return SelectForStandaloneCluster(servers);
case ClusterType.Unknown: return __noServers;
default:
var message = string.Format("ReadPreferenceServerSelector is not implemented for cluster of type: {0}.", cluster.Type);
throw new NotImplementedException(message);
}
}
示例4: ClusterSelectingServerFailedEvent
/// <summary>
/// Initializes a new instance of the <see cref="ClusterSelectingServerFailedEvent" /> struct.
/// </summary>
/// <param name="clusterDescription">The cluster description.</param>
/// <param name="serverSelector">The server selector.</param>
/// <param name="exception">The exception.</param>
/// <param name="operationId">The operation identifier.</param>
public ClusterSelectingServerFailedEvent(ClusterDescription clusterDescription, IServerSelector serverSelector, Exception exception, long? operationId)
{
_clusterDescription = clusterDescription;
_serverSelector = serverSelector;
_exception = exception;
_operationId = operationId;
}
示例5: SelectServers
// methods
public IEnumerable<ServerDescription> SelectServers(ClusterDescription cluster, IEnumerable<ServerDescription> servers)
{
var selectedServers = servers;
foreach (var selector in _selectors)
{
selectedServers = selector.SelectServers(cluster, selectedServers);
}
return selectedServers;
}
示例6: TestFixtureSetup
public void TestFixtureSetup()
{
var clusterId = new ClusterId(1);
var clusterType = ClusterType.Standalone;
var endPoint = new DnsEndPoint("localhost", 27017);
var serverId = new ServerId(clusterId, endPoint);
var server = new ServerDescription(serverId, endPoint);
var servers = new[] { server };
_clusterDescription = new ClusterDescription(clusterId, clusterType, servers);
}
示例7: Cluster
// constructors
protected Cluster(ClusterSettings settings, IClusterableServerFactory serverFactory, IClusterListener listener)
{
_settings = Ensure.IsNotNull(settings, "settings");
_serverFactory = Ensure.IsNotNull(serverFactory, "serverFactory");
_listener = listener;
_state = new InterlockedInt32(State.Initial);
_clusterId = new ClusterId();
_description = ClusterDescription.CreateInitial(_clusterId, _settings.ConnectionMode.ToClusterType());
_descriptionChangedTaskCompletionSource = new TaskCompletionSource<bool>();
}
示例8: Constructor_should_initialize_instance
public void Constructor_should_initialize_instance()
{
var subject = new ClusterDescription(
__clusterId,
ClusterType.ReplicaSet,
new[] { __serverDescription1, __serverDescription2 });
subject.ClusterId.Should().Be(__clusterId);
subject.Servers.Should().ContainInOrder(new[] { __serverDescription1, __serverDescription2 });
subject.State.Should().Be(ClusterState.Disconnected);
subject.Type.Should().Be(ClusterType.ReplicaSet);
}
示例9: MongoIncompatibleDriverExceptionTests
public MongoIncompatibleDriverExceptionTests()
{
var clusterId = new ClusterId(1);
var connectionMode = ClusterConnectionMode.Standalone;
var clusterType = ClusterType.Standalone;
var endPoint = new DnsEndPoint("localhost", 27017);
var serverId = new ServerId(clusterId, endPoint);
var server = new ServerDescription(serverId, endPoint);
var servers = new[] { server };
_clusterDescription = new ClusterDescription(clusterId, connectionMode, clusterType, servers);
}
示例10: Setup
public void Setup()
{
var clusterId = new ClusterId();
_primary = ServerDescriptionHelper.Connected(clusterId, new DnsEndPoint("localhost", 27017), ServerType.ReplicaSetPrimary, new TagSet(new [] { new Tag("a", "1") }));
_secondary1 = ServerDescriptionHelper.Connected(clusterId, new DnsEndPoint("localhost", 27018), ServerType.ReplicaSetSecondary, new TagSet(new [] { new Tag("a", "1") }));
_secondary2 = ServerDescriptionHelper.Connected(clusterId, new DnsEndPoint("localhost", 27019), ServerType.ReplicaSetSecondary, new TagSet(new[] { new Tag("a", "2") }));
_description = new ClusterDescription(
clusterId,
ClusterType.ReplicaSet,
new[] { _primary, _secondary1, _secondary2 });
}
示例11: SelectServers
// methods
public IEnumerable<ServerDescription> SelectServers(ClusterDescription cluster, IEnumerable<ServerDescription> servers)
{
var list = servers.ToList();
switch (list.Count)
{
case 0:
case 1:
return list;
default:
var index = ThreadStaticRandom.Next(list.Count);
return new[] { list[index] };
}
}
示例12: Setup
public void Setup()
{
var clusterId = new ClusterId();
_description = new ClusterDescription(
clusterId,
ClusterType.Unknown,
new[]
{
ServerDescriptionHelper.Connected(clusterId, new DnsEndPoint("localhost", 27017), averageRoundTripTime: TimeSpan.FromMilliseconds(10)),
ServerDescriptionHelper.Connected(clusterId, new DnsEndPoint("localhost", 27018), averageRoundTripTime: TimeSpan.FromMilliseconds(30)),
ServerDescriptionHelper.Connected(clusterId, new DnsEndPoint("localhost", 27019), averageRoundTripTime: TimeSpan.FromMilliseconds(20))
});
}
示例13: Setup
public void Setup()
{
var clusterId = new ClusterId();
_description = new ClusterDescription(
clusterId,
ClusterType.Unknown,
new[]
{
ServerDescriptionHelper.Connected(clusterId, new DnsEndPoint("localhost", 27017)),
ServerDescriptionHelper.Connected(clusterId, new DnsEndPoint("localhost", 27018)),
ServerDescriptionHelper.Connected(clusterId, new DnsEndPoint("localhost", 27019)),
});
}
示例14: SelectServers
// methods
/// <inheritdoc/>
public IEnumerable<ServerDescription> SelectServers(ClusterDescription cluster, IEnumerable<ServerDescription> servers)
{
switch (cluster.Type)
{
case ClusterType.ReplicaSet: return SelectForReplicaSet(servers);
case ClusterType.Sharded: return SelectForShardedCluster(servers);
case ClusterType.Standalone: return SelectForStandaloneCluster(servers);
case ClusterType.Unknown: return __noServers;
default:
var message = string.Format("ReadPreferenceServerSelector is not implemented for cluster of type: {0}.", cluster.Type);
throw new NotImplementedException(message);
}
}
示例15: LatencyLimitingServerSelectorTests
public LatencyLimitingServerSelectorTests()
{
var clusterId = new ClusterId();
_description = new ClusterDescription(
clusterId,
ClusterConnectionMode.Automatic,
ClusterType.Unknown,
new[]
{
ServerDescriptionHelper.Connected(clusterId, new DnsEndPoint("localhost", 27017), averageRoundTripTime: TimeSpan.FromMilliseconds(10)),
ServerDescriptionHelper.Connected(clusterId, new DnsEndPoint("localhost", 27018), averageRoundTripTime: TimeSpan.FromMilliseconds(30)),
ServerDescriptionHelper.Connected(clusterId, new DnsEndPoint("localhost", 27019), averageRoundTripTime: TimeSpan.FromMilliseconds(20))
});
}