Performs a heartbeat with the Worker Handler.
483217
public function heartbeat()
    {
        $state = $this->worker->getState();
        if (!in_array($state, array(Worker::BUSY, Worker::READY))) {
            return;
        }

        // Detect manager crash.
        $timeout = 2500;
        if (!$this->worker->isExpired($timeout)) {
            // Worker is pretty active no heartbeat required.
            return;
        }

        if ($this->isWorkerHandlerReady()) {
            // Send a heartbeat.
            $this->sendToWorkerHandler(new Protocol\Heartbeat());

            return;
        }

        $expiry = 5000 + $this->delay;
        if (!$this->worker->isExpired($expiry)) {
            return;
        }

        // Expired, manager already destroyed this instance.
        $this->worker->setState(Worker::INVALID);
    }
270590
def _send_heartbeat_request(self):
        """"""
        if self.coordinator_unknown():
            e = Errors.GroupCoordinatorNotAvailableError(self.coordinator_id)
            return Future().failure(e)

        elif not self._client.ready(self.coordinator_id, metadata_priority=False):
            e = Errors.NodeNotReadyError(self.coordinator_id)
            return Future().failure(e)

        version = 0 if self.config['api_version'] < (0, 11, 0) else 1
        request = HeartbeatRequest[version](self.group_id,
                                            self._generation.generation_id,
                                            self._generation.member_id)
        log.debug("Heartbeat: %s[%s] %s", request.group, request.generation_id, request.member_id)  # pylint: disable-msg=no-member
        future = Future()
        _f = self._client.send(self.coordinator_id, request)
        _f.add_callback(self._handle_heartbeat_response, future, time.time())
        _f.add_errback(self._failed_request, self.coordinator_id,
                       request, future)
        return future
432229
def send_heartbeat(self):
        '''
        
        '''
        # Note that this does not take into account the time that we last
        # sent a frame. Hearbeats are so small the effect should be quite
        # limited. Also note that we're looking for something near to our
        # scheduled interval, because if this is exact, then we'll likely
        # actually send a heartbeat at twice the period, which could cause
        # a broker to kill the connection if the period is large enough. The
        # 90% bound is arbitrary but seems a sensible enough default.
        if self.connection._heartbeat:
            if time.time() >= (self._last_heartbeat_send + 0.9 *
                               self.connection._heartbeat):
                self.send_frame(HeartbeatFrame(self.channel_id))
                self._last_heartbeat_send = time.time()
1358237
def _heartbeat_loop(self):
        """"""
        self.logger.debug("running main heartbeat thread")
        while not self.closed:
            time.sleep(self.settings['SLEEP_TIME'])
            self._report_self()
607206
def do_workers(self, args):
        ''''''
        workers = self.task_master.workers(alive=not args.all)
        for k in sorted(workers.iterkeys()):
            self.stdout.write('{0} ({1})\n'.format(k, workers[k]))
            if args.details:
                heartbeat = self.task_master.get_heartbeat(k)
                for hk, hv in heartbeat.iteritems():
                    self.stdout.write('  {0}: {1}\n'.format(hk, hv))
348296
private void scheduleHeartbeat()
  {
    // elapsed time in seconds since the last heartbeat
    long elapsedSecsSinceLastHeartBeat =
        System.currentTimeMillis() / 1000 - lastHeartbeatStartTimeInSecs;

    /*
     * The initial delay for the new scheduling is 0 if the elapsed
     * time is more than the heartbeat time interval, otherwise it is the
     * difference between the heartbeat time interval and the elapsed time.
     */
    long initialDelay = Math.max(heartBeatIntervalInSecs -
                                 elapsedSecsSinceLastHeartBeat, 0);

    LOGGER.debug(
        "schedule heartbeat task with initial delay of {} seconds",
        initialDelay);

    // Creates and executes a periodic action to send heartbeats
    this.heartbeatFuture =
        this.scheduler.schedule(this, initialDelay, TimeUnit.SECONDS);
  }
120849
def heartbeat(self):
        
        url = urljoin(self.base_url, 'heartbeat')
        return self.session.get(url).json()['ok']
114563
def _handle_heartbeat(self, sender, data):
        
        # Format of packet
        parsed, data = self._unpack("<B", data)
        format = parsed[0]
        if format == PACKET_FORMAT_VERSION:
            # Kind of beat
            parsed, data = self._unpack("<B", data)
            kind = parsed[0]
            if kind == PACKET_TYPE_HEARTBEAT:
                # Extract content
                parsed, data = self._unpack("<H", data)
                port = parsed[0]
                path, data = self._unpack_string(data)
                uid, data = self._unpack_string(data)
                node_uid, data = self._unpack_string(data)
                try:
                    app_id, data = self._unpack_string(data)
                except struct.error:
                    # Compatibility with previous version
                    app_id = herald.DEFAULT_APPLICATION_ID

            elif kind == PACKET_TYPE_LASTBEAT:
                # Peer is going away
                uid, data = self._unpack_string(data)
                app_id, data = self._unpack_string(data)
                port = -1
                path = None
                node_uid = None

            else:
                _logger.warning("Unknown kind of packet: %d", kind)
                return

            try:
                self._callback(kind, uid, node_uid, app_id, sender[0], port, path)
            except Exception as ex:
                _logger.exception("Error handling heart beat: %s", ex)
193107
def _trigger_event(self, event, *args, **kwargs):
        """"""
        run_async = kwargs.pop('run_async', False)
        if event in self.handlers:
            if run_async:
                return self.start_background_task(self.handlers[event], *args)
            else:
                try:
                    return self.handlers[event](*args)
                except:
                    self.logger.exception(event + ' handler error')
942548
public function keepAlive()
        {
            while (is_resource($this->fd)) {
                if ($this->session['heartbeat_timeout'] > 0 && $this->session['heartbeat_timeout'] + $this->heartbeatStamp - 5 < time()) {
                    $this->send(self::TYPE_HEARTBEAT);
                    $this->heartbeatStamp = time();
                }

                $r = array($this->fd);
                $w = $e = null;

                if (stream_select($r, $w, $e, 5) == 0) {
                    continue;
                }

                $res    = $this->read();
                $sess   = explode(':', $res);

                if ((int) Arrays::first($sess) === self::TYPE_EVENT) {
                    unset(Arrays::first($sess), $sess[1], $sess[2]);

                    $response = json_decode(implode(':', $sess), true);
                    $name = $response['name'];
                    $data = Arrays::first($response['args']);

                    $this->stdout('debug', 'Receive event "' . $name . '" with data "' . $data . '"');

                    if (!empty($this->callbacks[$name])) {
                        foreach ($this->callbacks[$name] as $callback) {
                            call_user_func($callback, $data);
                        }
                    }
                }
            }
        }
610394
@Override
  public void heartbeat() {
    MetaCommand command = null;
    try {
      if (mMasterId.get() == UNINITIALIZED_MASTER_ID) {
        setIdAndRegister();
      }
      command = mMasterClient.heartbeat(mMasterId.get());
      handleCommand(command);
    } catch (IOException e) {
      // An error occurred, log and ignore it or error if heartbeat timeout is reached
      if (command == null) {
        LOG.error("Failed to receive leader master heartbeat command.", e);
      } else {
        LOG.error("Failed to execute leader master heartbeat command: {}", command, e);
      }
      mMasterClient.disconnect();
    }
  }
657785
boolean onHeartbeatStop()
  {
    SocketPool clusterSocketPool;
    
    if (isExternal()) {
      clusterSocketPool = _clusterSocketPool.getAndSet(null);
    }
    else {
      clusterSocketPool = _clusterSocketPool.get();
    }

    if (clusterSocketPool != null) {
      clusterSocketPool.getFactory().notifyHeartbeatStop();
    }

    /*
    if (! _heartbeatState.notifyHeartbeatStop()) {
      return false;
    }
    */
    
    log.fine("notify-heartbeat-stop " + this);

    return true;
  }
114106
protected function handleHeartbeat($data)
    {
        $this->logger->debug('received heartbeat', ['seq' => $data->d]);

        $payload = [
            'op' => Op::OP_HEARTBEAT,
            'd'  => $data->d,
        ];

        $this->send($payload);
    }
369971
protected function write_heartbeat()
    {
        $pkt = new AMQPWriter();
        $pkt->write_octet(8);
        $pkt->write_short(0);
        $pkt->write_long(0);
        $pkt->write_octet(0xCE);
        $this->write($pkt->getvalue());
    }
588653
void processBeat(Beat beat) {
        if (isRunning() && beat.isTempoMaster()) {
            setMasterTempo(beat.getEffectiveTempo());
            deliverBeatAnnouncement(beat);
        }
    }
498944
def HeartBeat(self):
    
    # In prod, self.job.lifetime is guaranteed to always be set, and is
    # always equal to self.__class__.lifetime. Some tests however, do not
    # set the job lifetime, which isn't great.
    if self.allow_overruns or not self.job.lifetime:
      return

    runtime = rdfvalue.RDFDatetime.Now() - self.run_state.started_at
    if runtime > self.lifetime:
      raise LifetimeExceededError(
          "Cronjob run has exceeded the maximum runtime of %s." % self.lifetime)
742963
def start_heartbeat(self):
        

        if not self._hb_thread:

            try:

                self._logger.info('Starting heartbeat thread')
                self._prof.prof('creating heartbeat thread', uid=self._uid)
                self._hb_terminate = threading.Event()
                self._hb_thread = threading.Thread(target=self._heartbeat, name='heartbeat')

                self._prof.prof('starting heartbeat thread', uid=self._uid)
                self._hb_thread.start()

                return True

            except Exception, ex:

                self._logger.exception('Heartbeat not started, error: %s' % ex)
                self.terminate_heartbeat()
                raise

        else:
            self._logger.warn('Heartbeat thread already running, but attempted to restart!')