Beispiel #1
0
 /// <summary>
 /// remove task and remove all connections
 /// </summary>
 /// <param name="poolKey"> target pool key </param>
 protected internal virtual void removeTask(string poolKey)
 {
     connTasks.TryRemove(poolKey, out var task);
     if (null != task)
     {
         ConnectionPool pool = (ConnectionPool)FutureTaskUtil.getFutureTaskResult(task, logger);
         if (null != pool)
         {
             pool.removeAllAndTryClose();
         }
     }
 }
        public virtual void monitor(ConcurrentDictionary <string, RunStateRecordedFutureTask> connPools)
        {
            try
            {
                if (connPools == null || connPools.Count == 0)
                {
                    return;
                }

                foreach (var entry in connPools)
                {
                    string         poolKey = entry.Key;
                    ConnectionPool pool    = (ConnectionPool)FutureTaskUtil.getFutureTaskResult(entry.Value, logger);

                    var serviceOnConnections  = new List <Connection>();
                    var serviceOffConnections = new List <Connection>();


                    foreach (var connection in pool.All)
                    {
                        if (isConnectionOn(connection))
                        {
                            serviceOnConnections.Add(connection);
                        }
                        else
                        {
                            serviceOffConnections.Add(connection);
                        }
                    }

                    if (serviceOnConnections.Count > connectionThreshold)
                    {
                        Connection freshSelectConnect = (Connection)serviceOnConnections[random.nextInt(serviceOnConnections.Count)];
                        freshSelectConnect.setAttribute(Configs.CONN_SERVICE_STATUS, Configs.CONN_SERVICE_STATUS_OFF);
                        serviceOffConnections.Add(freshSelectConnect);
                    }
                    else
                    {
                        if (logger.IsEnabled(LogLevel.Information))
                        {
                            logger.LogInformation("serviceOnConnections({}) size[{}], CONNECTION_THRESHOLD[{}].", poolKey, serviceOnConnections.Count, connectionThreshold);
                        }
                    }

                    foreach (var offConn in serviceOffConnections)
                    {
                        if (offConn.InvokeFutureMapFinish)
                        {
                            if (offConn.Fine)
                            {
                                offConn.close();
                            }
                        }
                        else
                        {
                            if (logger.IsEnabled(LogLevel.Information))
                            {
                                logger.LogInformation("Address={} won't close at this schedule turn", offConn.Channel.RemoteAddress.ToString());
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                logger.LogError("ScheduledDisconnectStrategy monitor error", e);
            }
        }
Beispiel #3
0
 /// <summary>
 /// get connection pool from future task
 /// </summary>
 /// <param name="task"> future task </param>
 /// <returns> connection pool </returns>
 private ConnectionPool getConnectionPool(RunStateRecordedFutureTask task)
 {
     return((ConnectionPool)FutureTaskUtil.getFutureTaskResult(task, logger));
 }