public class ClientsToPortsGenerator
extends java.lang.Object
| Modifier and Type | Class and Description |
|---|---|
private static class |
ClientsToPortsGenerator.HostsFileParser
Defines the hosts file parser.
|
| Modifier and Type | Field and Description |
|---|---|
private BootstrapConfig |
cfg
Configuration used to initialize the directory.
|
private DirectoryService |
ds
Instance to access the directory.
|
private static java.lang.String |
OUTPUT_FILE
The generated mapping clients to their ports will be saved into this file
|
private java.io.BufferedReader |
reader
Read data from the standard input.
|
private static java.lang.String[] |
YES_NO
Valid entries for yes/no options.
|
| Constructor and Description |
|---|
ClientsToPortsGenerator(BootstrapConfig config)
Create a new utility.
|
| Modifier and Type | Method and Description |
|---|---|
private void |
addNode(java.lang.String nodeId,
java.lang.String cls,
Attribute[] attrs)
Add a new node to the directory, having the specified class and attributes.
|
private void |
addNode(java.lang.String nodeId,
java.lang.String cls,
java.lang.Object value)
Add a new node to the directory, having the specified class and a single attribute
with the same class and specified value.
|
static boolean |
appendHost(java.lang.String filePath,
java.lang.String hostNameOrIpAddress,
java.lang.Integer value)
Appends new host and its value to the hosts file.
|
private void |
closeBatch(java.lang.String node)
Close a batch editing session.
|
private void |
deleteNode(java.lang.String nodeId)
Delete the specified node and all of its children.
|
private int |
enterPortsRangeTo(int from) |
void |
generate(java.lang.String hostsFilePath)
Main method to generate mapping clients to their ports.
|
static java.lang.String |
getPortName(java.lang.String prefix,
int from,
java.lang.Integer hostIndex,
int port)
Represents a well-defined mapping from host indices to their names.
|
static void |
main(java.lang.String[] args)
Command line driver.
|
private void |
openBatch(java.lang.String node)
Open a batch editing session for the specified node.
|
static java.util.Map<java.lang.String,java.lang.Integer> |
readHostsFile(java.lang.String filePath)
Reads the given hosts file and returns the hosts map.
|
private java.lang.String |
readLine(java.lang.String txt)
Read a line of text using the created
reader. |
private java.lang.String |
readOption(java.lang.String msg,
java.lang.String[] valid)
Ask the user to enter one of the specified valid options, using the given message.
|
private static final java.lang.String OUTPUT_FILE
private static final java.lang.String[] YES_NO
private final java.io.BufferedReader reader
private final BootstrapConfig cfg
private DirectoryService ds
public ClientsToPortsGenerator(BootstrapConfig config)
config - Configuration for accessing the directory.public void generate(java.lang.String hostsFilePath)
throws ConfigurationException,
java.io.IOException
hostsFilePath - The string representing the file path to the hosts fileConfigurationException - In case the directory service could not be initialized.java.io.IOException - If standard input can not be accessed.public static java.lang.String getPortName(java.lang.String prefix,
int from,
java.lang.Integer hostIndex,
int port)
prefix - The client prefixfrom - The beginning value of the given port rangehostIndex - The host indexport - The port numberprivate int enterPortsRangeTo(int from)
throws java.io.IOException
java.io.IOExceptionprivate void deleteNode(java.lang.String nodeId)
nodeId - The node ID.java.lang.RuntimeException - If the node or one of its children could not be deleted.private void addNode(java.lang.String nodeId,
java.lang.String cls,
java.lang.Object value)
nodeId - The node ID.cls - The node's and attribute's class.value - The attribute's value.java.lang.RuntimeException - If the node could not be added.private void addNode(java.lang.String nodeId,
java.lang.String cls,
Attribute[] attrs)
nodeId - The node ID.cls - The node's class.attrs - The node's attributes.java.lang.RuntimeException - If the node could not be added.private void openBatch(java.lang.String node)
node - The node ID.java.lang.RuntimeException - If the batch editing session could not be opened.private void closeBatch(java.lang.String node)
node - The node ID.java.lang.RuntimeException - If the batch editing session could not be closed.private java.lang.String readLine(java.lang.String txt)
throws java.io.IOException
reader.txt - Description to be written to standard output.java.io.IOException - If data could not be read.private java.lang.String readOption(java.lang.String msg,
java.lang.String[] valid)
throws java.io.IOException
msg - The message shown to the user.valid - An array of valid options.java.io.IOExceptionpublic static void main(java.lang.String[] args)
throws ConfigurationException,
java.io.IOException
args - Application command line parameters. File name is the only one expected.ConfigurationException - In case the directory service could not be initialized.java.io.IOException - If standard input can not be accessed.public static java.util.Map<java.lang.String,java.lang.Integer> readHostsFile(java.lang.String filePath)
throws java.io.IOException
filePath - The path to the hosts filejava.io.IOException - Iff create, write or read operations applied to the target file is failedpublic static boolean appendHost(java.lang.String filePath,
java.lang.String hostNameOrIpAddress,
java.lang.Integer value)
filePath - The path to the hosts filehostNameOrIpAddress - The new host addressvalue - The new host value