class P2pProcessRecordsService extends BaseSyncIntentService {

    @Override
    protected void onHandleIntent(@Nullable Intent intent) {

        super.onHandleIntent(intent);
        AllSharedPreferences allSharedPreferences = CoreLibrary.getInstance().context().allSharedPreferences();

        if (allSharedPreferences.isPeerToPeerUnprocessedEvents()) {
            CoreLibrary.getInstance().setPeerToPeerProcessing(true);

            long eventsMaxRowId = allSharedPreferences.getLastPeerToPeerSyncProcessedEvent();
            EventClientRepository eventClientRepository = CoreLibrary.getInstance().context().getEventClientRepository();

            while (eventsMaxRowId > -1) {
                EventClientQueryResult eventClientQueryResult = eventClientRepository.fetchEventClientsByRowId(eventsMaxRowId);
                List<EventClient> eventClientList = eventClientQueryResult.getEventClientList();

                if (eventClientList.size() > 0) {
                    try {
                        DrishtiApplication.getInstance().getClientProcessor().processClient(eventClientList);
                        int tableMaxRowId = eventClientRepository.getMaxRowId(EventClientRepository.Table.event);

                        if (tableMaxRowId == eventClientQueryResult.maxRowId) {
                            eventsMaxRowId = -1;
                            allSharedPreferences.resetLastPeerToPeerSyncProcessedEvent();
                        } else {
                            eventsMaxRowId = eventClientQueryResult.maxRowId;
                            allSharedPreferences.setLastPeerToPeerSyncProcessedEvent(eventClientQueryResult.maxRowId);
                        }

                        // Profile images do not have a foreign key to the clients and can therefore be saved during the sync.
                        // They also do not take long to save and therefore happen during sync
                        Timber.i("Finished processing %s EventClients", String.valueOf(eventClientList.size()));
                    } catch (Exception e) {
                        Timber.e(e);
                    }
                } else {
                    allSharedPreferences.resetLastPeerToPeerSyncProcessedEvent();
                    break;
                }

            }

            sendSyncStatusBroadcastMessage(FetchStatus.fetched);
        }
    }

    public  P2pProcessRecordsService(String name);
    public  P2pProcessRecordsService();

}