Exemplo n.º 1
0
        /// <summary>
        ///     Dynamically adds a node to the cluster asynchronously.
        /// </summary>
        /// <param name="nodeOptions">the node connection options</param>
        /// <returns>
        ///     a task that represents the asynchronous operation
        ///     <para>the cluster node info created for the node</para>
        /// </returns>
        public async Task <LavalinkClusterNode> AddNodeAsync(LavalinkNodeOptions nodeOptions)
        {
            var node = CreateNode(nodeOptions);

            // initialize node
            await node.InitializeAsync();

            // add node info to nodes (so make it available for load balancing)
            lock (_nodesLock)
            {
                _nodes.Add(node);
            }

            return(node);
        }
Exemplo n.º 2
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="LavalinkNode"/> class.
        /// </summary>
        /// <param name="cluster">the cluster</param>
        /// <param name="options">the node options for connecting</param>
        /// <param name="client">the discord client</param>
        /// <param name="logger">the logger</param>
        /// <param name="cache">an optional cache that caches track requests</param>
        /// <param name="id">the node number</param>
        /// <exception cref="ArgumentNullException">
        ///     thrown if the specified <paramref name="cluster"/> is <see langword="null"/>.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        ///     thrown if the specified <paramref name="options"/> parameter is <see langword="null"/>.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        ///     thrown if the specified <paramref name="client"/> is <see langword="null"/>.
        /// </exception>
        public LavalinkClusterNode(LavalinkCluster cluster, LavalinkNodeOptions options, IDiscordClientWrapper client,
                                   ILogger logger, ILavalinkCache cache, int id)
            : base(options, client, logger, cache)
        {
            if (options is null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            if (client is null)
            {
                throw new ArgumentNullException(nameof(client));
            }

            Cluster    = cluster ?? throw new ArgumentNullException(nameof(cluster));
            Identifier = "Cluster Node-" + id;
            LastUsage  = DateTimeOffset.MinValue;
        }
        /// <summary>
        ///     Initializes a new instance of the <see cref="LavalinkNode"/> class.
        /// </summary>
        /// <param name="cluster">the cluster</param>
        /// <param name="options">the node options for connecting</param>
        /// <param name="client">the discord client</param>
        /// <param name="logger">the logger</param>
        /// <param name="cache">an optional cache that caches track requests</param>
        /// <param name="id">the node number</param>
        /// <exception cref="ArgumentNullException">
        ///     thrown if the specified <paramref name="cluster"/> is <see langword="null"/>.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        ///     thrown if the specified <paramref name="options"/> parameter is <see langword="null"/>.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        ///     thrown if the specified <paramref name="client"/> is <see langword="null"/>.
        /// </exception>
        public LavalinkClusterNode(
            LavalinkCluster cluster, LavalinkNodeOptions options, IDiscordClientWrapper client,
            int id, ILogger?logger = null, ILavalinkCache?cache = null)
            : base(options, client, logger, cache)
        {
            if (options is null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            if (client is null)
            {
                throw new ArgumentNullException(nameof(client));
            }

            if (Label is null)
            {
                Label = "Cluster Node-" + id;
            }

            Id        = id;
            Cluster   = cluster ?? throw new ArgumentNullException(nameof(cluster));
            LastUsage = DateTimeOffset.MinValue;
        }
Exemplo n.º 4
0
 /// <summary>
 ///     Creates a new lavalink cluster node.
 /// </summary>
 /// <param name="nodeOptions">the node options</param>
 /// <returns>the created node</returns>
 private LavalinkClusterNode CreateNode(LavalinkNodeOptions nodeOptions)
 => new LavalinkClusterNode(this, nodeOptions, _client, _logger, _cache, _nodeId++);