Interface TrsStore
-
- All Superinterfaces:
ResourceEventStore
,Store
- All Known Implementing Classes:
AbstractTrsStore
,FileTrsStore
public interface TrsStore extends ResourceEventStore
A storage mechanism for TRS. Implementation of the methods of this sub-interface should run within the context of thesynchronizer
; the caller, typically theTrsService
class, already took care of the synchronization.- Since:
- 1.10.0
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description long
addBaseMembers(long lastMemberId, Function<Consumer<ResourceSeed>,?> membersProvider)
Adds members to the base.Optional<Long>
collectBaseMembers(Optional<Long> startingMemberId, Optional<Integer> size, Optional<Integer> resourceType, Optional<String> resourceProject, Consumer<ResourceSeed> baseMembersConsumer)
Collects base members, either all of them or just a page.void
collectChangeEventSeeds(Optional<ChangeEventSeed> since, Optional<ResourceEvent.Type> eventType, Consumer<ChangeEventSeed> changeEventsConsumer)
Collects (forwards) all existingevents
intrs:ChangeLog
since (optionally) a particular event.long
countChangeEventSeeds(Optional<ChangeEventSeed> since)
Counts how manyresource events
exist intrs:ChangeLog
since (optionally) a particular event.Executor
createSynchronizer()
Creates an executor that guarantees runnable instances handling data related to this store are never executed concurrently but one at a time across the whole web application.void
deleteResources(Function<Consumer<ResourceSeed>,?> seedsProvider)
Stores deletion events for the givenresource seeds
.TrsServiceControl
getControl()
Retrieves the current state of a TRS service control.Optional<ChangeEventSeed>
getFirstChangeEventSince(Date date)
Determines the oldest change event on or after a given a date.boolean
isResourceExposed(ResourceSeed seed)
Determines whether a resource is exposed or not.Optional<Integer>
pollChangeEventSeeds(int startingOrder, int count, Consumer<ChangeEventSeed> changeEventsConsumer)
Collects (backwards) a given number ofevents
from thetrs:ChangeLog
.void
pushChangeEventSeeds(Function<Consumer<ChangeEventSeed>,?> eventsProvider)
Stores the latestevents
in thetrs:ChangeLog
.int
removeBaseMembers(Function<Consumer<ResourceSeed>,?> membersProvider)
Removes members from the base.int
removeChangeEventSeedsBefore(int order)
Removesevents
intrs:ChangeLog
prior or equal to a given order.void
restore()
Restores the store's state to the starting stage.void
saveControl(TrsServiceControl control)
Saves the current state of a TRS service control.int
synchronizeResourceEvents(int lastEventOrder)
Synchronizes all the stored events (since the last synchronization) so all of them get their rightorder
and become visible to the TRS feed.-
Methods inherited from interface com.sodius.oslc.server.trs.store.ResourceEventStore
deleteResourcesOf, isStoringEventsOf, store, store
-
Methods inherited from interface com.sodius.oslc.server.trs.store.Store
corrupt, isCorrupted
-
-
-
-
Method Detail
-
createSynchronizer
Executor createSynchronizer()
Creates an executor that guarantees runnable instances handling data related to this store are never executed concurrently but one at a time across the whole web application. If the web application is deployed in a cluster, the executor must ensure only one cluster node can execute at a time the runnable instances.Subclasses may choose to use
LockExecutors
to obtain an executor.- Returns:
- an executor that guarantees runnable instances are executed one at a time.
- See Also:
TrsStoreSynchronizer
,LockExecutors
-
restore
void restore() throws TrsStoreException
Restores the store's state to the starting stage.- Throws:
CompletionException
- if the underlying task cannot complete due to synchronization problems (e.g. a lock cannot be acquired).TrsStoreException
- if the storage cannot be reestablished to its original state by any other reason.
-
saveControl
void saveControl(TrsServiceControl control) throws TrsStoreException
Saves the current state of a TRS service control.- Parameters:
control
- the control to be saved.- Throws:
TrsStoreException
- if the control cannot be saved.
-
getControl
TrsServiceControl getControl()
Retrieves the current state of a TRS service control. This method should always return an instance even if an internal implementation-specific exception occurs, in such case, a default instance should be returned to restart over the TRS feed.- Returns:
- the TRS service control.
-
addBaseMembers
long addBaseMembers(long lastMemberId, Function<Consumer<ResourceSeed>,?> membersProvider) throws TrsStoreException
Adds members to the base. To support a consistent pagination, this method is expected to keep an order between this member and existing members, such order must be reflected by the returned id: first appended members must have lesser members ids than those appended last.The function argument provides access to ResourceSeeds to be added in this store as base members. Implementation must call the
apply()
method of this function and use as argument aConsumer
to get notified of members. Implementation is advised to use aBufferedConsumer
for optimal performance.- Parameters:
lastMemberId
- last stored member id.membersProvider
- a function that provides access to ResourceSeeds to add as base members.- Returns:
- last stored member id (relative to its position).
- Throws:
TrsStoreException
- if any other TRS store error occurs.- See Also:
BufferedConsumer
-
removeBaseMembers
int removeBaseMembers(Function<Consumer<ResourceSeed>,?> membersProvider) throws TrsStoreException
Removes members from the base.The function argument provides access to ResourceSeeds to be removed as base members from this store. Implementation must call the
apply()
method of this function and use as argument aConsumer
to get notified of members. Implementation is advised to use aBufferedConsumer
for optimal performance.- Parameters:
membersProvider
- a function that provides access to URIs to add as base members.- Returns:
- number of members removed.
- Throws:
TrsStoreException
- if any other TRS store error occurs.- See Also:
BufferedConsumer
-
collectBaseMembers
Optional<Long> collectBaseMembers(Optional<Long> startingMemberId, Optional<Integer> size, Optional<Integer> resourceType, Optional<String> resourceProject, Consumer<ResourceSeed> baseMembersConsumer) throws TrsStoreException
Collects base members, either all of them or just a page. Consumers may raiseCancellationException
to indicate the collecting process must stop, but implementations must no propagate this exception, this is a convenient way to stop a searching process.- Parameters:
startingMemberId
- optional, the initial member (id) on the page. If not present, starts from first page (member).size
- optional, number of members to populate includingstartingMemberId
if present (used for pagination).resourceType
- optional, only members of this type will be collected.resourceProject
- optional, only members of this project area will be collected.baseMembersConsumer
- base members consumer.- Returns:
- if present, the id of the next member in the next page, otherwise it means no more pages exist (or pagination was not used).
- Throws:
CompletionException
- if consumer raise it to stop the collecting process due an error occurred.TrsStoreException
- if any other TRS store error occurs.- Since:
- 3.3.0
-
pushChangeEventSeeds
void pushChangeEventSeeds(Function<Consumer<ChangeEventSeed>,?> eventsProvider) throws TrsStoreException
Stores the latestevents
in thetrs:ChangeLog
.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 aConsumer
to get notified of events. Implementation is advised to use aBufferedConsumer
for optimal performance.- Parameters:
eventsProvider
- a function that provides access to change events to become part of thetrs:ChangeLog
.- Throws:
TrsStoreException
- if any other TRS store error occurs.- See Also:
BufferedConsumer
-
pollChangeEventSeeds
Optional<Integer> pollChangeEventSeeds(int startingOrder, int count, Consumer<ChangeEventSeed> changeEventsConsumer) throws TrsStoreException
Collects (backwards) a given number ofevents
from thetrs:ChangeLog
. This method is not forced to resolve all requested events, it must just provide as many as it has from requested and fromstartingOrder
. Implementations must also consider that acount
of zero may be requested. In this case, no events must be added totarget
, but the existence of a further event must be resolved in order to determine whether or not a next page exists. This latter must be reflected in the return value. Consumers may raiseCancellationException
to indicate the collecting process must stop, but implementations must no propagate this exception, this is a convenient way to stop a searching process.- Parameters:
startingOrder
- startingevent order
inclusive.count
- number of events to poll.changeEventsConsumer
- changes events consumer.- Returns:
- event order of previous event (not included in the extraction) if present; empty
Optional
if no more events exists. - Throws:
CompletionException
- if consumer raise it to stop the collecting process due an error occurred.TrsStoreException
- if any other TRS store error occurs.
-
collectChangeEventSeeds
void collectChangeEventSeeds(Optional<ChangeEventSeed> since, Optional<ResourceEvent.Type> eventType, Consumer<ChangeEventSeed> changeEventsConsumer) throws TrsStoreException
Collects (forwards) all existingevents
intrs:ChangeLog
since (optionally) a particular event. Consumers may raiseCancellationException
to indicate the collecting process must stop, but implementations must no propagate this exception, this is a convenient way to stop a searching process.- Parameters:
since
- starting event (exclusive) to be consumed. If present, typically the lasttrs:Base cutoff event
.eventType
- the type of event to collect; all types of events ifOptional.empty()
.changeEventsConsumer
- changes events consumer.- Throws:
CompletionException
- if consumer raise it to stop the collecting process due an error occurred.TrsStoreException
- if any other TRS store error occurs.
-
countChangeEventSeeds
long countChangeEventSeeds(Optional<ChangeEventSeed> since) throws TrsStoreException
Counts how manyresource events
exist intrs:ChangeLog
since (optionally) a particular event.- Parameters:
since
- starting point to count (exclusive). If present, it is typically the lasttrs:Base cutoff event
.- Returns:
- number of events in
trs:ChangeLog
sincechangeEvent
. - Throws:
TrsStoreException
- if any other TRS store error occurs.
-
getFirstChangeEventSince
Optional<ChangeEventSeed> getFirstChangeEventSince(Date date) throws TrsStoreException
Determines the oldest change event on or after a given a date. Implementations should compare only the date part, not the time.- Parameters:
date
- point of reference to find the event- Returns:
- an empty
Optional
if no event exists; the contained reference otherwise. - Throws:
TrsStoreException
- if any other TRS store error occurs.- Since:
- 3.8.0
-
removeChangeEventSeedsBefore
int removeChangeEventSeedsBefore(int order) throws TrsStoreException
Removesevents
intrs:ChangeLog
prior or equal to a given order.- Parameters:
order
- event order of reference (inclusive) to remove events.- Returns:
- number of deleted events.
- Throws:
TrsStoreException
- if any other TRS store error occurs.
-
isResourceExposed
boolean isResourceExposed(ResourceSeed seed) throws TrsStoreException
Determines whether a resource is exposed or not. An exposed resource is one that is part of the TRS feed, this means there has not been a DELETION event for it and it is either part of the trs:base or there is a CREATION event in the trs:changeLog.- Parameters:
seed
- the resource seed.- Returns:
true
if resource is exposed,false otherwise
.- Throws:
TrsStoreException
- if a TRS store error occurs.
-
synchronizeResourceEvents
int synchronizeResourceEvents(int lastEventOrder) throws TrsStoreException
Synchronizes all the stored events (since the last synchronization) so all of them get their rightorder
and become visible to the TRS feed.- Parameters:
lastEventOrder
- thelast stored order
.- Returns:
- the new last event order to be saved in the
TrsServiceControl
class. - Throws:
TrsStoreException
- if the synchronization fails.- Since:
- 3.6.0
-
deleteResources
void deleteResources(Function<Consumer<ResourceSeed>,?> seedsProvider) throws TrsStoreException
Stores deletion events for the givenresource seeds
.Implementations MUST store events without checking
ResourceEventStore.isStoringEventsOf(Optional)
.The function argument provides access to resource seeds for which deletion events need to be added in this store. Implementation must call the
apply()
method of this function and use, as argument, aConsumer
to get notified of seeds.- Parameters:
seedsProvider
- a function that provides access to resource seeds to become part of thetrs:ChangeLog
.- Throws:
TrsStoreException
- if a TRS store error occurs.- Since:
- 3.7.0
-
-