From 464bd5d54b6b55a84dd7245f48164ec0a72cd49c Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Tue, 3 Jun 2008 08:31:55 +0200 Subject: [PATCH] add id to node --- src/net/pterodactylus/jsite/core/Node.java | 24 ++++++++++++++++++++--- src/net/pterodactylus/jsite/core/NodeManager.java | 8 ++++++++ 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/src/net/pterodactylus/jsite/core/Node.java b/src/net/pterodactylus/jsite/core/Node.java index 183a916..5a8ec89 100644 --- a/src/net/pterodactylus/jsite/core/Node.java +++ b/src/net/pterodactylus/jsite/core/Node.java @@ -40,6 +40,9 @@ public class Node extends AbstractBean { /** Name of the “port” property. */ public static final String PROPERTY_PORT = "port"; + /** Internal ID. */ + private String id; + /** The name of the node. */ private String name; @@ -49,9 +52,24 @@ public class Node extends AbstractBean { /** The port number of the node. */ private int port; - // - // EVENT MANAGEMENT - // + /** + * Returns the internal ID of the node. + * + * @return The internal ID of the node + */ + String getId() { + return id; + } + + /** + * Sets the internal ID of the node. + * + * @param id + * The internal ID of the node + */ + void setId(String id) { + this.id = id; + } /** * Returns the user-given name of the node. diff --git a/src/net/pterodactylus/jsite/core/NodeManager.java b/src/net/pterodactylus/jsite/core/NodeManager.java index 56910ae..4224cf1 100644 --- a/src/net/pterodactylus/jsite/core/NodeManager.java +++ b/src/net/pterodactylus/jsite/core/NodeManager.java @@ -42,8 +42,10 @@ import net.pterodactylus.fcp.highlevel.HighLevelClient; import net.pterodactylus.fcp.highlevel.HighLevelClientListener; import net.pterodactylus.fcp.highlevel.HighLevelException; import net.pterodactylus.fcp.highlevel.KeyGenerationResult; +import net.pterodactylus.jsite.util.IdGenerator; import net.pterodactylus.util.io.Closer; import net.pterodactylus.util.logging.Logging; +import net.pterodactylus.util.number.Hex; /** * TODO @@ -238,6 +240,10 @@ public class NodeManager implements Iterable, PropertyChangeListener, High List loadedNodes = new ArrayList(); while (nodeProperties.containsKey("nodes." + ++nodeIndex + ".name")) { String nodePrefix = "nodes." + nodeIndex; + String nodeId = nodeProperties.getProperty(nodePrefix + ".id"); + if (nodeId == null) { + nodeId = Hex.toHex(IdGenerator.generateId()); + } String nodeName = nodeProperties.getProperty(nodePrefix + ".name"); if (!Verifier.verifyNodeName(nodeName)) { logger.log(Level.WARNING, "invalid node name “" + nodeName + "”, skipping…"); @@ -262,6 +268,7 @@ public class NodeManager implements Iterable, PropertyChangeListener, High continue; } Node newNode = new Node(); + newNode.setId(nodeId); newNode.setName(nodeName); newNode.setHostname(nodeHostname); newNode.setPort(nodePort); @@ -293,6 +300,7 @@ public class NodeManager implements Iterable, PropertyChangeListener, High int nodeIndex = -1; for (Node node : nodes) { String nodePrefix = "nodes." + ++nodeIndex; + nodeProperties.setProperty(nodePrefix + ".id", node.getId()); nodeProperties.setProperty(nodePrefix + ".name", node.getName()); nodeProperties.setProperty(nodePrefix + ".hostname", node.getHostname()); nodeProperties.setProperty(nodePrefix + ".port", String.valueOf(node.getPort())); -- 2.7.4