Router.Match
Constructor and Description |
---|
Jooby()
Creates a new Jooby instance.
|
Modifier and Type | Method and Description |
---|---|
Jooby |
after(Route.After after)
Add an after route decorator to the route pipeline.
|
<T> T |
attribute(String key)
Get an attribute by his key.
|
Jooby |
attribute(String key,
Object value)
Set an application attribute.
|
Jooby |
before(Route.Before before)
Add a before route decorator to the route pipeline.
|
Jooby |
decorator(Route.Decorator decorator)
Add a route decorator to the route pipeline.
|
Jooby |
dispatch(Executor executor,
Runnable action)
Dispatch route pipeline to the given executor.
|
Jooby |
dispatch(Runnable body)
Dispatch route pipeline to the
Router.getWorker() worker thread pool. |
Jooby |
error(ErrorHandler handler)
Add a custom error handler.
|
Jooby |
errorCode(Class<? extends Throwable> type,
StatusCode statusCode)
Map an exception type to a status code.
|
StatusCode |
errorCode(Throwable cause)
Computes the status code for the given exception.
|
Map<String,Object> |
getAttributes()
Mutable map of application attributes.
|
String |
getBasePackage()
Get base application package.
|
String |
getContextPath()
Get application context path (a.k.a as base path).
|
Environment |
getEnvironment()
Application environment.
|
ErrorHandler |
getErrorHandler()
Get the error handler.
|
ExecutionMode |
getExecutionMode()
Application execution mode.
|
org.slf4j.Logger |
getLog()
Application logger.
|
Map<ResourceKey,Object> |
getResources()
Application resource registry.
|
RouterOptions |
getRouterOptions()
Router options.
|
List<Route> |
getRoutes()
Returns all routes.
|
ServerOptions |
getServerOptions()
Server options or
null . |
Path |
getTmpdir()
Application temporary directory.
|
Executor |
getWorker()
Returns the worker thread pool.
|
Jooby |
install(Extension extension)
Install extension module.
|
Router.Match |
match(Context ctx)
Find a matching route using the given context.
|
Jooby |
mvc(Class router)
Import all route method from the given controller class.
|
<T> Jooby |
mvc(Class<T> router,
javax.inject.Provider<T> provider)
Import all route method from the given controller class.
|
Jooby |
mvc(Object router)
Import all route methods from given controller instance.
|
Jooby |
onStart(Throwing.Runnable body)
Start event is fire once all components has been initialized, for example router and web-server
are up and running, extension installed, etc...
|
Jooby |
onStop(AutoCloseable body)
Stop event is fire at application shutdown time.
|
Jooby |
parser(MediaType contentType,
Parser parser)
Register a parser for the given content type.
|
Jooby |
path(String pattern,
Runnable action)
Group one or more routes under a common path prefix.
|
Jooby |
ready(Server server)
Callback method that indicates application was successfully started it and it is ready
listening for connections.
|
Jooby |
registry(Registry registry)
Set application registry.
|
Jooby |
renderer(MediaType contentType,
Renderer renderer)
Register a route response renderer.
|
Jooby |
renderer(Renderer renderer)
Register a route response renderer.
|
<T> T |
require(Class<T> type)
Provides an instance of the given type.
|
<T> T |
require(Class<T> type,
String name)
Provides an instance of the given type where name matches it.
|
<R> Jooby |
resource(ResourceKey<R> key,
R resource)
Put an application resource.
|
<T> T |
resource(ResourceKey<T> key)
Get a resource under this key or throws a
IllegalStateException exception. |
Jooby |
responseHandler(ResponseHandler handler)
Add a response handler factory.
|
Jooby |
route(Runnable action)
Group one or more routes.
|
Route |
route(String method,
String pattern,
Route.Handler handler)
Add a route.
|
static void |
runApp(String[] args,
Class<? extends Jooby> applicationType)
Setup default environment, logging (logback or log4j2) and run application.
|
static void |
runApp(String[] args,
Consumer<Jooby> consumer)
Setup default environment, logging (logback or log4j2) and run application.
|
static void |
runApp(String[] args,
ExecutionMode executionMode,
Class<? extends Jooby> applicationType)
Setup default environment, logging (logback or log4j2) and run application.
|
static void |
runApp(String[] args,
ExecutionMode executionMode,
Consumer<Jooby> consumer)
Setup default environment, logging (logback or log4j2) and run application.
|
static void |
runApp(String[] args,
ExecutionMode executionMode,
Supplier<Jooby> provider)
Setup default environment, logging (logback or log4j2) and run application.
|
static void |
runApp(String[] args,
Supplier<Jooby> provider)
Setup default environment, logging (logback or log4j2) and run application.
|
Jooby |
setContextPath(String basePath)
Set application context path.
|
Jooby |
setDefaultWorker(Executor worker)
Set the default worker thread pool.
|
Jooby |
setEnvironment(Environment environment)
Set application environment.
|
Environment |
setEnvironmentOptions(EnvironmentOptions options)
Set environment options and initialize/overrides the environment.
|
Jooby |
setExecutionMode(ExecutionMode mode)
Set application execution mode.
|
Jooby |
setRouterOptions(RouterOptions options)
Set router options.
|
Jooby |
setServerOptions(ServerOptions serverOptions)
Set server options.
|
Jooby |
setTmpdir(Path tmpdir)
Set application temporary directory.
|
Jooby |
setWorker(Executor worker)
Set a worker thread pool.
|
Server |
start()
Start application, find a web server, deploy application, start router, extension modules,
etc..
|
Jooby |
start(Server server)
Call back method that indicates application was deploy it in the given server.
|
Jooby |
stop()
Stop application, fire the stop event to cleanup resources.
|
String |
toString() |
Jooby |
use(Predicate<Context> predicate,
Router router)
Import routes from given router.
|
Jooby |
use(Router router)
Import all routes from the given router.
|
Jooby |
use(String path,
Router router)
Import all routes from the given router and prefix them with the given path.
|
@Nullable public ServerOptions getServerOptions()
null
.null
.@Nonnull public Jooby setServerOptions(@Nonnull ServerOptions serverOptions)
serverOptions
- Server options.@Nonnull public RouterOptions getRouterOptions()
Router
getRouterOptions
in interface Router
@Nonnull public Jooby setRouterOptions(@Nonnull RouterOptions options)
Router
setRouterOptions
in interface Router
options
- router options.@Nonnull public Environment getEnvironment()
Environment.loadEnvironment(EnvironmentOptions)
.@Nonnull public Jooby setEnvironment(@Nonnull Environment environment)
environment
- Application environment.@Nonnull public Environment setEnvironmentOptions(@Nonnull EnvironmentOptions options)
options
- Environment options.@Nonnull public Jooby onStart(@Nonnull Throwing.Runnable body)
body
- Start body.@Nonnull public Jooby onStop(@Nonnull AutoCloseable body)
body
- Stop body.@Nonnull public Jooby setContextPath(@Nonnull String basePath)
Router
/
.setContextPath
in interface Router
basePath
- Context path.@Nonnull public String getContextPath()
Router
getContextPath
in interface Router
@Nonnull public Jooby use(@Nonnull Router router)
Router
@Nonnull public Jooby use(@Nonnull Predicate<Context> predicate, @Nonnull Router router)
Router
{
use(ctx -> ctx.getHost().equals("foo.com"), new FooApp());
use(ctx -> ctx.getHost().equals("bar.com"), new BarApp());
}
Imported routes are matched only when predicate pass.@Nonnull public Jooby use(@Nonnull String path, @Nonnull Router router)
Router
@Nonnull public Jooby mvc(@Nonnull Object router)
Router
@Nonnull public Jooby mvc(@Nonnull Class router)
Router
require(Class)
.@Nonnull public <T> Jooby mvc(@Nonnull Class<T> router, @Nonnull javax.inject.Provider<T> provider)
Router
@Nonnull public List<Route> getRoutes()
Router
@Nonnull public Jooby error(@Nonnull ErrorHandler handler)
Router
@Nonnull public Jooby decorator(@Nonnull Route.Decorator decorator)
Router
@Nonnull public Jooby before(@Nonnull Route.Before before)
Router
@Nonnull public Jooby after(@Nonnull Route.After after)
Router
@Nonnull public Jooby renderer(@Nonnull Renderer renderer)
Router
@Nonnull public Jooby parser(@Nonnull MediaType contentType, @Nonnull Parser parser)
Router
@Nonnull public Jooby renderer(@Nonnull MediaType contentType, @Nonnull Renderer renderer)
Router
@Nonnull public Jooby install(@Nonnull Extension extension)
extension
- Extension module.@Nonnull public Jooby dispatch(@Nonnull Runnable body)
Router
Router.getWorker()
worker thread pool. After dispatch
application code is allowed to do blocking calls.@Nonnull public Jooby dispatch(@Nonnull Executor executor, @Nonnull Runnable action)
Router
dispatch
in interface Router
executor
- Executor. ExecutorService
instances automatically
shutdown at application exit.action
- Dispatch body.@Nonnull public Jooby path(@Nonnull String pattern, @Nonnull Runnable action)
Router
@Nonnull public Jooby route(@Nonnull Runnable action)
Router
@Nonnull public Route route(@Nonnull String method, @Nonnull String pattern, @Nonnull Route.Handler handler)
Router
@Nonnull public Router.Match match(@Nonnull Context ctx)
Router
404
handler.
See Route.NOT_FOUND
.@Nonnull public Jooby errorCode(@Nonnull Class<? extends Throwable> type, @Nonnull StatusCode statusCode)
Router
@Nonnull public StatusCode errorCode(@Nonnull Throwable cause)
Router
@Nonnull public Executor getWorker()
Router
@Nonnull public Jooby setWorker(@Nonnull Executor worker)
Router
@Nonnull public Jooby setDefaultWorker(@Nonnull Executor worker)
Router
Router.getWorker()
returns the default thread pool, unless you explicitly set one.setDefaultWorker
in interface Router
worker
- Default worker thread pool.@Nonnull public org.slf4j.Logger getLog()
Router
@Nonnull public Jooby responseHandler(ResponseHandler handler)
Router
responseHandler
in interface Router
handler
- Response handler factory.@Nonnull public ErrorHandler getErrorHandler()
Router
getErrorHandler
in interface Router
@Nonnull public Path getTmpdir()
Router
@Nonnull public Jooby setTmpdir(@Nonnull Path tmpdir)
tmpdir
- Temp directory.@Nonnull public ExecutionMode getExecutionMode()
@Nonnull public Jooby setExecutionMode(@Nonnull ExecutionMode mode)
mode
- Application execution mode.@Nonnull public Map<String,Object> getAttributes()
Router
getAttributes
in interface Router
@Nonnull public Jooby attribute(@Nonnull String key, Object value)
Router
@Nonnull public <T> T attribute(@Nonnull String key)
Router
Router.getAttributes()
.@Nonnull public <T> T require(@Nonnull Class<T> type, @Nonnull String name)
Registry
@Nonnull public <T> T require(@Nonnull Class<T> type)
Registry
@Nonnull public Jooby registry(@Nonnull Registry registry)
registry
- Application registry.@Nonnull public Map<ResourceKey,Object> getResources()
Router
onStop(AutoCloseable)
(if need it).getResources
in interface Router
@Nonnull public <R> Jooby resource(@Nonnull ResourceKey<R> key, @Nonnull R resource)
Router
@Nonnull public <T> T resource(@Nonnull ResourceKey<T> key) throws IllegalStateException
Router
IllegalStateException
exception.resource
in interface Router
T
- Attribute type.key
- Attribute key.IllegalStateException
- If there is no resource under this key.@Nullable public String getBasePackage()
@Nonnull public Server start()
@Nonnull public Jooby start(@Nonnull Server server)
server
- Server.@Nonnull public Jooby ready(@Nonnull Server server)
server
- Server.@Nonnull public Jooby stop()
public static void runApp(@Nonnull String[] args, @Nonnull Class<? extends Jooby> applicationType)
args
- Application arguments.applicationType
- Application type.public static void runApp(@Nonnull String[] args, @Nonnull ExecutionMode executionMode, @Nonnull Class<? extends Jooby> applicationType)
args
- Application arguments.executionMode
- Application execution mode.applicationType
- Application type.public static void runApp(@Nonnull String[] args, @Nonnull Supplier<Jooby> provider)
args
- Application arguments.provider
- Application provider.public static void runApp(@Nonnull String[] args, @Nonnull Consumer<Jooby> consumer)
args
- Application arguments.consumer
- Application consumer.public static void runApp(@Nonnull String[] args, @Nonnull ExecutionMode executionMode, @Nonnull Consumer<Jooby> consumer)
args
- Application arguments.executionMode
- Application execution mode.consumer
- Application consumer.public static void runApp(@Nonnull String[] args, @Nonnull ExecutionMode executionMode, @Nonnull Supplier<Jooby> provider)
args
- Application arguments.executionMode
- Application execution mode.provider
- Application provider.Copyright © 2019. All rights reserved.