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 || serverCount == 1) { connection = server.OpenConnection(); } _roundRobinIdx = id; if (connection != null) { break; } } } Trace.TraceInformation("open any server {0}", connection); return(connection); }
public HmuxConnection OpenSessionServer(String sessionId) { if (sessionId == null || sessionId.Length < 1) { return(null); } char c = sessionId[0]; int i = c - 'a'; if (i < 0 || i >= _servers.Length) { return(null); } Server server = _servers[i]; HmuxConnection connection = null; connection = server.OpenConnection(); Trace.TraceInformation("open session server {0}->{1}", sessionId, connection); return(connection); }
public HmuxConnection OpenSessionServer(String sessionId) { char c = sessionId[0]; Server server = _servers[(c - 'a')]; HmuxConnection connection = null; connection = server.OpenConnection(); return(connection); }