/// <summary> /// do create connections /// </summary> /// <param name="url"> target url </param> /// <param name="pool"> connection pool </param> /// <param name="taskName"> task name </param> /// <param name="syncCreateNumWhenNotWarmup"> you can specify this param to ensure at least desired number of connections available in sync way </param> /// <exception cref="RemotingException"> </exception> private void doCreate(Url url, ConnectionPool pool, string taskName, int syncCreateNumWhenNotWarmup) { //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final int actualNum = pool.size(); int actualNum = pool.size(); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final int expectNum = url.getConnNum(); int expectNum = url.ConnNum; if (actualNum >= expectNum) { return; } if (logger.IsEnabled(LogLevel.Debug)) { logger.LogDebug("actual num {}, expect num {}, task name {}", actualNum, expectNum, taskName); } if (url.ConnWarmup) { for (int i = actualNum; i < expectNum; ++i) { Connection connection = create(url); pool.add(connection); } } else { if (syncCreateNumWhenNotWarmup < 0 || syncCreateNumWhenNotWarmup > url.ConnNum) { throw new ArgumentException("sync create number when not warmup should be [0," + url.ConnNum + "]"); } // create connection in sync way if (syncCreateNumWhenNotWarmup > 0) { for (int i = 0; i < syncCreateNumWhenNotWarmup; ++i) { Connection connection = create(url); pool.add(connection); } if (syncCreateNumWhenNotWarmup >= url.ConnNum) { return; } } pool.markAsyncCreationStart(); // mark the start of async try { asyncCreateConnectionExecutor.execute(new TempRunnable(this, pool, url, taskName)); } catch (RejectedExecutionException) { pool.markAsyncCreationDone(); // mark the end of async when reject throw; } } // end of NOT warm up }
public void run() { try { for (int i = connectionPool.size(); i < url.ConnNum; ++i) { Connection conn = null; try { conn = defaultConnectionManager.create(url); } catch (RemotingException e) { logger.LogError("Exception occurred in async create connection thread for {}, taskName {}", url.UniqueKey, taskName, e); } connectionPool.add(conn); } } finally { connectionPool.markAsyncCreationDone(); // mark the end of async } }