void Init(string _registryRedisAddr, ESBOptions options) { lastESBServerActiveTime = DateTime.Now; isReady = false; guid = genGuid(); log.InfoFormat("new ESBClient {0}", guid); registryRedisAddr = _registryRedisAddr; redis = new RedisClient(registryRedisAddr, options.redisPort); responses = new ConcurrentDictionary<string, ResponseStruct>(); InvokeCallBag = new List<BlockingCollection<Message>>(); localMethods = new Dictionary<string, LocalInvokeMethod>(); subscribeCallbacks = new Dictionary<string, Dictionary<string, SubscribeCallback>>(); channels = new List<string>(); publisherPort = options.publisherPort; publisher = new Publisher(GetFQDN(), publisherPort); isWork = true; maxInactiveTimeInMsBeforeReconnect = options.maxInactiveTimeInMsBeforeReconnect; while (isConnecting || !Connect()) { Thread.Sleep(250); } log.InfoFormat("Connected with Publisher Port : {0}", publisherPort); (new Thread(new ThreadStart(MainLoop))).Start(); var cpus = Environment.ProcessorCount; var workers = cpus*Paragonex.Common.Helpers.Configuration.GetAppConfigValue<int>("WorkersCoresMultiplier", 1); log.InfoFormat("Machine have {0} cores, using {1} workers", cpus, workers); workerList = new List<Thread>(); for (var i = 0; i < workers; i++) { InvokeCallBag.Add(new BlockingCollection<Message>()); var t = new Thread(new ParameterizedThreadStart(InvokeCallWorker)); workerList.Add(t); t.Start(i); } Ping(); }
public void Dispose() { isDisposing = true; log.InfoFormat("ESBClient {0} dispose", guid); isWork = false; foreach (var w in workerList) { w.Abort(); } publisher.Dispose(); publisher = null; subscriber.Dispose(); subscriber = null; redis.Dispose(); redis = null; isDisposing = false; }