Esempio n. 1
0
        public void UnregisterPlugin(string plugin_name)
        {
            try
            {
                CommonPair <IPlugin, List <Constants.TK_CommandType> > cmds = null;
                lock (m_Plugins)
                {
                    if (!m_Plugins.ContainsKey(plugin_name))
                    {
                        return;
                    }

                    cmds = m_Plugins[plugin_name];
                    m_Plugins.Remove(plugin_name);

                    try
                    {
                        cmds.First.Kill();
                    }
                    catch { }
                }

                foreach (Constants.TK_CommandType cmd in cmds.Second)
                {
                    CommandProcessor.instance().unregisterReportHandler(cmd, this);
                }

                Logger.Instance().SendLog("已卸载: " + plugin_name);
            }
            catch (Exception ex)
            {
                Logger.Instance().SendLog(ex.ToString());
            }
        }
Esempio n. 2
0
        public int FilterResponse(List <ICommunicationMessage> income_msgs)
        {
            List <ICommunicationMessage> not_filtered = new List <ICommunicationMessage>();

            foreach (ICommunicationMessage message in income_msgs)
            {
                if (message.TK_CommandType != Constants.TK_CommandType.RESPONSE ||
                    !message.Contains(Constants.MSG_PARANAME_RESPONSE_TO) ||
                    !message.Contains("ClientID"))
                {
                    not_filtered.Add(message);
                    continue;
                }

                long clientid = Convert.ToInt64(message.GetValue("ClientID").ToString());
                lock (m_ClientCommunicators)
                {
                    if (!m_ClientCommunicators.ContainsKey(clientid))
                    {
                        not_filtered.Add(message);
                        continue; // 非来自自身管理的client的响应包, 不处理
                    }
                }

                long id = 0;
                try
                {
                    id = Convert.ToInt64(message.GetValue(Constants.MSG_PARANAME_RESPONSE_TO).ToString());

                    lock (m_MessagesWaitForResponse)
                    {
                        if (m_MessagesWaitForResponse.ContainsKey(id))
                        {
                            // 是自身正在等待的响应包
                            CommonPair <ICommunicationMessage, ManualResetEvent> de = m_MessagesWaitForResponse[id];
                            ManualResetEvent mutex = de.Second;

                            de.First = message.clone(); // 复制信息
                            mutex.Set();
                        }
                        else
                        {
                            not_filtered.Add(message);
                        }
                    }
                }
                catch
                {
                    SendLog("报文缺少RESPONSE_TO关键字");
                    not_filtered.Add(message);
                }
            }

            int filtered_count = income_msgs.Count - not_filtered.Count;

            income_msgs.Clear();
            income_msgs.AddRange(not_filtered);
            return(filtered_count);
        }
Esempio n. 3
0
        public bool Close()
        {
            lock (this)
            {
                if (Interlocked.Exchange(ref m_Run, 0) == 0)
                {
                    return(true);
                }

                //m_Listener.Shutdown(SocketShutdown.Both);
                m_Listener.Close();

                m_AccepterStopEvent.WaitOne();

                this.m_TimerKeepAlive.Stop();

                // 取消所有响应包的等待
                lock (this.m_MessagesWaitForResponse)
                {
                    foreach (KeyValuePair <long, CommonPair <ICommunicationMessage, ManualResetEvent> > de in this.m_MessagesWaitForResponse)
                    {
                        CommonPair <ICommunicationMessage, ManualResetEvent> elem = de.Value;
                        ManualResetEvent mutex = elem.Second;
                        mutex.Set();
                    }

                    m_MessagesWaitForResponse.Clear();
                }

                m_KeepAliveClearEvent.WaitOne();

                m_TimerCheckBroken.Stop();
                m_CheckBrokenClearEvent.WaitOne();



                lock (m_ClientCommunicators)
                {
                    foreach (Communicator comm in m_ClientCommunicators.Values)
                    {
                        comm.endWork();
                    }

                    m_ClientCommunicators.Clear();
                }

                lock (m_ClientActiveCounter)
                    m_ClientActiveCounter.Clear();

                foreach (KeyValuePair <Constants.TK_CommandType, byte> pair in m_AcceptedMsgs)
                {
                    CommandProcessor.instance().unregisterReportHandler(pair.Key, this);
                }

                //CommandProcessor.instance().unregisterReportHandler(Constants.TK_CommandType.RESPONSE, this);
            }

            return(true);
        }
Esempio n. 4
0
        public bool Close()
        {
            lock (this)
            {
                try
                {
                    if (Interlocked.Exchange(ref m_Started, 0) == 0)
                    {
                        return(true);
                    }

                    this.m_TimerKeepAlive.Stop();

                    // 取消所有响应包的等待
                    lock (this.m_MessagesWaitForResponse)
                    {
                        foreach (KeyValuePair <long, CommonPair <ICommunicationMessage, ManualResetEvent> > de in this.m_MessagesWaitForResponse)
                        {
                            CommonPair <ICommunicationMessage, ManualResetEvent> elem = de.Value;
                            ManualResetEvent mutex = elem.Second;
                            mutex.Set();
                        }

                        m_MessagesWaitForResponse.Clear();
                    }

                    m_KeepAliveClearEvent.WaitOne();

                    if (m_Comm != null)
                    {
                        m_Comm.endWork();
                        m_Comm.onLog -= new LogHandler(m_Comm_onLog);
                        m_Comm.onConnectionBroken -= new ConnectionBrokenHandler(m_Comm_onConnectionBroken);
                        m_Comm = null;
                    }

                    this.disconnectServer();

                    //CommandProcessor.instance().unregisterReportHandler(Constants.TK_CommandType.RESPONSE, this);
                    SendLog("通讯管理器已经停止.");
                }
                catch (Exception ex)
                {
                    SendLog("通讯管理器关闭与应用服务器的连接时发生异常:\n" + ex.ToString());
                }
            }

            return(true);
        }