public abstract class ClientBuilder
extends java.lang.Object
ProcessBuilder
instance. A special small tools are designed for
Linux / Windows OS in order to spawn the process on the OS user account.
Both tools are written in C using specific OS API and are build as executable
using ant native target. The source code and the make file for this tools are
available in the /src/native process directory.
The password is provided vis stdin redirection on both platforms.
The command line parameters for the spawned process are constructed from default
parameters stored in directory and some specific parameters stored inside a
ClientBuilderParameters
structure.Modifier and Type | Field and Description |
---|---|
protected java.util.List<java.lang.String> |
command
A collection of command line tokens
|
protected ClientBuilderParameters |
config
A Java Bean containing specific parameters
|
private static java.util.logging.Logger |
LOG
Logger
|
private java.lang.ProcessBuilder |
pb
The ProcessBuilder instance
|
private static java.util.Map<java.lang.String,java.lang.String[]> |
pendingCmds
Pending spawn commands to be retrieved by remote clients.
|
protected boolean |
remote
Indicate a remote or local spawn
|
Constructor and Description |
---|
ClientBuilder(ClientBuilderParameters config)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
private void |
addClasspath()
Add Java CLASSPATH and the main class.
|
protected abstract void |
addClientOptions()
Add custom client options to the
command . |
private void |
addConfigFile(java.lang.String userDir)
Add client configuration file if exists.
|
private void |
addServerOptions(boolean secure)
Add server properties.
|
private void |
buildCommand()
Build command for spawned process.
|
static java.lang.String[] |
getCommand(java.lang.String uuid)
Get the spawn command registered for this UUID.
|
private int |
getServerConfig(BootstrapConfig config,
java.lang.String cname,
java.lang.String gname,
java.lang.String kname,
int def)
Get a key value form configuration file.
|
protected abstract java.util.List<java.lang.String> |
getSpawnArguments()
Get the spawn arguments for a specific implementation.
|
protected void |
initNativeSecureConnection(java.util.List<java.lang.String> cmd,
java.lang.String securePort,
java.lang.String alias)
Initialize the command line parameters for a native secure connection, which is the
secure authentication method used for non-interactive clients and those interactive clients
which cannot be launched using a password.
|
java.lang.Process |
localStart(java.util.Map<java.lang.String,java.lang.String> env)
Spawn's new local Java process.
|
private java.util.List<java.lang.String> |
prepareToLaunch()
Prepare command line arguments for spawned process before to start.
|
BrokerSpawnResult |
remoteStart(Brokers brokers,
java.util.Map<java.lang.String,java.lang.String> env)
Spawn's new remote Java process.
|
static void |
removeCommand(java.lang.String uuid)
Remove the spawn command registered for this UUID.
|
private java.io.File |
setUserDir(java.lang.String userDir)
Sets this process builder's working directory.
|
private static final java.util.logging.Logger LOG
private static final java.util.Map<java.lang.String,java.lang.String[]> pendingCmds
protected java.util.List<java.lang.String> command
protected final ClientBuilderParameters config
protected boolean remote
private java.lang.ProcessBuilder pb
public ClientBuilder(ClientBuilderParameters config)
config
- The specific parameters for this client.public static java.lang.String[] getCommand(java.lang.String uuid)
uuid
- The UUID.public static void removeCommand(java.lang.String uuid)
uuid
- The UUID.protected abstract void addClientOptions()
command
.protected abstract java.util.List<java.lang.String> getSpawnArguments()
public java.lang.Process localStart(java.util.Map<java.lang.String,java.lang.String> env) throws java.io.IOException
env
- A map with environment variables for temporary account.java.io.IOException
- If something goes wrong.public BrokerSpawnResult remoteStart(Brokers brokers, java.util.Map<java.lang.String,java.lang.String> env) throws java.io.IOException
brokers
- List of brokers.env
- A map with environment variables for temporary account.java.io.IOException
- If something goes wrong.protected void initNativeSecureConnection(java.util.List<java.lang.String> cmd, java.lang.String securePort, java.lang.String alias)
spawn
tool using the spawn 0 <secure-port> <server-hostname> <server-alias> <uuid>
syntax.cmd
- The data structure to initialize with the parametes for the native secure
connection.securePort
- The server's secure port or -1 if this is a remote launch (the port will be
dynamically filled in later in that case).alias
- The alias of the server certificate in the certificate key store which will
be used to authenticate that this server indeed is on the other side of the
secure connection.private java.util.List<java.lang.String> prepareToLaunch() throws java.io.IOException
java.io.IOException
- On error.private void addServerOptions(boolean secure)
secure
- Indicating to setup a secure true
or an insecure false
connection.private int getServerConfig(BootstrapConfig config, java.lang.String cname, java.lang.String gname, java.lang.String kname, int def)
config
- Configuration file.cname
- Category name.gname
- Group name.kname
- Key name.def
- Key value if exists default value otherwise.private void addClasspath()
private void addConfigFile(java.lang.String userDir)
userDir
- Client working directory.private java.io.File setUserDir(java.lang.String userDir)
userDir
- Server working directory.private void buildCommand() throws java.io.IOException
java.io.IOException
- If something goes wrong.