/** * Returns the state of a node. * If the node is not known this returns a node in the state UP (never null) if it has lower index than the max * and DOWN otherwise. */ public NodeState getNodeState(Node node) { if (node.getIndex() >= nodeCount.get(node.getType().ordinal())) return new NodeState(node.getType(), State.DOWN); return nodeStates.getOrDefault(node, new NodeState(node.getType(), State.UP)); }
NodeState newState = new NodeState(type, State.UP); StringTokenizer st = new StringTokenizer(serialized, " \t\r\f\n", false); DiskData diskData = new DiskData();
/** * Set the node state of the given node. * * Automatically adjusts number of nodes of that given type if out of range of current nodes seen. */ public void setNodeState(Node node, NodeState newState) { newState.verifyValidInSystemState(node.getType()); if (node.getIndex() >= nodeCount.get(node.getType().ordinal())) { for (int i= nodeCount.get(node.getType().ordinal()); i<node.getIndex(); ++i) { nodeStates.put(new Node(node.getType(), i), new NodeState(node.getType(), State.DOWN)); } nodeCount.set(node.getType().ordinal(), node.getIndex() + 1); } if (newState.equals(new NodeState(node.getType(), State.UP))) { nodeStates.remove(node); } else { nodeStates.put(node, newState); } if (newState.getState().equals(State.DOWN)) { // We might be setting the last node down, so we can remove some states removeLastNodesDownWithoutReason(); } }