提交 745bd500 编写于 作者: 丁劲犇's avatar 丁劲犇 😸

PREPARE TO JOIN

上级 3a8660d0
#include "zp_clusterterm.h" #include "zp_clusterterm.h"
namespace ZP_Cluster{ namespace ZP_Cluster{
zp_ClusterTerm::zp_ClusterTerm(const QString & name,int nTransThreads ,int nWorkingThreads,QObject *parent ) : zp_ClusterTerm::zp_ClusterTerm(const QString & name,QObject *parent ) :
QObject(parent) QObject(parent)
,m_strTermName(name) ,m_strTermName(name)
{ {
m_pClusterEng = new ZPTaskEngine::zp_pipeline(this); m_pClusterEng = new ZPTaskEngine::zp_pipeline(this);
m_pClusterEng->addThreads(nWorkingThreads); m_pClusterNet = new ZPNetwork::zp_net_ThreadPool(8192,this);
m_pClusterNet = new ZPNetwork::zp_net_ThreadPool(8192,this);
m_pClusterNet->AddClientTransThreads(nTransThreads);
} }
void zp_ClusterTerm::StartListen(const QHostAddress &addr, int nPort) void zp_ClusterTerm::StartListen(const QHostAddress &addr, int nPort)
{ {
m_pClusterNet->AddListeningAddress(m_strTermName,addr,nPort,false); m_pClusterNet->AddListeningAddress(m_strTermName,addr,nPort,false);
} }
bool zp_ClusterTerm::JoinCluster(const QHostAddress &addr, int nPort) bool zp_ClusterTerm::JoinCluster(const QHostAddress &addr, int nPort)
{ {
return m_pClusterNet->connectTo(addr,nPort); return m_pClusterNet->connectTo(addr,nPort);
} }
bool zp_ClusterTerm::canExit() bool zp_ClusterTerm::canExit()
{ {
return m_pClusterEng->canClose() && m_pClusterNet->CanExit(); return m_pClusterEng->canClose() && m_pClusterNet->CanExit();
} }
} }
...@@ -8,31 +8,31 @@ ...@@ -8,31 +8,31 @@
#include "../pipeline/zp_pltaskbase.h" #include "../pipeline/zp_pltaskbase.h"
namespace ZP_Cluster{ namespace ZP_Cluster{
//!this class enable server processes can //!this class enable server processes can
//! communicate with each other. //! communicate with each other.
class zp_ClusterTerm : public QObject class zp_ClusterTerm : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit zp_ClusterTerm(const QString & name,int nTransThreads = 4,int nWorkingThreads = 4,QObject *parent = 0); explicit zp_ClusterTerm(const QString & name,QObject *parent = 0);
//cluster status //cluster status
ZPNetwork::zp_net_ThreadPool * netEng() {return m_pClusterNet;} ZPNetwork::zp_net_ThreadPool * netEng() {return m_pClusterNet;}
ZPTaskEngine::zp_pipeline * taskEng() {return m_pClusterEng;} ZPTaskEngine::zp_pipeline * taskEng() {return m_pClusterEng;}
bool canExit(); bool canExit();
protected: protected:
QString m_strTermName;//the Terminal's name QString m_strTermName;//the Terminal's name
ZPNetwork::zp_net_ThreadPool * m_pClusterNet; ZPNetwork::zp_net_ThreadPool * m_pClusterNet;
ZPTaskEngine::zp_pipeline * m_pClusterEng; ZPTaskEngine::zp_pipeline * m_pClusterEng;
signals: signals:
public slots: public slots:
//!Start listen, this term can be connected by newly joined terms in future. //!Start listen, this term can be connected by newly joined terms in future.
void StartListen(const QHostAddress &addr, int nPort); void StartListen(const QHostAddress &addr, int nPort);
//!Join cluster, using existing term (addr:nPort) //!Join cluster, using existing term (addr:nPort)
//!as soon as connection established, more existing terms will be sent to this term, //!as soon as connection established, more existing terms will be sent to this term,
//!an p2p connection will start //!an p2p connection will start
bool JoinCluster(const QHostAddress &addr, int nPort); bool JoinCluster(const QHostAddress &addr, int nPort);
}; };
} }
#endif // ZP_CLUSTERTERM_H #endif // ZP_CLUSTERTERM_H
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册