using LJLib.Client; using LJLib.Net.SPI.Client; using LJProxy.Settings; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Options; using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; namespace LJProxy.Controllers { [Route("api/[controller]")] [ApiController] public class L1SvrController : Controller { private static object _syncRoot = new object(); public static AppSettings _appSettingModel; public L1SvrController(IOptions appSettingModel) { if (_appSettingModel == null) { _appSettingModel = appSettingModel.Value; } } private static ILJClient _PROPool { get; set; } private static ILJClient PROPool { get { if (_PROPool == null) { lock (_syncRoot) { var url = _appSettingModel.L1SvrPROUrl; var urlArr = url.Split(':'); var ip = urlArr[0]; var port = urlArr[1]; var creator = new DirectP1ClientCreator(ip, Convert.ToInt32(port)); _PROPool = new LJClientPool(creator, 1000); } } return _PROPool; } } private static ILJClient _CRPPool { get; set; } private static ILJClient CRPPool { get { if (_CRPPool == null) { lock (_syncRoot) { var url = _appSettingModel.L1SvrCRPUrl; var urlArr = url.Split(':'); var ip = urlArr[0]; var port = urlArr[1]; var creator = new DirectP1ClientCreator(ip, Convert.ToInt32(port)); _CRPPool = new LJClientPool(creator, 20); } } return _CRPPool; } } [Route("PRO/{apiName}")] [HttpPost] public string PRO(string apiName, [FromBody] object requestBody) { var rslt = PROPool.DoExcute(apiName, requestBody.ToString()); return rslt; } [Route("CRP/{apiName}")] [HttpPost] public string CRP(string apiName,[FromBody] object requestBody) { var rslt = CRPPool.DoExcute(apiName, requestBody.ToString()); return rslt; } } }