Class AbstractTrsStore

    • Field Detail

      • BASE_BUFFER_SIZE

        protected static final int BASE_BUFFER_SIZE
        Proven buffer size for base members consumption with good performance for memory and db storage.
        See Also:
        Constant Field Values
      • EVENTS_BUFFER_SIZE

        protected static final int EVENTS_BUFFER_SIZE
        Proven buffer size for resource events consumption with good performance for memory and db storage.
        See Also:
        Constant Field Values
    • Constructor Detail

      • AbstractTrsStore

        public AbstractTrsStore()
    • Method Detail

      • isStoringEventsOf

        public boolean isStoringEventsOf​(Optional<String> projectAreaId)
        Description copied from interface: ResourceEventStore
        Determines whether the store is currently able to store events and, optionally, for a particular project.

        This method must not raise any exception, false must be returned silently if any of them occurred while computing the result.

        Implementations should use a temporary cache for keeping results for a very brief moment (at most 1s) in order to optimize performance. The intention is just to avoid multiple computations of the result during a single storage request, where it's very likely all events belong to the same project.

        Specified by:
        isStoringEventsOf in interface ResourceEventStore
        Parameters:
        projectAreaId - the optional project identifier.
        Returns:
        true if the given project is TRS exposed, the TRS store is not corrupted and the corresponding base is computed; false otherwise.
      • deleteResourcesOf

        public void deleteResourcesOf​(String projectId)
        Description copied from interface: ResourceEventStore
        Creates ResourceEvent.Type.DELETED events for all exposed resources of the given project in the store.

        This method is convenient to un-expose all resources of a deleted project in the hosting application.

        Implementations MUST store events, without blocking the application, only if the ResourceEventStore.isStoringEventsOf(Optional) method returns true for the given project (at the beginning of the process) and MUST avoid calling it again for each individual resource event seed because the project could not be longer accessible, and therefore, the isStoringEventsOf(Optional) method could return false for some events. If implementations decide to do not call the isStoringEventsOf(Optional) method at all, because the project could not be longer accessible from the beginning, they MUST ensure that: the store is not corrupted, the base is computed and there is a TRS functional user configured before saving events. The events MUST keep hidden from the TRS feed up to the TrsStore.synchronizeResourceEvents(int) method is called.

        This method is intended to avoid raising TrsStoreException, if something went wrong preventing the storage of the event, implementations must corrupt the storage silently.

        Specified by:
        deleteResourcesOf in interface ResourceEventStore
        Parameters:
        projectId - the project identifier of the resources to un-expose.
      • store

        protected abstract void store​(Function<Consumer<ResourceEvent>,​?> eventsProvider,
                                      int bufferSize,
                                      boolean assertStoring)
        Stores the provided events using a BufferedConsumer of the given size and indicating whether to call the isStoringEventsOf(Optional) method or not.

        The function implementation must be thread-safe, as the store will call the Function.apply(Object) method in a dedicated thread, so that calls to this method are non blocking.

        This method is intended to avoid raising TrsStoreException, if something went wrong preventing the storage of the event, implementations must corrupt the storage silently.

        The function argument provides access to change events to be added in this store. Implementation must call the apply() method of this function and use as argument a Consumer to get notified of events. Implementation is advised to use a BufferedConsumer for optimal performance.

        Parameters:
        eventsProvider - the events provider.
        bufferSize - the size for the BufferedConsumer.
        assertStoring - whether or not to call the isStoringEventsOf(Optional) method for each event seed.