-
Notifications
You must be signed in to change notification settings - Fork 2
Handlers
Handlers
, and in particular OutputHandlers
are the means of receiving and processing the output from the Crawler
. The Crawler
sends its outputs, which are Matches
, to its OutputHandler
.
An OutputHandler
requires the handle
method from the Handler
interface to be implemented, which is a void
that simply takes an input Match
and processes it (i.e uploads its contents to a database).
If one requires pre-processing before handling it, i.e converting the Match
into some other object and then handling such object, they are to use a FormattingOutputHandler
, which takes a MatchFormatter
and a Handler
that handles the generic type produced from the input MatchFormatter
.
There also exists a FilteringOutputHandler
, which first filters the incoming Match
based upon a given MatchFilter
, and then will only apply its super OutputHandler
if the Match
was accepted by the filter.
Below is an example of constructing an OutputHandler:
public class ExampleOutputHandler extends OutputHandler {
public void handle(Match m) {
// do something with the Match...
}
}
and now constructing a FilteringOutputHandler
which will first filter the Match
with preset GameDurationMatchFilter
and if successful pass the result to an ExampleOutputHandler
(there is a Factory for FilteringOutputHandlers
:
FilteringOutputHandler filteringOutputHandler = FilteringOutputHandlerFactory.get(new GameDurationMatchFilter(), new ExampleOutputHandler());
and finally constructing a FormattingOutputHandler
which will first format the input Match
into a Teams
object which contains the team statistics as Team
Orianna core objects for both teams in the Match, and then the Handler
will take a Teams
object and do something with the Team
objects within:
Handler<Teams> teamsHandler = new Handler<Teams>() {
@Override
public void handle(Teams input) {
Team red = input.getRed();
Team blue = input.getBlue();
// do something with the Team data...
}
};
FormattingOutputHandler<Teams> formattingOutputHandler = new FormattingOutputHandler<>(new TeamStatsMatchFormatter(), teamsHandler);
It's important to note that since FilteringOutputHandlers
and FormattingOutputHandlers
are both OutputHandlers
, one may embed them within eachother to obtain filtering and formatting output handlers. If one requires this, firstly construct a FormattingOutputHandler
as above, then construct a FilteringOutputHandler
with its Factory, passing the FormattingOutputHandler
into its get
method.
One may find the following preset OutputHandlers in presets/outputhandlers
. They can be extended into FormattingOutputHandlers
or FilteringOutputHandlers
, as above.
-
PrintOutputHandler
- uses a givenStringMatchFormatter
to format an inputMatch
into a String, and then prints the result to System.out. -
PostFirebaseOutputHandler
- uses a givenFirebaseDataMatchFormatter
to format an inputMatch
into aFirebaseData
object. SuchFirebaseData
object stores the connection to the Firebase, the path in the Firebase to post the result, and the JSON String that shall be posted at the path in the Firebase. Obtaining the context from theFirebaseData
object, the handler uses the connection to post the JSON String to the Google Firebase.