ExtSender.cpp
上传用户:romrleung
上传日期:2022-05-23
资源大小:18897k
文件大小:4k
源码类别:

MySQL数据库

开发平台:

Visual C++

  1. /* Copyright (C) 2003 MySQL AB
  2.    This program is free software; you can redistribute it and/or modify
  3.    it under the terms of the GNU General Public License as published by
  4.    the Free Software Foundation; either version 2 of the License, or
  5.    (at your option) any later version.
  6.    This program is distributed in the hope that it will be useful,
  7.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  8.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  9.    GNU General Public License for more details.
  10.    You should have received a copy of the GNU General Public License
  11.    along with this program; if not, write to the Free Software
  12.    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
  13. #include "ExtSender.hpp"
  14. /*****************************************************************************
  15.  * Constructor / Destructor / Init / Get / Set
  16.  *****************************************************************************/
  17. /**
  18.  * @todo: signalErrorHandler is not finished. Just infrastructure. 
  19.  */
  20. ExtSender::ExtSender() {
  21.   m_tf = NULL;
  22.   m_nodeId = 0;
  23.   m_ownRef = 0;
  24. }
  25. ExtSender::~ExtSender() {
  26.   if (m_tf) delete m_tf;
  27. }
  28. void    
  29. ExtSender::setNodeId(Uint32 nodeId) 
  30. #if 0
  31.   ndbout_c("ExtSender: Set nodeid to %d", nodeId);
  32. #endif
  33.   m_nodeId = nodeId; 
  34. }
  35. Uint32 
  36. ExtSender::getOwnRef() const 
  37.   if(!m_ownRef) REPABORT("No m_ownRef set");
  38.   return m_ownRef; 
  39. }
  40. void 
  41. ExtSender::setOwnRef(Uint32 ref) 
  42.   // Can only be set once
  43.   if (m_ownRef != 0) REPABORT("Trying to change m_ownRef");
  44.   m_ownRef = ref; 
  45. }
  46. /*****************************************************************************
  47.  * Usage
  48.  *****************************************************************************/
  49. int
  50. ExtSender::sendSignal(class NdbApiSignal * s) {
  51. #if 0
  52.   ndbout_c("ExtSender: Sending signal %d to %d", 
  53.    s->readSignalNumber(), m_nodeId);
  54. #endif
  55.   if (m_tf == NULL || m_nodeId == 0 || s==0) abort();
  56.   m_tf->lock_mutex();
  57.   int retvalue = m_tf->sendSignal(s, m_nodeId);
  58.   if (retvalue) {
  59.     RLOG(("sendSignal returned %d for send to node %d", retvalue, m_nodeId));
  60.   }
  61. #if 0
  62.   ndbout_c("ExtSender: Sent signal to %d", m_nodeId);
  63. #endif
  64.   m_tf->unlock_mutex();
  65.   return retvalue;
  66. }
  67. int
  68. ExtSender::sendFragmentedSignal(NdbApiSignal * s, 
  69. LinearSectionPtr ptr[3],
  70. Uint32 sections) {
  71.   if (m_tf == NULL || m_nodeId == 0) abort();
  72.   m_tf->lock_mutex();
  73.   int retvalue = m_tf->sendFragmentedSignal(s, m_nodeId, ptr, sections);
  74.   if (retvalue) {
  75.     RLOG(("sendFragmentedSignal returned %d for send to node %d",
  76.   retvalue, m_nodeId));
  77.   }
  78.   m_tf->unlock_mutex();
  79.   return retvalue;
  80. }
  81. /**
  82.  * Check that TransporterFacade is connected to at least one DB node
  83.  */
  84. bool
  85. ExtSender::connected(Uint32 timeOutMillis){
  86. #if 0
  87.   ndbout_c("ExtSender: Waiting for remote component to be ready!");
  88. #endif
  89.   NDB_TICKS start = NdbTick_CurrentMillisecond();
  90.   NDB_TICKS now = start;
  91.   //  while(m_tf->theClusterMgr->getNoOfConnectedNodes() == 0 &&
  92.   while((m_tf->get_an_alive_node() == 0) &&
  93. (timeOutMillis == 0 || (now - start) < timeOutMillis)){
  94.     NdbSleep_MilliSleep(100);
  95.     now = NdbTick_CurrentMillisecond();
  96.  }
  97.   return m_tf->theClusterMgr->getNoOfConnectedNodes() > 0;
  98. }
  99. bool
  100. ExtSender::connected(Uint32 timeOutMillis, Uint32 nodeId){
  101.   NDB_TICKS start = NdbTick_CurrentMillisecond();
  102.   NDB_TICKS now = start;
  103.   //  while(m_tf->theClusterMgr->getNoOfConnectedNodes() == 0 &&
  104.   while((m_tf->get_node_alive(nodeId) != 0) &&
  105. (timeOutMillis == 0 || (now - start) < timeOutMillis)){
  106.     NdbSleep_MilliSleep(100);
  107.     now = NdbTick_CurrentMillisecond();
  108.   }
  109.   return m_tf->theClusterMgr->getNoOfConnectedNodes() > 0;
  110. }
  111. NdbApiSignal * 
  112. ExtSender::getSignal() 
  113. {
  114.   /**
  115.    * @todo  This should use some kind of list of NdbApiSignals,
  116.    *        similar to the NDBAPI and the MGRSRVR.
  117.    *        The best thing would be to have set of code 
  118.    *        shared between the programs.
  119.    *        Thus the NDBAPI and MGMSRVR should be refactored.
  120.    *        /Lars
  121.    */
  122.   return new NdbApiSignal(getOwnRef());
  123. }