Client views

Concept

The client views allow you work with part of the data stream that is relevant to a specific purpose. For example, if your data stream received from our server can contain both tennis and soccer data, you might want to create a view for soccer to work with the soccer related components, and a view for tennis to work with tennis related components of your application. A view presents a focused view of odds that you have configured through FeedView objects and Filters. By using client view, you can focus on what’s important to you.

Views

Views perform filtering on feed data. The simplest view is the view without any filter. To create such a view, do the following:


    FeedView<IBetMatch> noFilterView = client.view(IBetMatch.class);

Views also determine the shape of records that will be retrieved, you can choose the shape of the records to be used with the view through parameterization during view creation.

Each sport uses a different record shape. IBetMatch provides a generic API for all sports where as IB2Match provides a generic API for all sports with two side playing against each other. You can also create a view with specific sport type to use sport specific API that is suitable for you. For more information check our multi-level API

Examples below are how you parameterize the record shape to specify sport type to use sport specific API:


    FeedView<SoccerMatch> soccerNoFilter = client.view(SoccerMatch.class);

    FeedView<TennisMatch> tennisNoFilter = client.view(TennisMatch.class);

    FeedView<BasketballMatch> basketballNoFilter = client.view(BasketballMatch.class);

As you can also see above, a single client attach multiple views concurrently.

View Parameterization Filtering

Although the main purpose of parameterization is to give you data under the specific type that is most convenient for you, it is a form of data filtering as well. A view only gives you the data of the correct type. In the above example, tennisNoFilter view will only give Tennis related data which are TennisMatch, TennisEvent, TennisRecord although your client might be consuming multiple sports from our server at the same time.

Client side filter

While using parameterization is one way of filtering and can help you choose a specific sport data, a view can provide even more detailed filtering. One example where this is useful is when you want to work with data of specific property, like HDP or TOTAL or LIVE or TODAY data. Below shows how you are able to create a view with a filter that only accept data LIVE TENNIS data.


    /* This example retrieves only tennis live odds. */
    SportFilterRule sportRule = new SportFilterRule();
    sportRule.setSportTypes(Arrays.asList(SportType.TENNIS));
    
    OddTypeFilterRule oddTypeRule = new OddTypeFilterRule();
    oddTypeRule.setOddTypes(Arrays.asList(OddType.LIVE));
    
    GeneralDataFilter filter = new GeneralDataFilter();
    filter.addFilterRule(sportRule);
    filter.addFilterRule(oddTypeRule);
    
    /* Client side filter decides the records to be sent to the local view(s) 
    * Make sure you implement either upstream or local view filter to filter out other sport types 
    * as the FeedView declared below only support TennisMatch as what you have parameterized */
    FeedView<TennisMatch> tennisMatchFeedView = client.view(filter, TennisMatch.class);

There are many types of filter rules, which you can see the details from our Filter Java Docs

Once a view is created, its filters cannot be modified. A new view has to be created to modify the filter terms.

You can choose to retrieve data by polling the view or by attaching an event handler. Multiple handlers can be registered to a single view.


    TennisMatchPushModeHandler myHandler = new TennisMatchPushModeHandler("filtered");
    tennisMatchFeedView.register(myHandler);

Upon registering the handler, insert events will begin streaming into the handler. Hence, you might want ensure that the handler is ready to process events before registering it with a view to avoid missing some data at the begining.

Clean Up

Once an event handler is no longer needed, it should be unregistered from a view. This frees up resources and prevents any memory leaks.

The original handler is needed to successfully unregister it from the view.


    view.unregister(myHandler);

Similarly, when a view is not needed, you can remove it from the client


    client.removeView(view);

Read more about Feed View API here.