public final class FkRegex extends Object implements Fork.AtTake
Use this class in combination with TsFork
,
for example:
Takes takes = new TsFork( new FkRegex("/home", new TsHome()), new FkRegex("/account", new TsAccount()) );
Each instance of FkRegex
is being
asked only once by TsFork
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 Target
and accept an
instance of RqRegex
, which makes it very
convenient to reuse regular expression matcher, for example:
Takes takes = new TsFork( new FkRegex( "/file(.*)", new Target<RqRegex>() { @Override public Take route(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.
TsFork
,
Target
Fork.AtResponse, Fork.AtTake
Constructor and Description |
---|
FkRegex(Pattern ptn,
Takes tks)
Ctor.
|
FkRegex(Pattern ptn,
Target<RqRegex> tgt)
Ctor.
|
FkRegex(String ptn,
String text)
Ctor.
|
FkRegex(String ptn,
Take take)
Ctor.
|
FkRegex(String ptn,
Takes tks)
Ctor.
|
FkRegex(String ptn,
Target<RqRegex> tgt)
Ctor.
|
public Iterator<Take> route(Request req) throws IOException
Fork
route
in interface Fork<Take>
req
- RequestIOException
- If failsCopyright © 2015 Takes. All rights reserved.