Class AbstractTrsStore
- java.lang.Object
-
- com.sodius.oslc.server.trs.store.AbstractTrsStore
-
- All Implemented Interfaces:
ResourceEventStore
,Store
,TrsStore
- Direct Known Subclasses:
FileTrsStore
public abstract class AbstractTrsStore extends Object implements TrsStore
Partial implementation of aTrsStore
fulfilling the contract ofResourceEventStore
.- Since:
- 3.3.0
-
-
Field Summary
Fields Modifier and Type Field Description protected static int
BASE_BUFFER_SIZE
Proven buffer size for base members consumption with good performance for memory and db storage.protected static int
EVENTS_BUFFER_SIZE
Proven buffer size for resource events consumption with good performance for memory and db storage.
-
Constructor Summary
Constructors Constructor Description AbstractTrsStore()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
deleteResources(Function<Consumer<ResourceSeed>,?> seedsProvider)
Stores deletion events for the givenresource seeds
.void
deleteResourcesOf(String projectId)
CreatesResourceEvent.Type.DELETED
events for all exposed resources of the given project in the store.boolean
isStoringEventsOf(Optional<String> projectAreaId)
Determines whether the store is currently able to store events and, optionally, for a particular project.void
store(ResourceEvent... resourceEvents)
Stores one or a fewresource events
.void
store(Function<Consumer<ResourceEvent>,?> eventsProvider)
Storesresource events
.protected abstract void
store(Function<Consumer<ResourceEvent>,?> eventsProvider, int bufferSize, boolean assertStoring)
Stores the provided events using aBufferedConsumer
of the given size and indicating whether to call theisStoringEventsOf(Optional)
method or not.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.sodius.oslc.server.trs.store.Store
corrupt, isCorrupted
-
Methods inherited from interface com.sodius.oslc.server.trs.store.TrsStore
addBaseMembers, collectBaseMembers, collectChangeEventSeeds, countChangeEventSeeds, createSynchronizer, getControl, getFirstChangeEventSince, isResourceExposed, pollChangeEventSeeds, pushChangeEventSeeds, removeBaseMembers, removeChangeEventSeedsBefore, restore, saveControl, synchronizeResourceEvents
-
-
-
-
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
-
-
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 interfaceResourceEventStore
- Parameters:
projectAreaId
- the optional project identifier.- Returns:
true
if the given project isTRS exposed
, theTRS store is not corrupted
and the correspondingbase is computed
;false
otherwise.
-
store
public void store(ResourceEvent... resourceEvents)
Description copied from interface:ResourceEventStore
Stores one or a fewresource events
. If a larger volume of events is to send at once, client is recommended to rather use theResourceEventStore.store(Function)
method.Implementations MUST store events, without blocking the application, only if the
ResourceEventStore.isStoringEventsOf(Optional)
method returnstrue
, for each of the givenevent seeds
, and must keep them hidden from the TRS feed up to theTrsStore.synchronizeResourceEvents(int)
method is called.This method is intended to avoid raising
TrsStoreException
, if something went wrong preventing the storage of the event, implementations mustcorrupt
the storage silently.- Specified by:
store
in interfaceResourceEventStore
- Parameters:
resourceEvents
- events to store.
-
store
public void store(Function<Consumer<ResourceEvent>,?> eventsProvider)
Description copied from interface:ResourceEventStore
Storesresource events
. If only one or a few events are to report at once, client may use the simplerResourceEventStore.store(ResourceEvent...)
method.Implementations MUST store events, without blocking the application, only if the
ResourceEventStore.isStoringEventsOf(Optional)
method returnstrue
, for each of the givenevent seeds
, and must keep them hidden from the TRS feed up to theTrsStore.synchronizeResourceEvents(int)
method is called.This method is intended to avoid raising
TrsStoreException
, if something went wrong preventing the storage of the event, implementations mustcorrupt
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, aConsumer
to get notified of events. Implementation is advised to use aBufferedConsumer
for optimal performance.- Specified by:
store
in interfaceResourceEventStore
- Parameters:
eventsProvider
- a function that provides access to change events to become part of thetrs:ChangeLog
.- See Also:
BufferedConsumer
,ResourceEventStore.store(ResourceEvent...)
-
deleteResourcesOf
public void deleteResourcesOf(String projectId)
Description copied from interface:ResourceEventStore
CreatesResourceEvent.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 returnstrue
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, theisStoringEventsOf(Optional)
method could returnfalse
for some events. If implementations decide to do not call theisStoringEventsOf(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 theTrsStore.synchronizeResourceEvents(int)
method is called.This method is intended to avoid raising
TrsStoreException
, if something went wrong preventing the storage of the event, implementations mustcorrupt
the storage silently.- Specified by:
deleteResourcesOf
in interfaceResourceEventStore
- Parameters:
projectId
- the project identifier of the resources to un-expose.
-
deleteResources
public void deleteResources(Function<Consumer<ResourceSeed>,?> seedsProvider) throws TrsStoreException
Description copied from interface:TrsStore
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.- Specified by:
deleteResources
in interfaceTrsStore
- Parameters:
seedsProvider
- a function that provides access to resource seeds to become part of thetrs:ChangeLog
.- Throws:
TrsStoreException
- if a TRS store error occurs.
-
store
protected abstract void store(Function<Consumer<ResourceEvent>,?> eventsProvider, int bufferSize, boolean assertStoring)
Stores the provided events using aBufferedConsumer
of the given size and indicating whether to call theisStoringEventsOf(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 mustcorrupt
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 aConsumer
to get notified of events. Implementation is advised to use aBufferedConsumer
for optimal performance.- Parameters:
eventsProvider
- the events provider.bufferSize
- the size for theBufferedConsumer
.assertStoring
- whether or not to call theisStoringEventsOf(Optional)
method for each event seed.
-
-