Esempio n. 1
0
        /// <summary>
        ///  Add name and methods to internal lists
        /// </summary>
        /// <param name="rpcModule">RpcModule instance</param>
        public bool Register(RpcModule rpcModule)
        {
            if (mAvailableModules.TryAdd(rpcModule.Name, rpcModule))
            {
                foreach (var method in rpcModule.Methods)
                {
                    mAvailableMethods.TryAdd(method, rpcModule);
                }
                return(true);
            }

            return(false);
        }
Esempio n. 2
0
        /// <summary>
        /// We wait new connection from modules in this thread
        /// </summary>
        private void ModuleThread()
        {
            mModuleListener.Start();

            while (true)
            {
                try
                {
                    var client = mModuleListener.AcceptTcpClient();

                    var module = new RpcModule {
                        InvokeGuardtime = new TimeSpan(0, 0, 5)
                    };                                                                      // 5 seconds is default
                    module.Handler(client);

                    // yes, it's correct rpcModule connection
                    if (module.IsActive)
                    {
                        // add rpcModule and methods to list
                        if (mRpcModuleList.Register(module))
                        {
                            if (mLogger != null)
                            {
                                mLogger.Debug("RpcModule(" + module.Name + ") succefully added");
                            }

                            // debug
                            if (mLogger != null)
                            {
                                if (mLogger.IsDebugEnabled)
                                {
                                    mRpcModuleList.PrintRemoteMethods();
                                }
                            }
                        }
                        else
                        {
                            if (mLogger != null)
                            {
                                mLogger.Debug("RpcModule(" + module.Name + ") cann't added");
                            }

                            module.Dispose();
                        }
                    }

                    Thread.Sleep(200);
                }
                catch (ThreadAbortException)
                {
                    mModuleListener.Stop();

                    throw;
                }
                catch (Exception ex)
                {
                    if (!(ex is SocketException || ex is IOException || ex is InvalidOperationException))
                    {
                        if (mLogger != null)
                        {
                            mLogger.Warn("Unexpected exception " + ex.GetType() + " at ModuleThread " + ex.Message);
                        }
                    }
                }
            }
        }