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>baseUrlsprotected StringcontextPathprotected Stringhostprotected LongidleTimeoutprotected Integerportprotected List<String>serverUrlsprotected StringsslKeystorePasswordprotected URIsslKeystoreUriprotected IntegersslPortprotected StringsslTruststorePasswordprotected URIsslTruststoreUri-
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 TcontextPath(String contextPath)Sets the "context path" of the Ninja application.protected StringcreateBaseUrl(String scheme, String host, Integer port, String context)protected List<String>createBaseUrls()protected StringcreateServerUrl(String scheme, String host, Integer port)protected List<String>createServerUrls()protected SSLContextcreateSSLContext()protected abstract voiddoJoin()protected voiddoPostConfigure()protected voiddoPreConfigure()List<String>getBaseUrls()Get the urls for the application that is configured to start.StringgetContextPath()StringgetHost()LonggetIdleTimeout()protected StringgetLoggableIdentifier()IntegergetPort()List<String>getServerUrls()Get the urls for the servers that are configured to start.StringgetSslKeystorePassword()URIgetSslKeystoreUri()IntegergetSslPort()StringgetSslTruststorePassword()URIgetSslTruststoreUri()Thost(String host)TidleTimeout(long idleTimeout)booleanisPortEnabled()Tests if the clear text HTTP port is enabled.booleanisSslPortEnabled()Tests if the SSL HTTP port is enabled.Tjoin()Joins the underlying server to wait until its finished.protected voidlogStarted()Tport(int port)voidrun()Configure, start, add shutdown hook, and join.TsslKeystorePassword(String keystorePassword)TsslKeystoreUri(URI keystoreUri)TsslPort(int sslPort)TsslTruststorePassword(String truststorePassword)TsslTruststoreUri(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:
doPreConfigurein classAbstractConsole<T extends AbstractStandalone>- Throws:
Exception
-
doPostConfigure
protected void doPostConfigure() throws Exception- Overrides:
doPostConfigurein classAbstractConsole<T extends AbstractStandalone>- Throws:
Exception
-
run
public final void run()
Configure, start, add shutdown hook, and join. Does not exit.- Specified by:
runin interfaceRunnable- Specified by:
runin interfaceStandalone<T extends AbstractStandalone>
-
join
public final T join() throws Exception
Description copied from interface:StandaloneJoins the underlying server to wait until its finished.- Specified by:
joinin interfaceStandalone<T extends AbstractStandalone>- Returns:
- This standalone
- Throws:
Exception- Thrown if an exception occurs while waiting
-
getPort
public Integer getPort()
- Specified by:
getPortin interfaceStandalone<T extends AbstractStandalone>
-
port
public T port(int port)
- Specified by:
portin interfaceStandalone<T extends AbstractStandalone>
-
getHost
public String getHost()
- Specified by:
getHostin interfaceStandalone<T extends AbstractStandalone>
-
host
public T host(String host)
- Specified by:
hostin interfaceStandalone<T extends AbstractStandalone>
-
getIdleTimeout
public Long getIdleTimeout()
- Specified by:
getIdleTimeoutin interfaceStandalone<T extends AbstractStandalone>
-
idleTimeout
public T idleTimeout(long idleTimeout)
- Specified by:
idleTimeoutin interfaceStandalone<T extends AbstractStandalone>
-
getContextPath
public String getContextPath()
- Specified by:
getContextPathin interfaceStandalone<T extends AbstractStandalone>
-
contextPath
public T contextPath(String contextPath)
Description copied from interface:StandaloneSets 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:
contextPathin interfaceStandalone<T extends AbstractStandalone>- Parameters:
contextPath- The context path such as "/mycontext"- Returns:
- This standalone
-
getSslPort
public Integer getSslPort()
- Specified by:
getSslPortin interfaceStandalone<T extends AbstractStandalone>
-
sslPort
public T sslPort(int sslPort)
- Specified by:
sslPortin interfaceStandalone<T extends AbstractStandalone>
-
getSslKeystoreUri
public URI getSslKeystoreUri()
- Specified by:
getSslKeystoreUriin interfaceStandalone<T extends AbstractStandalone>
-
sslKeystoreUri
public T sslKeystoreUri(URI keystoreUri)
- Specified by:
sslKeystoreUriin interfaceStandalone<T extends AbstractStandalone>
-
getSslKeystorePassword
public String getSslKeystorePassword()
- Specified by:
getSslKeystorePasswordin interfaceStandalone<T extends AbstractStandalone>
-
sslKeystorePassword
public T sslKeystorePassword(String keystorePassword)
- Specified by:
sslKeystorePasswordin interfaceStandalone<T extends AbstractStandalone>
-
getSslTruststoreUri
public URI getSslTruststoreUri()
- Specified by:
getSslTruststoreUriin interfaceStandalone<T extends AbstractStandalone>
-
sslTruststoreUri
public T sslTruststoreUri(URI truststoreUri)
- Specified by:
sslTruststoreUriin interfaceStandalone<T extends AbstractStandalone>
-
getSslTruststorePassword
public String getSslTruststorePassword()
- Specified by:
getSslTruststorePasswordin interfaceStandalone<T extends AbstractStandalone>
-
sslTruststorePassword
public T sslTruststorePassword(String truststorePassword)
- Specified by:
sslTruststorePasswordin interfaceStandalone<T extends AbstractStandalone>
-
getServerUrls
public List<String> getServerUrls()
Description copied from interface:StandaloneGet 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:
getServerUrlsin 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:StandaloneGet 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:
getBaseUrlsin 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:StandaloneTests if the clear text HTTP port is enabled. Usually this indicates the "ninja.port" property is > -1.- Specified by:
isPortEnabledin interfaceStandalone<T extends AbstractStandalone>- Returns:
- True if enabled otherwise false.
-
isSslPortEnabled
public boolean isSslPortEnabled()
Description copied from interface:StandaloneTests if the SSL HTTP port is enabled. Usually this indicates the "ninja.ssl.port" property is > -1.- Specified by:
isSslPortEnabledin 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:
logStartedin classAbstractConsole<T extends AbstractStandalone>
-
createSSLContext
protected SSLContext createSSLContext() throws Exception
- Throws:
Exception
-
-