Class DiffusionServer
java.lang.Object
com.pushtechnology.diffusion.api.server.DiffusionServer
- All Implemented Interfaces:
EmbeddedDiffusion
Represents an instance of the Diffusion Server.
When a server is instantiated it will attempt to load any XML configuration
files that it finds on the classpath (or in the specified directory). If no
XML files are found then the server will be loaded with default (empty)
configuration and will have to be configured before starting it.
The server may be configured by getting the root configuration using the
getConfig()
and then configuring any aspects that are required.
Once the server has been started then most aspects of the configuration can
no longer be changed.
Currently only one instance of the Diffusion Server can ever be instantiated
in a VM. Once one has been instantiated another can not be. Once a server has
been stopped it may not be restarted nor another instantiated. These
restrictions may be removed at a future release.- Since:
- 4.4
-
Nested Class Summary
Nested classes/interfaces inherited from interface com.pushtechnology.diffusion.api.server.EmbeddedDiffusion
EmbeddedDiffusion.LifecycleListener, EmbeddedDiffusion.State
-
Constructor Summary
ConstructorsConstructorDescriptionConstructor.DiffusionServer
(String propertiesDirectory, boolean embedded) Constructor.DiffusionServer
(Properties bootstrapProps) Constructor.DiffusionServer
(Properties bootstrapProps, boolean embedded) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Register for lifecycle events.final ServerConfig
Returns the root server configuration.boolean
boolean
static void
This can be invoked to run free standing.void
De-Register for lifecycle events.void
start()
Starts the server.void
stop()
Stops the server.
-
Constructor Details
-
DiffusionServer
Constructor. Creates a Diffusion Server with default configuration. Equivalent to callingDiffusionServer(Properties)
with the system properties.- Throws:
ConfigException
- If the configuration is invalid.
-
DiffusionServer
Constructor. Creates a Diffusion Server which loads xml properties from a directory specified by the provided bootstrap properties- Parameters:
bootstrapProps
- The bootstrap properties to be used for configuration- Throws:
ConfigException
- If the configuration is invalid.
-
DiffusionServer
Constructor.- Parameters:
propertiesDirectory
- The properties directory from which xml properties will be loaded. Ifnull
, the default directory will be used.embedded
- Iftrue
, do not register a JVM shutdown hook, and do not exit the JVM after stopping.- Throws:
ConfigException
- If the configuration is invalid.- Since:
- 5.0.0
-
DiffusionServer
Constructor. Creates a Diffusion Server which loads xml properties from a directory specified by the provided bootstrap properties- Parameters:
bootstrapProps
- The bootstrap properties to be used for configurationembedded
- Iftrue
, do not register a JVM shutdown hook, and do not exit the JVM after stopping.- Throws:
ConfigException
- If the configuration is invalid.- Since:
- 5.0.0
-
-
Method Details
-
getConfig
Description copied from interface:EmbeddedDiffusion
Returns the root server configuration. This may be called before starting the server to configure it or provide further configuration over and above that loaded from any XML properties files found (either on the classpath or the specified directory).- Specified by:
getConfig
in interfaceEmbeddedDiffusion
- Returns:
- configuration root
-
isStarted
public boolean isStarted()- Specified by:
isStarted
in interfaceEmbeddedDiffusion
- Returns:
- whether or not the server has started
-
isStopped
public boolean isStopped()- Specified by:
isStopped
in interfaceEmbeddedDiffusion
- Returns:
- whether or not the server has stopped
-
start
Starts the server. The server may only be started once.- Specified by:
start
in interfaceEmbeddedDiffusion
- Throws:
APIException
- if embedded and unable to start; if not embedded (seeDiffusionServer(Properties, boolean)
), the JVM will exit
-
stop
public void stop()Stops the server. If not embedded (seeDiffusionServer(Properties, boolean)
), the JVM will exit.- Specified by:
stop
in interfaceEmbeddedDiffusion
-
addLifecycleListener
Description copied from interface:EmbeddedDiffusion
Register for lifecycle events.- Specified by:
addLifecycleListener
in interfaceEmbeddedDiffusion
- Parameters:
callback
- that is called when a state transition occurs.
-
removeLifecycleListener
Description copied from interface:EmbeddedDiffusion
De-Register for lifecycle events.- Specified by:
removeLifecycleListener
in interfaceEmbeddedDiffusion
- Parameters:
callback
- to be removed.
-
main
This can be invoked to run free standing.- Parameters:
args
- the first argument may be used to specify the location of the properties directory from which XML property files will be loaded. If not specified then they are loaded from the classpath.- Throws:
Throwable
- not expected - failures should cause the JVM to exit
-