Package ninja.standalone
Class AbstractStandalone<T extends AbstractStandalone>
- java.lang.Object
-
- ninja.standalone.AbstractConsole<T>
-
- ninja.standalone.AbstractStandalone<T>
-
- Type Parameters:
T
- The concrete standalone implementation
- All Implemented Interfaces:
Runnable
,Console<T>
,Standalone<T>
public abstract class AbstractStandalone<T extends AbstractStandalone> extends AbstractConsole<T> implements Standalone<T>, Runnable
Abstract Standalone that implements most functionality required to write a concrete Standalone. Introduces new doStart(), doStop(), and doJoin() methods which are actually where you'll place most of your logic. You'll also want to subclass the configure() method to add any configuration specific to your Standalone. See NinjaJetty for example concrete implementation.
-
-
Field Summary
Fields Modifier and Type Field Description protected List<String>
baseUrls
protected String
contextPath
protected String
host
protected Long
idleTimeout
protected Integer
port
protected List<String>
serverUrls
protected String
sslKeystorePassword
protected URI
sslKeystoreUri
protected Integer
sslPort
protected String
sslTruststorePassword
protected URI
sslTruststoreUri
-
Fields inherited from class ninja.standalone.AbstractConsole
configured, externalConfigurationPath, logger, name, ninjaMode, ninjaProperties, overlayedNinjaProperties, overrideModuleOpt, overridePropertiesOpt, started
-
Fields inherited from interface ninja.standalone.Standalone
DEFAULT_CONTEXT_PATH, DEFAULT_DEV_NINJA_SSL_KEYSTORE_PASSWORD, DEFAULT_DEV_NINJA_SSL_KEYSTORE_URI, DEFAULT_DEV_NINJA_SSL_TRUSTSTORE_PASSWORD, DEFAULT_DEV_NINJA_SSL_TRUSTSTORE_URI, DEFAULT_HOST, DEFAULT_IDLE_TIMEOUT, DEFAULT_PORT, DEFAULT_SSL_PORT, DEFAULT_STANDALONE_CLASS, KEY_NINJA_CONTEXT_PATH, KEY_NINJA_HOST, KEY_NINJA_IDLE_TIMEOUT, KEY_NINJA_PORT, KEY_NINJA_SSL_KEYSTORE_PASSWORD, KEY_NINJA_SSL_KEYSTORE_URI, KEY_NINJA_SSL_PORT, KEY_NINJA_SSL_TRUSTSTORE_PASSWORD, KEY_NINJA_SSL_TRUSTSTORE_URI, KEY_NINJA_STANDALONE_CLASS
-
-
Constructor Summary
Constructors Constructor Description AbstractStandalone(String name)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description T
contextPath(String contextPath)
Sets the "context path" of the Ninja application.protected String
createBaseUrl(String scheme, String host, Integer port, String context)
protected List<String>
createBaseUrls()
protected String
createServerUrl(String scheme, String host, Integer port)
protected List<String>
createServerUrls()
protected SSLContext
createSSLContext()
protected abstract void
doJoin()
protected void
doPostConfigure()
protected void
doPreConfigure()
List<String>
getBaseUrls()
Get the urls for the application that is configured to start.String
getContextPath()
String
getHost()
Long
getIdleTimeout()
protected String
getLoggableIdentifier()
Integer
getPort()
List<String>
getServerUrls()
Get the urls for the servers that are configured to start.String
getSslKeystorePassword()
URI
getSslKeystoreUri()
Integer
getSslPort()
String
getSslTruststorePassword()
URI
getSslTruststoreUri()
T
host(String host)
T
idleTimeout(long idleTimeout)
boolean
isPortEnabled()
Tests if the clear text HTTP port is enabled.boolean
isSslPortEnabled()
Tests if the SSL HTTP port is enabled.T
join()
Joins the underlying server to wait until its finished.protected void
logStarted()
T
port(int port)
void
run()
Configure, start, add shutdown hook, and join.T
sslKeystorePassword(String keystorePassword)
T
sslKeystoreUri(URI keystoreUri)
T
sslPort(int sslPort)
T
sslTruststorePassword(String truststorePassword)
T
sslTruststoreUri(URI truststoreUri)
-
Methods inherited from class ninja.standalone.AbstractConsole
checkConfigured, checkNotConfigured, checkStarted, configure, doConfigure, doShutdown, doStart, externalConfigurationPath, getExternalConfigurationPath, getName, getNinjaMode, getNinjaProperties, name, ninjaMode, overrideModule, overrideProperties, shutdown, start, tryToUnwrapInjectorException
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface ninja.standalone.Console
configure, externalConfigurationPath, getExternalConfigurationPath, getInjector, getName, getNinjaMode, getNinjaProperties, name, ninjaMode, overrideModule, overrideProperties, shutdown, start
-
-
-
-
Field Detail
-
host
protected String host
-
port
protected Integer port
-
contextPath
protected String contextPath
-
idleTimeout
protected Long idleTimeout
-
sslPort
protected Integer sslPort
-
sslKeystoreUri
protected URI sslKeystoreUri
-
sslKeystorePassword
protected String sslKeystorePassword
-
sslTruststoreUri
protected URI sslTruststoreUri
-
sslTruststorePassword
protected String sslTruststorePassword
-
-
Constructor Detail
-
AbstractStandalone
public AbstractStandalone(String name)
-
-
Method Detail
-
doPreConfigure
protected void doPreConfigure() throws Exception
- Overrides:
doPreConfigure
in classAbstractConsole<T extends AbstractStandalone>
- Throws:
Exception
-
doPostConfigure
protected void doPostConfigure() throws Exception
- Overrides:
doPostConfigure
in classAbstractConsole<T extends AbstractStandalone>
- Throws:
Exception
-
run
public final void run()
Configure, start, add shutdown hook, and join. Does not exit.- Specified by:
run
in interfaceRunnable
- Specified by:
run
in interfaceStandalone<T extends AbstractStandalone>
-
join
public final T join() throws Exception
Description copied from interface:Standalone
Joins the underlying server to wait until its finished.- Specified by:
join
in interfaceStandalone<T extends AbstractStandalone>
- Returns:
- This standalone
- Throws:
Exception
- Thrown if an exception occurs while waiting
-
getPort
public Integer getPort()
- Specified by:
getPort
in interfaceStandalone<T extends AbstractStandalone>
-
port
public T port(int port)
- Specified by:
port
in interfaceStandalone<T extends AbstractStandalone>
-
getHost
public String getHost()
- Specified by:
getHost
in interfaceStandalone<T extends AbstractStandalone>
-
host
public T host(String host)
- Specified by:
host
in interfaceStandalone<T extends AbstractStandalone>
-
getIdleTimeout
public Long getIdleTimeout()
- Specified by:
getIdleTimeout
in interfaceStandalone<T extends AbstractStandalone>
-
idleTimeout
public T idleTimeout(long idleTimeout)
- Specified by:
idleTimeout
in interfaceStandalone<T extends AbstractStandalone>
-
getContextPath
public String getContextPath()
- Specified by:
getContextPath
in interfaceStandalone<T extends AbstractStandalone>
-
contextPath
public T contextPath(String contextPath)
Description copied from interface:Standalone
Sets the "context path" of the Ninja application. Must follow servlet spects where it starts with a "/" and does not end with a "/". https://docs.oracle.com/javaee/6/api/javax/servlet/ServletContext.html#getContextPath()- Specified by:
contextPath
in interfaceStandalone<T extends AbstractStandalone>
- Parameters:
contextPath
- The context path such as "/mycontext"- Returns:
- This standalone
-
getSslPort
public Integer getSslPort()
- Specified by:
getSslPort
in interfaceStandalone<T extends AbstractStandalone>
-
sslPort
public T sslPort(int sslPort)
- Specified by:
sslPort
in interfaceStandalone<T extends AbstractStandalone>
-
getSslKeystoreUri
public URI getSslKeystoreUri()
- Specified by:
getSslKeystoreUri
in interfaceStandalone<T extends AbstractStandalone>
-
sslKeystoreUri
public T sslKeystoreUri(URI keystoreUri)
- Specified by:
sslKeystoreUri
in interfaceStandalone<T extends AbstractStandalone>
-
getSslKeystorePassword
public String getSslKeystorePassword()
- Specified by:
getSslKeystorePassword
in interfaceStandalone<T extends AbstractStandalone>
-
sslKeystorePassword
public T sslKeystorePassword(String keystorePassword)
- Specified by:
sslKeystorePassword
in interfaceStandalone<T extends AbstractStandalone>
-
getSslTruststoreUri
public URI getSslTruststoreUri()
- Specified by:
getSslTruststoreUri
in interfaceStandalone<T extends AbstractStandalone>
-
sslTruststoreUri
public T sslTruststoreUri(URI truststoreUri)
- Specified by:
sslTruststoreUri
in interfaceStandalone<T extends AbstractStandalone>
-
getSslTruststorePassword
public String getSslTruststorePassword()
- Specified by:
getSslTruststorePassword
in interfaceStandalone<T extends AbstractStandalone>
-
sslTruststorePassword
public T sslTruststorePassword(String truststorePassword)
- Specified by:
sslTruststorePassword
in interfaceStandalone<T extends AbstractStandalone>
-
getServerUrls
public List<String> getServerUrls()
Description copied from interface:Standalone
Get the urls for the servers that are configured to start. This value does not include the configured contextPath. Returns a value in the form 'scheme://host:port'. Well-known scheme and port combinations will not include the port.- Specified by:
getServerUrls
in interfaceStandalone<T extends AbstractStandalone>
- Returns:
- The urls of the server such as http://localhost:8080
- See Also:
Standalone.getServerUrls()
-
getBaseUrls
public List<String> getBaseUrls()
Description copied from interface:Standalone
Get the urls for the application that is configured to start. This value includes the configured contextPath. Returns a value in form 'scheme://host:port/context'. Well-known scheme and port combinations will not include the port.- Specified by:
getBaseUrls
in interfaceStandalone<T extends AbstractStandalone>
- Returns:
- The uri(s) of the application such as http://localhost:8080/context
- See Also:
Standalone.getBaseUrls()
-
isPortEnabled
public boolean isPortEnabled()
Description copied from interface:Standalone
Tests if the clear text HTTP port is enabled. Usually this indicates the "ninja.port" property is > -1.- Specified by:
isPortEnabled
in interfaceStandalone<T extends AbstractStandalone>
- Returns:
- True if enabled otherwise false.
-
isSslPortEnabled
public boolean isSslPortEnabled()
Description copied from interface:Standalone
Tests if the SSL HTTP port is enabled. Usually this indicates the "ninja.ssl.port" property is > -1.- Specified by:
isSslPortEnabled
in interfaceStandalone<T extends AbstractStandalone>
- Returns:
- True if enabled otherwise false.
-
createBaseUrl
protected String createBaseUrl(String scheme, String host, Integer port, String context)
-
getLoggableIdentifier
protected String getLoggableIdentifier()
-
logStarted
protected void logStarted()
- Overrides:
logStarted
in classAbstractConsole<T extends AbstractStandalone>
-
createSSLContext
protected SSLContext createSSLContext() throws Exception
- Throws:
Exception
-
-