public final class FkRegex extends Object implements Fork
Use this class in combination with TkFork
,
for example:
Take take = new TkFork( new FkRegex("/home", new TkHome()), new FkRegex("/account", new TkAccount()) );
Each instance of FkRegex
is being
asked only once by TkFork
whether the
request is good enough to be processed. If the request is suitable
for this particular fork, it will return the relevant
Take
.
Also, keep in mind that the second argument of the constructor may
be of type TkRegex
and accept an
instance of RqRegex
, which makes it very
convenient to reuse regular expression matcher, for example:
Take take = new TkFork( new FkRegex( "/file(.*)", new Target<RqRegex>() { @Override public Response act(final RqRegex req) { // Here we immediately getting access to the // matcher that was used during parsing of // the incoming request final String file = req.matcher().group(1); } } ) );
The class is immutable and thread-safe.
TkFork
,
TkRegex
Constructor and Description |
---|
FkRegex(Pattern ptn,
Response rsp)
Ctor.
|
FkRegex(Pattern ptn,
Scalar<TkRegex> tke)
Ctor.
|
FkRegex(Pattern ptn,
Take tke)
Ctor.
|
FkRegex(Pattern ptn,
TkRegex tke)
Ctor.
|
FkRegex(String ptn,
Response rsp)
Ctor.
|
FkRegex(String ptn,
String text)
Ctor.
|
FkRegex(String ptn,
Take tke)
Ctor.
|
FkRegex(String ptn,
TkRegex tke)
Ctor.
|
Modifier and Type | Method and Description |
---|---|
Opt<Response> |
route(Request req)
Process this request or ignore it.
|
public FkRegex(String ptn, Response rsp)
ptn
- Patternrsp
- Responsepublic FkRegex(Pattern ptn, Response rsp)
ptn
- Patternrsp
- Responsepublic Opt<Response> route(Request req) throws IOException
Fork
route
in interface Fork
req
- RequestIOException
- If failsCopyright © 2015–2018 Take. All rights reserved.