Push mode

Instead of polling the data regularly at fixed interval, push mode allows users to be notified as and when new changes in the feed arrive. To use the push mode, you simply create a handler which implements the interface


    public interface DeltaEventHandler<M extends IBetMatch, E extends IBetEvent, R extends IBetRecord> {
        
        /** Data notification methods **/
        default public void onInsertMatch(InsertMatch<M> insertMatch) {}
        default public void onUpdateMatch(UpdateMatch<M> updateMatch) {}
        default public void onDeleteMatch(DeleteMatch<M> deleteMatch) {}
        default public void onInsertEvent(InsertEvent<E> insertEvent) {}
        default public void onUpdateEvent(UpdateEvent<E> updateEvent) {}
        default public void onDeleteEvent(DeleteEvent<E> deleteEvent) {}
        default public void onInsertOdd(InsertOdd<R> insertOdd) {}
        default public void onUpdateOdd(UpdateOdd<R> updateOdd) {}
        default public void onDeleteOdd(DeleteOdd<R> deleteOdd) {}
        default public void onRefresh(List<PartitionKey> keys) {}


        /** State notification methods **/
        default public void onSwitchFilterStart() {}
        default public void onSwitchFilterEnd() {}
        default public void onSwitchFilterFail() {}
        default public void onFullSnapshotStart() {}
        default public void onFullSnapshotEnd() {}
        default public void onReset(Reset resetKeys) {}
    }

The methods can be divided into two types of methods:

  • Data notification: these methods let user knows about the changes in the data itself. For example, onInsertMatch informs you when a match is inserted.
  • State notification: these methods let the user knows the state of the sports client or the views.

All methods are provided with empty body implementation which allows user to skip the method if not needed in their app. In most cases, users will only need to implement data notification methods of this interface to consume the data.

Data notification methods

The methods:


    default public void onInsertMatch(InsertMatch<M> insertMatch) {}
    default public void onUpdateMatch(UpdateMatch<M> updateMatch) {}
    default public void onDeleteMatch(DeleteMatch<M> deleteMatch) {}
    default public void onInsertEvent(InsertEvent<E> insertEvent) {}
    default public void onUpdateEvent(UpdateEvent<E> updateEvent) {}
    default public void onDeleteEvent(DeleteEvent<E> deleteEvent) {}
    default public void onInsertOdd(InsertOdd<R> insertOdd) {}
    default public void onUpdateOdd(UpdateOdd<R> updateOdd) {}
    default public void onDeleteOdd(DeleteOdd<R> deleteOdd) {}

All take an input which is the Insert/Update/Delete command of the corresponding data type.

The parameterization of the handler depends on the parameterization of the view that this push mode handler is attached to. For example, if you parameterize the view and attach the pushmode listener as following


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

    // PushModeHandler is a class that must implements interface DeltaEventHandler<SoccerMatch, SoccerEvent, SoccerRecord>
    PushModeHandler myHandler = new PushModeHandler();
    soccerView.register(myHandler);

Then the parameters M, E, R of the above method signatures will be SoccerMatch, SoccerEvent, SoccerRecord correspondingly.

Insert methods

The insert methods are invoked when there is a new match, event or odd is observed on the sportbooks and sent to the client. One insert commands might insert multiple objects.

Update methods

The update methods are invoked when something in the match, event, odd has changed. Currently, you will not see update match invoked.

Update events are invoked when the live state of an event change. With the UpdateEvent object, you will be able to access all the live state of the event as seen on different sportbooks as following:


    public void onUpdateEvent(UpdateEvent<E> event) {

        // List of updated events
        List<E> events = event.get()

        events.forEach(e -> {
            // extract the primary state
            e.eventState();
            // extract all event states from all companies
            e.eventStates();

        })
    }

Update odds are invoked when the rateOver, rateUnder, or rateEqual of an odd changes.

Delete methods

Delete methods are invoked whenever the corresponding data is removed from the sportbooks. Note that, deleted data might be re-inserted later on. Some sportbooks might delete an event or a match just because there is a goal score or red card awarded, and later on the same event, or match will be re-inserterd again.

Accessing the modified snapshot

Each delta event sent through handler’s method invocation can be understood as a transformantion command that modifies an existing data snapshot. To access the modified snapshot from within the method you can use the delta event method after(). The returned snapshot contains the changed / inserted data or lacks the deleted data. Example ,


    public void onDeleteMatch(DeleteMatch<E> event) {

        // List of updated events
        ISnapshot<M> snapshot = event.after()

        // this list of matches doesn't contain the deleted matches
        Collection<M> matches = snapshot.matches()

    }

State notification methods

State notification methods notify client some important moments during the operation of the client. These methods are:


    /** State notification methods **/
    default public void onSwitchFilterStart() {}
    default public void onSwitchFilterEnd() {}
    default public void onSwitchFilterFail() {}
    default public void onFullSnapshotStart() {}
    default public void onFullSnapshotEnd() {}
    default public void onReset(Reset resetKeys) {}

Fullsnapshot notification

An application consuming our feed might want to first receive all current data to do some initialization or to decide to start processing. Because of this, we provide two methods to let the application know the begining and the ends of delta commands that together produce the current snapshot of the data.

These two methods are:


    default public void onFullSnapshotStart() {}
    default public void onFullSnapshotEnd() {}

The timeline of when these two methods are called is detailed in following diagrams:

When fullsnapshot start and end are invoked

Filter notification

Beside client side filtering, we also provide upstream filtering. Whenever an upstream filter is set, our feed server will send necessary delta commands to transform the current snapshot to the new one matching the new filter. To mark the start and end of these delta commands, the below methods will be invoked:


    default public void onSwitchFilterStart() {}
    default public void onSwitchFilterEnd() {}
    default public void onSwitchFilterFail() {}

When you encounter onSwitchFilterFail, it is normally because you set an upstream filter before the previous one finished.

Data reset notification

In some cases, when we restart our server for example, you won’t receive the delete commands but will receive a reset command which tell you the type of data that is no longer invalid.


    public void onReset(Reset resetKey) {

        // Get out the partition that should be deleted
        Collection<PartitionKey> keys = resetKey.get();

        keys.forEach(k -> {
            String c = k.source();
            OddType o = k.oddType();
            SportType s = k.sportType();

            // you can delete data from the company = c and has odd type = o and 
            // sport type = s
        })

    }