Class CalendarSubscriptionStorage

java.lang.Object
org.exoplatform.agenda.storage.CalendarSubscriptionStorage

@Component public class CalendarSubscriptionStorage extends Object
Maps calendar subscriptions and the occurrences they imported between their rows and their models (EXO-90278). No cache: the job reads a row right after claiming it, and must read what the claim just wrote.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    Most occurrence rows read for one subscription: comfortably above what an import keeps, so that the rows of occurrences a feed dropped are read too.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Builds the storage.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    claim(long id, String node, Date now, Date staleBefore)
    Claims a subscription for a node, due or not.
    boolean
    claimDue(long id, String node, Date now, Date staleBefore)
    Claims a due subscription for a node.
    org.exoplatform.agenda.model.CalendarSubscription
    create(org.exoplatform.agenda.model.CalendarSubscription subscription)
    Inserts a subscription.
    void
    delete(long id)
    Deletes a subscription and its occurrence rows; the events are the caller's.
    void
    deleteEvent(long id)
    Deletes an occurrence row.
    boolean
    forgetContent(long id)
    Forgets the validators and the digest of the last read (EXO-90373).
    org.exoplatform.agenda.model.CalendarSubscription
    getByCalendarId(long calendarId)
    Reads the subscription of a calendar.
    org.exoplatform.agenda.model.CalendarSubscription
    getById(long id)
    Reads a subscription.
    List<org.exoplatform.agenda.model.CalendarSubscription>
    getByOwner(long ownerIdentityId, int limit)
    Reads an owner's subscriptions, oldest first: a user's personal ones, or a space's (EXO-90373).
    org.exoplatform.agenda.model.CalendarSubscription
    Reads an owner's subscription to a URL.
    getCalendarIdsByOwner(long ownerIdentityId, int limit)
    Reads the calendars an owner's subscriptions fill (EXO-90373).
    getCalendarIdsByOwners(Collection<Long> ownerIdentityIds, int limit)
    Reads the calendars the subscriptions of several owners fill, in one statement (EXO-90373).
    getDueIds(Date now, Date staleBefore, int limit)
    Lists the subscriptions due and unclaimed.
    List<org.exoplatform.agenda.model.CalendarSubscriptionEvent>
    getEvents(long subscriptionId)
    Reads the occurrence rows of a subscription.
    boolean
    recordFailure(long id, String node, Date attempt, String lastError, Date nextRefreshDate)
    Records a failed refresh and releases the claim.
    boolean
    recordSuccess(long id, String node, String urlKey, String etag, String lastModified, String contentHash, Integer refreshMinutes, Date attempt, boolean truncated, Date nextRefreshDate)
    Records a successful refresh and releases the claim.
    boolean
    release(long id, String node)
    Releases a node's claim.
    org.exoplatform.agenda.model.CalendarSubscriptionEvent
    saveEvent(org.exoplatform.agenda.model.CalendarSubscriptionEvent event)
    Inserts or updates an occurrence row.
    boolean
    updateUrl(long id, String urlEncrypted, String urlKey, Date now)
    Points a subscription at a new URL, due at once.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • MAX_EVENT_ROWS

      public static final int MAX_EVENT_ROWS
      Most occurrence rows read for one subscription: comfortably above what an import keeps, so that the rows of occurrences a feed dropped are read too.
      See Also:
  • Constructor Details

    • CalendarSubscriptionStorage

      @Autowired public CalendarSubscriptionStorage(CalendarSubscriptionDAO subscriptionDAO, CalendarSubscriptionEventDAO subscriptionEventDAO)
      Builds the storage.
      Parameters:
      subscriptionDAO - the subscription rows
      subscriptionEventDAO - the occurrence rows
  • Method Details

    • getById

      public org.exoplatform.agenda.model.CalendarSubscription getById(long id)
      Reads a subscription.
      Parameters:
      id - technical identifier
      Returns:
      the subscription, or null
    • getByCalendarId

      public org.exoplatform.agenda.model.CalendarSubscription getByCalendarId(long calendarId)
      Reads the subscription of a calendar.
      Parameters:
      calendarId - technical identifier of the calendar
      Returns:
      the subscription, or null
    • getByUrlKey

      public org.exoplatform.agenda.model.CalendarSubscription getByUrlKey(String urlKey)
      Reads an owner's subscription to a URL.
      Parameters:
      urlKey - the key of the owner and the URL
      Returns:
      the subscription, or null
    • getByOwner

      public List<org.exoplatform.agenda.model.CalendarSubscription> getByOwner(long ownerIdentityId, int limit)
      Reads an owner's subscriptions, oldest first: a user's personal ones, or a space's (EXO-90373).
      Parameters:
      ownerIdentityId - identity identifier of the owner
      limit - most subscriptions read
      Returns:
      the subscriptions
    • getCalendarIdsByOwner

      public List<Long> getCalendarIdsByOwner(long ownerIdentityId, int limit)
      Reads the calendars an owner's subscriptions fill (EXO-90373).
      Parameters:
      ownerIdentityId - identity identifier of the owner
      limit - most calendars read
      Returns:
      technical identifiers of the calendars
    • getCalendarIdsByOwners

      public List<Long> getCalendarIdsByOwners(Collection<Long> ownerIdentityIds, int limit)
      Reads the calendars the subscriptions of several owners fill, in one statement (EXO-90373).
      Parameters:
      ownerIdentityIds - identity identifiers of the owners
      limit - most calendars read across all of them
      Returns:
      technical identifiers of the calendars, empty when no owner is named
    • create

      public org.exoplatform.agenda.model.CalendarSubscription create(org.exoplatform.agenda.model.CalendarSubscription subscription)
      Inserts a subscription. The insert is flushed, so that the engine's refusal of a second subscription of the owner to the URL surfaces here.
      Parameters:
      subscription - the subscription, without identifier
      Returns:
      the stored subscription, or null when a subscription with the same URL key or calendar already exists
    • updateUrl

      public boolean updateUrl(long id, String urlEncrypted, String urlKey, Date now)
      Points a subscription at a new URL, due at once.
      Parameters:
      id - technical identifier
      urlEncrypted - the new URL encrypted
      urlKey - the key of the new URL
      now - the instant it becomes due
      Returns:
      false when the owner already subscribes to that URL
    • forgetContent

      public boolean forgetContent(long id)
      Forgets the validators and the digest of the last read (EXO-90373).
      Parameters:
      id - technical identifier
      Returns:
      true when the row exists
    • getDueIds

      public List<Long> getDueIds(Date now, Date staleBefore, int limit)
      Lists the subscriptions due and unclaimed.
      Parameters:
      now - the current instant
      staleBefore - a claim older than this no longer counts
      limit - the batch
      Returns:
      technical identifiers, the longest waiting first
    • claimDue

      public boolean claimDue(long id, String node, Date now, Date staleBefore)
      Claims a due subscription for a node.
      Parameters:
      id - technical identifier
      node - the node
      now - the current instant
      staleBefore - a claim older than this may be taken over
      Returns:
      true when the node now holds it
    • claim

      public boolean claim(long id, String node, Date now, Date staleBefore)
      Claims a subscription for a node, due or not.
      Parameters:
      id - technical identifier
      node - the node
      now - the current instant
      staleBefore - a claim older than this may be taken over
      Returns:
      true when the node now holds it
    • release

      public boolean release(long id, String node)
      Releases a node's claim.
      Parameters:
      id - technical identifier
      node - the node
      Returns:
      true when released
    • recordSuccess

      public boolean recordSuccess(long id, String node, String urlKey, String etag, String lastModified, String contentHash, Integer refreshMinutes, Date attempt, boolean truncated, Date nextRefreshDate)
      Records a successful refresh and releases the claim.
      Parameters:
      id - technical identifier
      node - the node holding the claim
      urlKey - the key of the URL read
      etag - the entity tag read
      lastModified - the Last-Modified header read
      contentHash - digest of the body
      refreshMinutes - interval the feed advertised, null for none
      attempt - when the refresh ran
      truncated - whether part of the feed was left out
      nextRefreshDate - when the next refresh is due
      Returns:
      true when recorded
    • recordFailure

      public boolean recordFailure(long id, String node, Date attempt, String lastError, Date nextRefreshDate)
      Records a failed refresh and releases the claim.
      Parameters:
      id - technical identifier
      node - the node holding the claim
      attempt - when the refresh ran
      lastError - message code of the failure
      nextRefreshDate - when the next attempt is due
      Returns:
      true when recorded
    • delete

      public void delete(long id)
      Deletes a subscription and its occurrence rows; the events are the caller's.
      Parameters:
      id - technical identifier
    • getEvents

      public List<org.exoplatform.agenda.model.CalendarSubscriptionEvent> getEvents(long subscriptionId)
      Reads the occurrence rows of a subscription.
      Parameters:
      subscriptionId - technical identifier of the subscription
      Returns:
      the rows, oldest first
    • saveEvent

      public org.exoplatform.agenda.model.CalendarSubscriptionEvent saveEvent(org.exoplatform.agenda.model.CalendarSubscriptionEvent event)
      Inserts or updates an occurrence row.
      Parameters:
      event - the row; an identifier of 0 inserts
      Returns:
      the row as stored
    • deleteEvent

      public void deleteEvent(long id)
      Deletes an occurrence row.
      Parameters:
      id - technical identifier of the row