Switch to the given node and map the cluster from its HELLO

@param Node $node
333755
private function switchToNode(Node $node)
    {
        $nodeId = $node->getId();
        // Return early if we're trying to switch to the current node.
        if (($this->nodeId === $nodeId)) {
            // But return early only if the current node is connected to Disque.
            // If it is disconnected, we want to overwrite it with the node
            // from the method argument, because that one is connected.
            if ($this->getCurrentNode()->isConnected()) {
                return;
            }

            // Copy the stats from the now-disconnected node object
            $this->copyNodeStats($this->getCurrentNode(), $node);
        }

        $this->resetNodeCounters();

        $this->nodeId = $nodeId;
        $this->nodes[$nodeId] = $node;
        $this->revealClusterFromHello($node);
    }
460986
public function copyNode(NodeInterface $node)
    {
        $this->nodeContextPath = $node->getContextPath();
        $this->mode = self::MODE_COPY;
    }
244493
public function addNode(Node $node): self
    {
        $this->nodes[] = $node;
        $this->nodesByType[$node::NODE_TYPE][] = $node;
        return $this;
    }
397046
public function enterNode(Node $node)
    {
        if ($node instanceof Namespace_) {
            if ($this->namespace) {
                throw new UnexpectedValueException('Multiple nested namespaces discovered (invalid AST?)');
            }

            $this->namespace = $node;
        }

        if ($node instanceof Class_) {
            if ($this->class) {
                throw new UnexpectedValueException('Multiple classes discovered');
            }

            $this->class = $node;
        }
    }
472556
protected function _switch(array $node) {
		$attrib=$node['@attrib'];
		unset($node['@attrib']);
		foreach ($node as $pos=>$block)
			if (is_string($block) && !preg_replace('/\s+/','',$block))
				unset($node[$pos]);
		return
			'<?php switch ('.$this->token($attrib['expr']).'): ?>'.
				$this->build($node).
			'<?php endswitch; ?>';
	}
1076523
function it_compiles_nodes($node)
    {
        $node->compile($this)->will(function ($args) {
            $args[0]->write('echo $message');
        });

        $this->compile($node)->getSource()->shouldMatch('/\Recho \$message/');
    }
674651
public function leaveNode(Node $node)
    {
        if ($node instanceof Class_) {
            // Build params
            $params = [];
            $paramComments = '';
            foreach ($this->params as $param) {
                if (is_array($param)) {
                    $params[] = isset($param['type']) && isset($param['name'])
                        ? new Param($param['name'], null, new Name([$param['type']]))
                        : new Param($param[0]);
                } else {
                    $params[] = new Param($param);
                }
                $paramComments .= '    * @param '
                    .(isset($param['type']) ? $param['type'] : 'mixed')
                    .' $'.(isset($param['name']) ? $param['name'] : $param)."\n";
            }
            if (count($params) > 0)
                $paramComments = '     *'."\n".$paramComments;
            // ADD statement
            $node->stmts[] = new ClassMethod(
                preg_replace('/\-\./', '_', $this->methodName),
                [
                    'type'      => 1,
                    'params'    => $params,
                ],
                [
                    'comments'  => [new Comment(sprintf(
                        '/**'."\n"
                            . (empty($this->comment) ? '' : '    * '.$this->comment."\n")
                            .'     * Ayuco: addition %s'."\n"
                            .'     * @since fill'."\n"
                            .$paramComments
                            .'     *'."\n"
                            .'     * @return'."\n"
                            .'     */',
                        date('Y-m-d h:i a'))
                    )]
                ]
            );
        }
    }
429179
protected function interruptNode(NodeInterface $node)
    {
        // if we have an interruptNodeId, bubble up until we match a node
        // else stop propagation
        return $this->interruptNodeId ? $this->interruptNodeId !== $node->getId() : false;
    }
641858
public function removeNode( $node )
	{
		foreach( $this->getNodes() as $_node )
			$this->removeEdge( $_node, $node );									//  remove all Edges of Node
		$this->nodeSet->removeNode( $node );									//  remove Node
	}
1214444
public function parseXml($node)
    {
        foreach ($node->childNodes as $item) {
            switch ($item->nodeName) {
                case "day_entry":
                    $this->_dayEntry = new DayEntry();
                    $this->_dayEntry->parseXml( $node );
                break;
                case "hours_for_previously_running_timer":
                    $this->_hoursForPrevious = $item->nodeValue;
                break;
                default:
                break;
            }
        }
    }
27995
public function enterNode(Node $node)
    {
        if ($node instanceof Class_ || $node instanceof Trait_) {
            $this->inClass = true;
        } elseif ($node instanceof FuncCall && !$this->inClass) {
            // We'll give any args at all (besides null) a pass.
            // Technically we should be checking whether the args are objects, but this will do for now.
            //
            // @todo switch this to actually validate args when we get context-aware code cleaner passes.
            if (!empty($node->args) && !$this->isNull($node->args[0])) {
                return;
            }

            // We'll ignore name expressions as well (things like `$foo()`)
            if (!($node->name instanceof Name)) {
                return;
            }

            $name = \strtolower($node->name);
            if (\in_array($name, ['get_class', 'get_called_class'])) {
                $msg = \sprintf('%s() called without object from outside a class', $name);
                throw new ErrorException($msg, 0, E_USER_WARNING, null, $node->getLine());
            }
        }
    }
385877
public function leaveNode(Node $node)
    {
        if ($node instanceof Stmt\GroupUse) {
            $nodes = [];
            foreach ($node->uses as $use) {
                $name = Name::concat($node->prefix, $use->name);
                $nodes[] = new Stmt\Use_([new Stmt\UseUse($name)]);
            }
            return $nodes;
        }
    }
238809
public function setNode(NodeInterface $node = null)
    {
        $this->node = $node;

        if ($node->getMenu() !== $this) {
            $node->setMenu($this);
        }

        return $this;
    }
569471
protected function performRemove(Node $node)
    {
        $subtree = $this->get(
            $node->getId(),
            $node[$this->getRootIdName()]
        );

        $sorter = $this->sorter();

        $byDepth = $sorter->byDepthReversed($sorter->flatify($subtree));

        array_walk_recursive($byDepth, function($node, $key){
            $node->delete();
        });

        return $this;
    }
811450
private function switchNodeIfNeeded()
    {
        $sortedNodes = $this->priorityStrategy->sort(
            $this->nodes,
            $this->nodeId
        );

        $previous = null;

        // Try to connect by priority, continue on error, return on success
        foreach($sortedNodes as $nodeCandidate) {
            // If the first recommended node is our current node and it has
            // a working connection, return early.
            // If its connection is not working, let's try and reconnect further
            // below, or find the first best connected node.
            if ($nodeCandidate->getId() === $this->nodeId &&
                $nodeCandidate->isConnected()) {
                return;
            }

            try {
                if ($nodeCandidate->isConnected()) {
                    // Say a new HELLO to the node, the cluster might have changed
                    $nodeCandidate->sayHello();
                } else {
                    $nodeCandidate->connect();
                }
            } catch (ConnectionException $e) {
                $previous = $e;
                continue;
            }

            $this->switchToNode($nodeCandidate);
            return;
        }

        throw new ConnectionException('Could not switch to any node', 0, $previous);
    }
624637
public function enterNode(Node $node)
    {
        if ($node instanceof Namespace_) {
            $this->resetContext($node->name);
        }

        $this->recordDoc($node->getAttribute('comments', []));

        return $node;
    }
952052
public function removeNode(Node $node)
    {
        $node->setNavigation(null);
        $this->nodes->removeElement($node);
    }