The sports client provide several ways of filtering data to get only the data you need:
- Method 1: Filtering the correct sport type through view parameterization.
- Method 2: Filtering with client view filter
- Method 3: Filtering at source with upstream filter
- Method 4: Filtering with configuration
In this section, we focus on the last 2 and how to construct a filter.
Constructing a filter
Constructing a filter is quite easy, you just create a GeneralDataFilter
and attach the rules that you are interested. For example, if you want to just receive HDP LIVE data, you do as following:
import jayeson.model.filter.*;
import jayeson.model.filterrules.*;
...
// Create the PivotTypeFilterRule to get only HDP
PivotTypeFilterRule pivotTypeRule = new PivotTypeFilterRule();
pf.setTypes(Arrays.asList(PivotType.HDP));
// Create the OddTypeFilterRule to get only LIVE
OddTypeFilterRule oddTypeRule = new OddTypeFilterRule();
oddTypeRule.setOddTypes(Arrays.asList(OddType.LIVE));
// add the filter rules to the filter
GeneralDataFilter filter = new GeneralDataFilter();
filter.addFilterRule(pivotTypeRule);
filter.addFilterRule(oddTypeRule);
You can also negate a filter rule, meaning filter to receive only the opposite of what is set, by using the negate method of the filter rule, to not receive HDP:
pivotTypeRule.setNegated(true);
There are many types of filter rules, which you can see the details from our Filter Java Docs
Once you created a filter, you can use it to create a view as in client view filter or use it for setting upstream filter.
Upstream filter
To reduce the amount of data our server has to send to your application, you can use an upstream filter. When a filter is set, our server keeps track of the data sent to a client and perform filtering of the unnecessary data by sending suitable delete or insert commands.
The upstream filter is set by the client and it affects all views attached to the client. Let say you want to set the filter already constructed above:
// wrap the constructed filter into a FilterData to send over the network
FilterData data = new FilterData("default", filter);
// sent the filter to the upstream server that the client is connected to
client.setUpstreamFilter(data)
Setting upstream filter is a non-blocking operation and it exits immediately. Your application knows when the filter has been set when receiving the state notification calls onSwitchFilterStart
and onSwitchFilterEnd
on your push mode handler. Between these two calls, you will receive the delta commands (insert / delete) that transform the current snapshot (matching old filter) to match the new filter.
Configuration filtering
Although setting filters programmatically is more flexible, it requires work be done on the server side to keep the data matching the filter your application needs. For simple filtering need, you can use a more efficient method, which is configuration filtering.
Using this, you specify the sources of data you need in the configuration and the sport client will only consume those sources. We provide different sources for different odd types, companies and sports.
A configuration to receive only LIVE
data for SOCCER
and TENNIS
from IBC
and MATCHBOOK
looks like following:
{
"username":"<your username>",
"password":"<your password>",
"uri":"<uri given to you>",
"bookFilter": ["IBC", "MATCHBOOK"], # list of sportbooks you want to receive
"oddTypeFilter":["LIVE"], # list of odd type you want to receive
"sportFilter":["SOCCER", "TENNIS"], # list of sports you want to receive
"ttlConfig": {
"livettl": "5000",
"todayttl": "15000",
"earlyttl": "30000",
"enableTtl": true
}
}