public class EmbeddedXVM extends Object
SrvController
to facilitate configuring and launching an embedded Talon XVM (aka Talon Server).
An EmbeddedXVM
provides a thread of control for the xvm along with the requisite
start()
and shutdown()
methods.
This class provides factory methods that allow the EmbeddedXVM
to be created in a
manner that is consistent with how the xvm would be configured and created using the non
embedded Talon XVM Main
, as well as factory methods that accept a pre configured or
programmatically created SrvConfigDescriptor
for the server.
Important Notes:
Creating multiple instances of an EmbeddedXVM
or creating one after any other
platform class has been loaded is inherently unreliable as by nature the intent of the Configurer
is to not only seed the configuration repository with the server configuration but to also perform
environment wide configuration that is used throughout the platform during static
singleton initialization of shared components. As such it is not guaranteed that an EmbeddedXVM
will behave exactly as one launched from the command line if the environment has been in any way altered
prior to creation and start()
of the EmbeddedXVM
particularly if the Configurer
s
for each xvm configure the environment in a different of conflicting fashion.
This class is not intended for use in production and is provided for use in testing situations. This class may be removed or altered in future releases, so users are encouraged to encapsulate this class to protect against changes until such time as its api has been stabliized.
Modifier and Type | Class and Description |
---|---|
static class |
EmbeddedXVM.State
Enumerates the various
EmbeddedXVM states. |
Modifier and Type | Method and Description |
---|---|
static EmbeddedXVM |
create(Configurer configurer,
String... args)
Creates an embedded talon xvm using the provided configurer and optional arguments.
|
static EmbeddedXVM |
create(Properties ddlProperties,
String xvmName)
Creates an embedded XVM.
|
static EmbeddedXVM |
create(SrvConfigDescriptor configDescriptor)
Creates an embedded talon xvm using the provided
SrvConfigDescriptor . |
static EmbeddedXVM |
create(String... args)
Bootstraps and creates an embedded talon xvm using the provided command line arguments.
|
static EmbeddedXVM |
create(URL ddlConfig,
String xvmName,
Properties configProperties)
Creates and embedded XVM using the provided DDL XML.
|
Object |
getApplication(String appName)
Gets an application loaded in this server.
|
SrvController |
getServerController()
Returns the underlying
SrvController which provides access to its
SrvAppManager |
Throwable |
getStartupError()
Returns the error associated with a failed xvm start or null if the server
started successfully, or failed without an associated exception.
|
EmbeddedXVM.State |
getState()
Gets the current xvm state.
|
void |
shutdown()
Shuts down the xvm (synchronously).
|
void |
shutdown(boolean sync)
Shuts down the xvm.
|
void |
start()
Starts the embedded talon xvm waiting until start up completes.
|
boolean |
start(long timeout)
Starts the embedded xvm, waiting for it to start.
|
EmbeddedXVM |
verifyAppsLoaded(boolean val)
Set whether the embedded XVM should verify whether apps successfully loaded on completion of start
This check is on by default.
|
boolean |
waitForStart(long timeout)
Waits for the xvm to start.
|
public static EmbeddedXVM create(Properties ddlProperties, String xvmName) throws Exception
WARNING: EmbeddedXVMs are intended for use only in testing scenarios. When launching more than one EmbeddedXVM in a JVM, the configuration bootstrapping of their environments cannot be guaranteed particularly in cases where their environment conflicts.
ddlProperties
- The x-ddl configuration properties describing the system that contains the server.xvmName
- The name of the xvmName to create (which must be defined as a server in the ddlConfig).
in the ddlConfig.Exception
- If there is an error creating the EmbeddedXVM
.public static EmbeddedXVM create(URL ddlConfig, String xvmName, Properties configProperties) throws Exception
This method parses the provided DDL document and localizes the environment for the specified target XVM. The DDL is localized using the environment from UtlEnv and the provided configProperties passed in with precedence given to the provided properties.
This method resets the environment to its original state prior to launching unless the provided configProperties
contains the value 'nv.server.embedded.suppressenvreset=true'. This helps to prevent enviroment variables set by
previous EmbeddedXVM
s from affecting this XVM launch.
WARNING: EmbeddedXVMs are intended for use only in testing scenarios. When launching more than one EmbeddedXVM in a JVM, the configuration bootstrapping of their environments cannot be guaranteed particularly in cases where their environment conflicts.
ddlConfig
- The x-ddl configuration document describing the system that contains the server.xvmName
- The name of the xvmName to create (which must be defined as a server in the ddlConfig).configProperties
- The set of configuration properties to use for DDL substitution and DDL overlay properties.
in the ddlConfig. These values will override any elements sourced from UtlEnv
.Exception
- If there is an error creating the EmbeddedXVM
.public static EmbeddedXVM create(String... args) throws Exception
This method allows creation of a Talon server using the same arguments that would be used
to launch a non embedded server using the Talon Server Main
.
Specifically this method:
Configurer
via Main.loadBootstrapConfigurer()
Configurer.configure(String[])
method with the supplied arguments
to allow it to seed the configuration repository via VMConfigurer
.
SrvController
using the embedded
WARNING: EmbeddedXVMs are intended for use only in testing scenarios. When launching more than one EmbeddedXVM in a JVM, the configuration bootstrapping of their environments cannot be guaranteed particularly in cases where their environment conflicts.
args
- The same arguments that would be passed on the command line when launching Main.main(String[])
.
It is possible to pass in "--help" to pring a listing of valid arguments.Exception
- If there is an error creating the embedded server.Main
,
SrvController
public static EmbeddedXVM create(SrvConfigDescriptor configDescriptor) throws Exception
SrvConfigDescriptor
.Exception
- If there is an error creating the embedded server.public static EmbeddedXVM create(Configurer configurer, String... args) throws Exception
This method is equivalent to create(String...)
except that the bootstrap
Configurer
invoked is the one supplied here. If the Configurer is null, no bootstrap configuration
is performed.
WARNING: EmbeddedXVMs are intended for use only in testing scenarios. When launching more than one EmbeddedXVM in a JVM, the configuration bootstrapping of their environments cannot be guaranteed particularly in cases where their environment conflicts.
configurer
- The Bootstrap Configurer to use for seeding the server configuration.args
- The same arguments that would be passed on the command line when launching Main.main(String[])
.
It is possible to pass in "--help" to pring a listing of valid arguments.Exception
- If there is an error creating the embedded server.public EmbeddedXVM verifyAppsLoaded(boolean val)
This check is on by default. Use this method to change whether the check should be performed or not
IllegalStateException
- Thrown if this method is invoked in any state other than the Init statepublic boolean start(long timeout) throws TimeoutException, Throwable
When working with multiple embedded servers that employ separate
Configurer
s it is generally not a good idea to start servers
in parallel to avoid separate configurations from stepping on
one another during the startup phase.
If this call throws an Exception, it is incumbent on the caller
to call shutdown()
.
timeout
- The time in seconds to wait for the server to start. A value of -1 means wait indefinitely,
0 means don't wait at all, otherwise wait the given number of secondsEmbeddedXVM.State.Started
, or false if it did not start in the allotted time and is still EmbeddedXVM.State.Starting
IllegalStateException
- If the server was already started.InterruptedException
- If the thread is interrupted waiting for the server to start.Throwable
- If the server fails to startTimeoutException
public void start() throws Throwable
This id equivalent to calling start(long)
with a value of -1
IllegalStateException
- If the server was already started.Throwable
public Throwable getStartupError()
public void shutdown()
public void shutdown(boolean sync)
sync
- Whether or not to synchronously shutdown the server. It is not safe to
set this value to true when called from any thread that must exit prior to server shutdown.public EmbeddedXVM.State getState()
public boolean waitForStart(long timeout) throws Throwable
timeout
- The time in seconds to wait for the server to start. A value of -1 means wait indefinitely,
0 means don't wait at all, otherwise wait the given number of secondsEmbeddedXVM.State.Starting
IllegalStateException
- If the xvm has not been started or has been shutdown.InterruptedException
- If the thread is interrupted waiting for the xvm to start.Throwable
- thrown if there is an error in xvm startup or the server was shutdown.public SrvController getServerController()
SrvController
which provides access to its
SrvAppManager
SrvController
.Copyright © 2019 Neeve Research, LLC. All Rights Reserved.