private void loadCalendarEvents(
     final Calendar calendar,
     final CalendarListEntry calendarEntry,
     final UpdateInfo updateInfo,
     final Long since)
     throws IOException {
   String pageToken = null;
   do {
     long then = System.currentTimeMillis();
     final Calendar.Events.List eventsApiCall = calendar.events().list(calendarEntry.getId());
     final String uriTemplate = eventsApiCall.getUriTemplate();
     try {
       eventsApiCall.setPageToken(pageToken);
       eventsApiCall.setShowHiddenInvitations(true);
       eventsApiCall.setSingleEvents(true);
       eventsApiCall.setTimeMax(new DateTime(System.currentTimeMillis()));
       if (since != null) eventsApiCall.setTimeMin(new DateTime(since));
       final Events events = eventsApiCall.execute();
       countSuccessfulApiCall(updateInfo.apiKey, updateInfo.objectTypes, then, uriTemplate);
       final List<Event> eventList = events.getItems();
       storeEvents(updateInfo, calendarEntry, eventList);
       pageToken = events.getNextPageToken();
     } catch (Throwable e) {
       countFailedApiCall(
           updateInfo.apiKey,
           updateInfo.objectTypes,
           then,
           uriTemplate,
           ExceptionUtils.getStackTrace(e),
           eventsApiCall.getLastStatusCode(),
           eventsApiCall.getLastStatusMessage());
       throw (new RuntimeException(e));
     }
   } while (pageToken != null);
 }
 private void updateCalendarEvents(
     final Calendar calendar,
     final CalendarListEntry calendarEntry,
     final UpdateInfo updateInfo,
     long since)
     throws IOException {
   // In the unlikely case where the server was down or disconnected more than 20 days and thus
   // wasn't able to
   // check for updated items during this period, we need to constrain the updatedMin parameter to
   // a maximum
   // of 20 days in the past, at the risk of getting an error from Google
   since = Math.max(since, System.currentTimeMillis() - 20 * DateTimeConstants.MILLIS_PER_DAY);
   String pageToken = null;
   do {
     long then = System.currentTimeMillis();
     final Calendar.Events.List eventsApiCall = calendar.events().list(calendarEntry.getId());
     final String uriTemplate = eventsApiCall.getUriTemplate();
     try {
       eventsApiCall.setPageToken(pageToken);
       eventsApiCall.setShowHiddenInvitations(true);
       eventsApiCall.setSingleEvents(true);
       eventsApiCall.setTimeMax(new DateTime(System.currentTimeMillis()));
       eventsApiCall.setUpdatedMin(new DateTime(since));
       final Events events = eventsApiCall.execute();
       countSuccessfulApiCall(updateInfo.apiKey, updateInfo.objectTypes, then, uriTemplate);
       final List<Event> eventList = events.getItems();
       storeEvents(updateInfo, calendarEntry, eventList);
       pageToken = events.getNextPageToken();
     } catch (Throwable e) {
       logger.warn(
           "updateCalendarEvents unexpected httpCode="
               + eventsApiCall.getLastStatusCode()
               + " reason="
               + eventsApiCall.getLastStatusMessage()
               + " since="
               + since
               + " message="
               + e.getMessage());
       countFailedApiCall(
           updateInfo.apiKey,
           updateInfo.objectTypes,
           then,
           uriTemplate,
           ExceptionUtils.getStackTrace(e),
           eventsApiCall.getLastStatusCode(),
           eventsApiCall.getLastStatusMessage());
       throw (new RuntimeException(e));
     }
   } while (pageToken != null);
 }