public class AgentMain extends Object
| Constructor and Description |
|---|
AgentMain()
Constructor for
AgentMain that loads the agent configuration and prepare some additional internal data. |
AgentMain(String[] args)
Constructor for
AgentMain that accepts command line arguments, loads the agent configuration and prepare
some additional internal data. |
| Modifier and Type | Method and Description |
|---|---|
void |
agentServerCommunicationsTrace(boolean enabled)
This will enable/disable agent-server communication tracing.
|
RemoteCommunicator |
createServerRemoteCommunicator(String transport,
String address,
int port,
String transportParams)
Creates a raw remote communicator that can talk to the given endpoint.
|
org.rhq.core.domain.cloud.composite.FailoverListComposite |
downloadServerFailoverList()
Downloads a new server failover list from the server and returns the failover list
that is now in effect.
|
boolean |
executePromptCommand(String command)
A public method that allows any container object that has embedded this agent to execute prompt commands on this
agent.
|
String |
getAgentHomeDirectory()
Returns the directory that is considered the "agent home" (i.e.
|
AgentManagement |
getAgentManagementMBean()
Returns the management MBean for this agent.
|
AgentRegistrationResults |
getAgentRegistration()
Returns non-
null registration information if this agent successfully registered itself during this
agent VM's lifetime. |
AgentRestartCounter |
getAgentRestartCounter()
Returns the agent restart counter object.
|
long |
getAgentServerClockDifference()
Returns the number of milliseconds this agent thinks its clock is ahead or behind from
its server's clock.
|
ClientCommandSender |
getClientCommandSender()
Returns the client sender which can be used to send commands to the server.
|
AgentConfiguration |
getConfiguration()
Returns the set of configuration preferences that the agent will use to configure things.
|
mazz.i18n.Msg |
getI18NMsg()
Returns the object that can be used to obtain I18N messages from the agent's resource bundle in the user's
locale.
|
AgentInputReader |
getIn()
Returns the current input reader where the agent is getting its input.
|
AgentPrintWriter |
getOut()
Returns the output stream that displays messages to the user.
|
Map<String,Class<? extends AgentPromptCommand>> |
getPromptCommands()
Returns the map containing all the valid prompt command definitions.
|
org.rhq.core.domain.cloud.composite.FailoverListComposite |
getServerFailoverList()
Returns an iteratable list of servers that can be used as backups when this agent needs to failover
to another server.
|
ServiceContainer |
getServiceContainer()
Returns the container that is managing our server-side communications services that accept and process incoming
messages.
|
long |
getStartTime()
Returns the time (as reported by
System.currentTimeMillis()) when the agent was
started. |
String |
getUserInput(String prompt)
Reads a line from the input stream and returns it.
|
void |
hotDeployLogConfigurationFile(String logFilePath)
This will hot-deploy a new log4j log configuration file.
|
boolean |
isPluginContainerStarted()
|
boolean |
isRegistered()
Returns
true if this agent is known to have previously been registered with the server. |
boolean |
isStarted()
Returns
true if the agent has started; false if the agent has either never been started
or has been stopped. |
AgentConfiguration |
loadConfigurationFile(String file_name)
Loads the given configuration file into the agent.
|
AgentConfiguration |
loadConfigurationFile(String pref_node_name,
String file_name)
Same as
loadConfigurationFile(String) except this allows you to indicate which preferences node the
configuration is to be stored in. |
static void |
main(String[] args)
The main method that starts the whole thing.
|
void |
overlaySystemPropertiesOnAgentConfiguration()
This is an API that allows the caller to explicitly ensure that system properties are overlaid on top of the
current agent configuration.
|
void |
performPrimaryServerSwitchoverCheck()
Asks the agent to check and see if it is currently connected to its primary server (as opposed
to one of its secondary failover servers).
|
void |
registerWithServer(long wait,
boolean regenerate_token)
This will send a registration request to the server.
|
void |
serverClockNotification(long serverTime)
This method should be called whenever the server time is known.
|
void |
shutdown()
Shuts down the agent gracefully.
|
boolean |
shutdownPluginContainer()
Shuts down the plugin container and all its child services and plugins.
|
void |
start()
This method will initialize all services and get the agent up and running.
|
boolean |
startPluginContainer(long wait_for_registration)
This starts up the plugin container.
|
boolean |
switchToServer(String server)
Tell the agent to immediately switch to another server.
|
void |
updatePlugins()
Management method to manually update plugins.
|
boolean |
waitForServer(long wait_ms)
This sleeps (blocking the calling thread) for at most the given number of milliseconds waiting for the RHQ Server
to be discovered.
|
public AgentMain()
throws Exception
AgentMain that loads the agent configuration and prepare some additional internal data.Exception - if failed to load the configuration properlypublic AgentMain(String[] args) throws Exception
AgentMain that accepts command line arguments, loads the agent configuration and prepare
some additional internal data.args - the command line arguments (may be null)Exception - if failed to load the configuration properlypublic static void main(String[] args)
args - the arguments passed on the command line (e.g. java org.rhq.enterprise.agent.AgentMain arg1 arg2 arg3)public String getAgentHomeDirectory()
public boolean isStarted()
true if the agent has started; false if the agent has either never been started
or has been stopped.true if the agent is started; false if it is stopped.public boolean isPluginContainerStarted()
public long getStartTime()
System.currentTimeMillis()) when the agent was
started. This returns 0 if the agent has been shutdown().public long getAgentServerClockDifference()
public void serverClockNotification(long serverTime)
getAgentServerClockDifference() up-to-date.serverTime - the currently know value of the server clock (epoch millis)public void start()
throws Exception
Exception - if failed to startpublic void shutdown()
public AgentPrintWriter getOut()
public AgentInputReader getIn()
null, this agent is in
daemon mode and not currently accepting input.null if the agent is not currently accepting inputpublic mazz.i18n.Msg getI18NMsg()
public AgentConfiguration getConfiguration()
public ClientCommandSender getClientCommandSender()
null,
which means the agent has been shutdown and it cannot send commands.
This is the agent's "remoting client".
public ServiceContainer getServiceContainer()
null, which means the agent has been shutdown and it cannot receive
commands.
This is the agent's "remoting server".
public AgentManagement getAgentManagementMBean()
This will return null if the agent is not started or the management MBean was
disabled.
public void agentServerCommunicationsTrace(boolean enabled)
enabled - whether or not to turn on agent comm tracingpublic void hotDeployLogConfigurationFile(String logFilePath) throws Exception
logFilePath - the path to the log file - relative to the classloader or filesystemException - if failed to hot deploy the new log configpublic org.rhq.core.domain.cloud.composite.FailoverListComposite getServerFailoverList()
null)public org.rhq.core.domain.cloud.composite.FailoverListComposite downloadServerFailoverList()
public void performPrimaryServerSwitchoverCheck()
public String getUserInput(String prompt)
If prompt is null, the standard prompt is output.
If the input stream has been closed, null is returned.
prompt - the string that will be displayed to stdout before stdin is readRuntimeException - if failed to read input for some reasonpublic Map<String,Class<? extends AgentPromptCommand>> getPromptCommands()
Class of the AgentPromptCommand implementation.public AgentConfiguration loadConfigurationFile(String pref_node_name, String file_name) throws Exception
loadConfigurationFile(String) except this allows you to indicate which preferences node the
configuration is to be stored in. See the Java Preferences API for the definition of what a preferences
node is.pref_node_name - the node name that much match the node name in the configuration file that is to be loadedfile_name - the config file to load (should exist either on the file system or in the current thread's
classloader)AgentConfiguration objectIllegalArgumentException - if the node name was invalid which occurs if the name has a forward
slash (/) in itIOException - if failed to load the configuration fileInvalidPreferencesFormatException - if the configuration file had an invalid formatBackingStoreException - if failed to access the preferences persistence storeException - on other failurespublic AgentConfiguration loadConfigurationFile(String file_name) throws Exception
fileName specifies the file as found in the
current class loader and the file will be searched there. An exception is thrown if the file cannot be found
anywhere.
It is assumed that the agent's preference node name as defined by the -p command line argument is the one that matches the node name in the given configuration file.
The agent's configuration will be those settings found in the file - specifically, they are not overridden by
system properties. If you want system properties to override any preferences found in the file, then you should
call overlaySystemPropertiesOnAgentConfiguration() after this method returns
file_name - the config file to load (should exist either on the file system or in the current thread's
classloader)AgentConfiguration objectIOException - if failed to load the configuration fileInvalidPreferencesFormatException - if the configuration file had an invalid formatBackingStoreException - if failed to access the preferences persistence storeException - on other failurespublic void overlaySystemPropertiesOnAgentConfiguration()
loadConfigurationFile(String) when you
want to allow system properties to override configuration preferences loaded from a file. Note that a runtime
exception will be thrown if the agent has not yet loaded an initial configuration.
This method ignores AgentConfiguration.doNotOverridePreferencesWithSystemProperties() - in other
words, this method will always overlay the system properties, even though the agent may have been configured not
to. Use this method with caution since you are disobeying an agent configuration preference.
public void registerWithServer(long wait,
boolean regenerate_token)
register prompt command).
This registration process is asynchronous - this method returns immediately after spawning the thread unless
the wait parameter is greater than 0. The registration will not be completed until the agent is able
to successfully send a command to the server and get a response back. If the wait period is 0, the caller is not
guaranteed this has happened when this method returns - the method return will only guarantee that the thread has
been started. If the wait period is greater than 0, then when this method returns, the agent will have been
registered or that amount of time has expired prior to successfully registering.
wait - the amount of time in milliseconds this method will wait for the registration process to
complete before returning. If 0 or less, this method will not wait and will return as
soon as the registration thread has started.regenerate_token - if true, the agent will ask for a new token even if it was already assigned
one. if false, the agent's existing token will not change.public AgentRegistrationResults getAgentRegistration()
null registration information if this agent successfully registered itself during this
agent VM's lifetime.registerWithServer(long, boolean)public boolean waitForServer(long wait_ms)
throws AgentNotSupportedException
true if the server has come up and detected by the agent;
false otherwise.
If wait_ms is 0 or less, this method will not wait at all; it will simply return the state of the
server at is is known at the time the call is made.
Note that if the agent is shutdown, this method will not wait no matter what wait_ms is. If the
agent is shutdown, false is returned immediately.
wait_ms - maximum number of milliseconds to waittrue if the server is up, false if it is not yet up or the agent has shutdownAgentNotSupportedException - If the server is up but it told us we are the wrong version, then this is thrown.
When this is thrown, the agent is currently in the midst of updating itself.public boolean isRegistered()
true if this agent is known to have previously been registered with the server. A
false means this agent needs to register with the server before it can successfully communicate with the
server.true if the agent is registered with the serverpublic void updatePlugins()
IllegalStateException - if the container is not initializedRuntimeException - for any other reason (failed to download, etc.)public boolean startPluginContainer(long wait_for_registration)
wait_for_registration
millisecond. This method will wait indefinitely if that parameter's value is 0 or less. This method will also
wait indefinitely until one or more plugins are available.wait_for_registration - the amount of milliseconds this method will wait for the agent to become registered
with the server; if 0 or less, this method blocks indefinitelytrue if the plugin container is started, false if it did not startpublic boolean switchToServer(String server)
server - the host of the server to switch to, or a full server endpoint URLtrue if successfully switched, false otherwisepublic AgentRestartCounter getAgentRestartCounter()
public boolean shutdownPluginContainer()
public RemoteCommunicator createServerRemoteCommunicator(String transport, String address, int port, String transportParams) throws Exception
PrimaryServerSwitchoverThread can use this
and the IdentifyPromptCommand can use this.transport - address - port - transportParams - Exception - if the communicator could not be createdpublic boolean executePromptCommand(String command) throws Exception
getIn() to read the input; so the caller must
either ensure the input stream is valid or it must expect errors if it tries to execute those commands that
require additional input.command - the full command to execute, including the command name and argumentstrue if the prompt command hasn't shut the agent down, false if the agent was
told by the prompt command to not accept any more inputExceptionCopyright © 2008-2014 Red Hat, Inc.. All Rights Reserved.