예제 #1
0
파일: LoadBalancer.cs 프로젝트: dlitz/resin
        //supports just one server for now
        public LoadBalancer(String servers,
            int loadBalanceConnectTimeout,
            int loadBalanceIdleTime,
            int loadBalanceRecoverTime,
            int loadBalanceSocketTimeout,
            int keepaliveTimeout,
            int socketTimeout,
            bool isDebug)
        {
            _log = Logger.GetLogger();

              _loadBalanceConnectTimeout = loadBalanceConnectTimeout;
              _loadBalanceIdleTime = loadBalanceIdleTime;
              _loadBalanceRecoverTime = loadBalanceRecoverTime;
              _loadBalanceSocketTimeout = loadBalanceSocketTimeout;
              _keepaliveTimeout = keepaliveTimeout;
              _socketTimeout = socketTimeout;
              _isDebug = isDebug;

              List<Server> pool = new List<Server>();
              String[] sruns = servers.Split(new char[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries);

              for (int i = 0; i < sruns.Length; i++) {
            String server = sruns[i];
            int portIdx = server.LastIndexOf(':');
            String host = server.Substring(0, portIdx);
            IPAddress address = GetIPsForHost(host);
            int port = int.Parse(server.Substring(portIdx + 1, server.Length - portIdx - 1));
            char c = (char)('a' + i);
            _log.Info("Adding Server '{0}:{1}:{2}'", c, host, port);

            Server srun = new Server(c, address, port, _loadBalanceConnectTimeout, _loadBalanceIdleTime, _loadBalanceRecoverTime, _socketTimeout);
            srun.SetDebug(_isDebug);
            pool.Add(srun);
              }

              _servers = pool.ToArray();

              _random = new Random();
        }
예제 #2
0
파일: LoadBalancer.cs 프로젝트: dlitz/resin
        public HmuxConnection OpenServer(String sessionId, Server xServer)
        {
            Trace.TraceInformation("{0}:{1}", _servers.Length, _servers[0]);

              HmuxConnection connection = null;
              if (sessionId != null)
            connection = OpenSessionServer(sessionId);

              if (connection == null)
            connection = OpenAnyServer(xServer);

              return connection;
        }
        public HmuxConnection(Socket socket, Server pool, char serverInternalId, String traceId)
        {
            _socket = socket;
              _stream = new BufferedStream(new NetworkStream(_socket, true));
              _pool = pool;
              _serverInternalId = serverInternalId;

              _traceId = traceId;
              _remoteEndPoint = socket.RemoteEndPoint.ToString();

              _log = Logger.GetLogger();
        }
예제 #4
0
파일: LoadBalancer.cs 프로젝트: dlitz/resin
        public HmuxConnection OpenAnyServer(Server xChannelFactory)
        {
            int serverCount = _servers.Length;

              Server server = null;
              HmuxConnection connection = null;

              int id = 0;

              lock (this) {
            _roundRobinIdx = _roundRobinIdx % serverCount;
            id = _roundRobinIdx;
            _roundRobinIdx++;
              }

              server = _servers[id];
              connection = server.OpenConnection();

              if (connection != null)
            return connection;

              lock (this) {
            _roundRobinIdx = _random.Next(serverCount);

            for (int i = 0; i < serverCount; i++) {
              id = (i + _roundRobinIdx) % serverCount;

              server = _servers[id];
              if (xChannelFactory != server)
            connection = server.OpenConnection();

              _roundRobinIdx = id;

              if (connection != null)
            break;
            }
              }

              return connection;
        }
예제 #5
0
        public HmuxConnection OpenServer(String sessionId, Server xServer)
        {
            HmuxConnection connection = null;

              if (sessionId != null && sessionId.Length > 1)
            connection = OpenSessionServer(sessionId);

              if (connection == null)
            connection = OpenAnyServer(xServer);

              return connection;
        }