public interface Env
A env is represented by it's name. For example: dev
, prod
, etc... A
dev env is special and a module provider could do some special configuration for
development, like turning off a cache, reloading of resources, etc.
Same is true for not dev environments. For example, a module provider might create a high performance connection pool, caches, etc.
By default env is set to dev, but you can change it by setting the application.env
property to anything else.
Modifier and Type | Interface and Description |
---|---|
static interface |
Env.Builder
Build an jooby environment.
|
Modifier and Type | Field and Description |
---|---|
static Env.Builder |
DEFAULT
Default builder.
|
Modifier and Type | Method and Description |
---|---|
com.typesafe.config.Config |
config() |
default <T> Optional<T> |
ifMode(String name,
Supplier<T> fn)
Runs the callback function if the current env matches the given name.
|
Locale |
locale() |
default javaslang.API.Match<String> |
match()
Produces a
API.Match of the current Env . |
String |
name() |
Env |
onStart(Runnable task)
Add a start task, useful for initialize and/or start services at startup time.
|
Env |
onStop(Runnable task)
Add a stop task, useful for cleanup and/or stop service at stop time.
|
default String |
resolve(String text)
Returns a string with all substitutions (the
${foo.bar} syntax,
see the
spec) resolved. |
default String |
resolve(String text,
com.typesafe.config.Config source)
Returns a string with all substitutions (the
${foo.bar} syntax,
see the
spec) resolved. |
default String |
resolve(String text,
com.typesafe.config.Config source,
String startDelimiter,
String endDelimiter)
Returns a string with all substitutions (the
${foo.bar} syntax,
see the
spec) resolved. |
default String |
resolve(String text,
String startDelimiter,
String endDelimiter)
Returns a string with all substitutions (the
${foo.bar} syntax,
see the
spec) resolved. |
Routes |
routes()
Application router.
|
List<Runnable> |
startTasks() |
List<Runnable> |
stopTasks() |
default <T> javaslang.control.Option<T> |
when(Predicate<String> predicate,
T result)
Produces a
API.Match of the current Env . |
default <T> javaslang.control.Option<T> |
when(String name,
Supplier<T> fn)
Produces a
API.Match of the current Env . |
default <T> javaslang.control.Option<T> |
when(String name,
T result)
Produces a
API.Match of the current Env . |
static final Env.Builder DEFAULT
String name()
Routes routes() throws UnsupportedOperationException
Routes
.UnsupportedOperationException
- if router isn't available.com.typesafe.config.Config config()
Locale locale()
application.lang
.default String resolve(String text)
${foo.bar}
syntax,
see the
spec) resolved. Substitutions are looked up using the config()
as the root object,
that is, a substitution ${foo.bar}
will be replaced with
the result of getValue("foo.bar")
.text
- Text to process.default String resolve(String text, String startDelimiter, String endDelimiter)
${foo.bar}
syntax,
see the
spec) resolved. Substitutions are looked up using the config()
as the root object,
that is, a substitution ${foo.bar}
will be replaced with
the result of getValue("foo.bar")
.text
- Text to process.startDelimiter
- Start delimiter.endDelimiter
- End delimiter.default String resolve(String text, com.typesafe.config.Config source)
${foo.bar}
syntax,
see the
spec) resolved. Substitutions are looked up using the source
param as the
root object, that is, a substitution ${foo.bar}
will be replaced with
the result of getValue("foo.bar")
.text
- Text to process.source
- The source config to use.default String resolve(String text, com.typesafe.config.Config source, String startDelimiter, String endDelimiter)
${foo.bar}
syntax,
see the
spec) resolved. Substitutions are looked up using the source
param as the
root object, that is, a substitution ${foo.bar}
will be replaced with
the result of getValue("foo.bar")
.text
- Text to process.source
- The source config to usestartDelimiter
- Start delimiter.endDelimiter
- End delimiter.default <T> Optional<T> ifMode(String name, Supplier<T> fn)
T
- A resulting type.name
- A name to test for.fn
- A callback function.default javaslang.API.Match<String> match()
API.Match
of the current Env
.
String accessKey = env.match()"dev", () -> "1234") .when("stage", () -> "4321") .when("prod", () -> "abc") .get();
default <T> javaslang.control.Option<T> when(String name, Supplier<T> fn)
API.Match
of the current Env
.
String accessKey = env.when("dev", () -> "1234") .when("stage", () -> "4321") .when("prod", () -> "abc") .get();
T
- A resulting type.name
- A name to test for.fn
- A callback function.default <T> javaslang.control.Option<T> when(String name, T result)
API.Match
of the current Env
.
String accessKey = env.when("dev", "1234") .when("stage", "4321") .when("prod", "abc") .get();
T
- A resulting type.name
- A name to test for.result
- A constant value to return.default <T> javaslang.control.Option<T> when(Predicate<String> predicate, T result)
API.Match
of the current Env
.
String accessKey = env.when("dev", () -> "1234") .when("stage", () -> "4321") .when("prod", () -> "abc") .get();
T
- A resulting type.predicate
- A predicate to use.result
- A constant value to return.Env onStart(Runnable task)
Jooby.Module.configure(Env, Config, com.google.inject.Binder)
.
The behaviour of this method once application has been initialized is undefined
.task
- Task to run.Env onStop(Runnable task)
Jooby.Module.configure(Env, Config, com.google.inject.Binder)
.
The behaviour of this method once application has been initialized is undefined
.task
- Task to run.Copyright © 2016. All rights reserved.