Package org.projectbarbel.histo
Class BarbelHistoBuilder
- java.lang.Object
-
- org.projectbarbel.histo.BarbelHistoBuilder
-
- All Implemented Interfaces:
BarbelHistoContext
public final class BarbelHistoBuilder extends Object implements BarbelHistoContext
Builder class forBarbelHisto
. UseBarbelHistoBuilder.barbel().build()
to receive the default implementation. Allows to set a variety of context objects to adopt the behaviour ofBarbelHisto
if required. Defaults are defined inBarbelHistoContext
.- Author:
- Niklas Schlimm
-
-
Field Summary
Fields Modifier and Type Field Description static Systemclock
CLOCK
static DateTimeFormatter
DATE_FORMATTER
static String
SYSTEM
static String
SYSTEMACTIVITY
static com.google.gson.JsonDeserializer<ZonedDateTime>
ZDT_DESERIALIZER
static com.google.gson.JsonSerializer<ZonedDateTime>
ZDT_SERIALIZER
-
Constructor Summary
Constructors Modifier Constructor Description protected
BarbelHistoBuilder()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static BarbelHistoBuilder
barbel()
<T> BarbelHisto<T>
build()
String
getActivity()
com.google.common.eventbus.AsyncEventBus
getAsynchronousEventBus()
<T> com.googlecode.cqengine.IndexedCollection<T>
getBackbone()
<T> Supplier<com.googlecode.cqengine.IndexedCollection<T>>
getBackboneSupplier()
Map<String,Object>
getContextOptions()
com.google.gson.Gson
getGson()
Map<Object,DocumentJournal>
getJournalStore()
Function<BarbelHistoContext,BiConsumer<DocumentJournal,Bitemporal>>
getJournalUpdateStrategyProducer()
BarbelMode
getMode()
Function<BarbelHistoContext,com.googlecode.cqengine.persistence.support.serialization.PojoSerializer<Bitemporal>>
getPersistenceSerializerProducer()
Supplier<UnaryOperator<Object>>
getPojoCopyFunctionSupplier()
Supplier<BiFunction<Object,BitemporalStamp,Object>>
getPojoProxyingFunctionSupplier()
Function<List<Bitemporal>,String>
getPrettyPrinter()
com.google.common.eventbus.EventBus
getSynchronousEventBus()
String
getUser()
Supplier<String>
getVersionIdGenerator()
void
postAsynchronousEvent(HistoEvent event)
Post an async event into theasynchronousEventBus
.void
postSynchronousEvent(HistoEvent event)
Post an event into thesynchronousEventBus
.protected void
setBackbone(com.googlecode.cqengine.IndexedCollection<?> backbone)
BarbelHistoBuilder
withActivity(String activity)
The activity stored when creating records.BarbelHistoBuilder
withAsynchronousEventBus(com.google.common.eventbus.AsyncEventBus asynchronousEventBus)
Register custom Google GuavaAsyncEventBus
withBarbelHisto
.BarbelHistoBuilder
withAsynchronousEventListener(Object listener)
Add a synchronous event listener to theAsyncEventBus
.<T> BarbelHistoBuilder
withBackboneSupplier(Supplier<com.googlecode.cqengine.IndexedCollection<T>> backbone)
The backbone collection ofBarbelHisto
.BarbelHistoBuilder
withContextOptions(Map<String,Object> contextOptions)
Allows to pass custom options to custom implementations of functions.BarbelHistoBuilder
withGson(com.google.gson.Gson gson)
Define a customGson
for use withBarbelHisto
.BarbelHistoBuilder
withJournalStore(Map<Object,DocumentJournal> journalStore)
Define the collection that storesDocumentJournal
instances.BarbelHistoBuilder
withJournalUpdateStrategyProducer(Function<BarbelHistoContext,BiConsumer<DocumentJournal,Bitemporal>> journalUpdateStrategy)
Set the strategy how to update a journal.BarbelHistoBuilder
withMode(BarbelMode mode)
Set theBarbelMode
of thisBarbelHisto
instance.BarbelHistoBuilder
withPersistenceSerializerProducer(Function<BarbelHistoContext,com.googlecode.cqengine.persistence.support.serialization.PojoSerializer<Bitemporal>> persistenceSerializerProducer)
Clients may want to decide how data is serialized into persistent storage.BarbelHistoBuilder
withPojoCopyFunctionSupplier(Supplier<UnaryOperator<Object>> pojoCopyFunction)
Set a custom POJO copy function.BarbelHistoBuilder
withPojoProxyingFunctionSupplier(Supplier<BiFunction<Object,BitemporalStamp,Object>> proxyingFunction)
Customize the proxying inBarbelMode.POJO
.BarbelHistoBuilder
withPrettyPrinter(Function<List<Bitemporal>,String> prettyPrinter)
Register custom pretty printer forDocumentJournal
s.BarbelHistoBuilder
withSynchronousEventBus(com.google.common.eventbus.EventBus synchronousEventBus)
Register custom Google Guava synchronousEventBus
withBarbelHisto
.BarbelHistoBuilder
withSynchronousEventListener(Object listener)
Add a synchronous event listener to theEventBus
.BarbelHistoBuilder
withUser(String user)
The user stored when creating records.BarbelHistoBuilder
withVersionIdGenerator(Supplier<String> versionIdGenerator)
Clients may want to implememt their own version id generator.
-
-
-
Field Detail
-
SYSTEM
public static final String SYSTEM
- See Also:
- Constant Field Values
-
SYSTEMACTIVITY
public static final String SYSTEMACTIVITY
- See Also:
- Constant Field Values
-
CLOCK
public static final Systemclock CLOCK
-
DATE_FORMATTER
public static final DateTimeFormatter DATE_FORMATTER
-
ZDT_DESERIALIZER
public static final com.google.gson.JsonDeserializer<ZonedDateTime> ZDT_DESERIALIZER
-
ZDT_SERIALIZER
public static final com.google.gson.JsonSerializer<ZonedDateTime> ZDT_SERIALIZER
-
-
Method Detail
-
barbel
public static BarbelHistoBuilder barbel()
-
build
public <T> BarbelHisto<T> build()
-
getBackbone
public <T> com.googlecode.cqengine.IndexedCollection<T> getBackbone()
- Specified by:
getBackbone
in interfaceBarbelHistoContext
-
setBackbone
protected void setBackbone(com.googlecode.cqengine.IndexedCollection<?> backbone)
-
postSynchronousEvent
public void postSynchronousEvent(HistoEvent event)
Post an event into thesynchronousEventBus
.- Specified by:
postSynchronousEvent
in interfaceBarbelHistoContext
- Parameters:
event
- the event posted
-
postAsynchronousEvent
public void postAsynchronousEvent(HistoEvent event)
Post an async event into theasynchronousEventBus
.- Specified by:
postAsynchronousEvent
in interfaceBarbelHistoContext
- Parameters:
event
- the event posted
-
getAsynchronousEventBus
public com.google.common.eventbus.AsyncEventBus getAsynchronousEventBus()
- Specified by:
getAsynchronousEventBus
in interfaceBarbelHistoContext
-
withAsynchronousEventBus
public BarbelHistoBuilder withAsynchronousEventBus(com.google.common.eventbus.AsyncEventBus asynchronousEventBus)
Register custom Google GuavaAsyncEventBus
withBarbelHisto
. SeeEventType
for various events that clients can subscribe to.- Parameters:
asynchronousEventBus
- theAsyncEventBus
- Returns:
- the builder again
-
getSynchronousEventBus
public com.google.common.eventbus.EventBus getSynchronousEventBus()
- Specified by:
getSynchronousEventBus
in interfaceBarbelHistoContext
-
withSynchronousEventBus
public BarbelHistoBuilder withSynchronousEventBus(com.google.common.eventbus.EventBus synchronousEventBus)
Register custom Google Guava synchronousEventBus
withBarbelHisto
. SeeEventType
for various events that clients can subscribe to.- Parameters:
synchronousEventBus
- theAsyncEventBus
- Returns:
- the builder again
-
withSynchronousEventListener
public BarbelHistoBuilder withSynchronousEventListener(Object listener)
Add a synchronous event listener to theEventBus
. Listeners are implemented like so:public class MyListener {
Then add an instance of this class to the@Subscribe
public void handleEvent(AquireLockEvent event) { // handle the event } }withSynchronousEventListener(Object)
method.BarbelHisto
will publish events to the handler. For events available inBarbelHisto
seeEventType
.
Notice that synchronous event listeners should be fairly quick, cause they are all executed in a row by the executing main thread. Use asynchronous event listeners if you have to perform time consuming event based procedures.- Parameters:
listener
- the listener to register- Returns:
- the builder again
-
withAsynchronousEventListener
public BarbelHistoBuilder withAsynchronousEventListener(Object listener)
Add a synchronous event listener to theAsyncEventBus
. Listeners are implemented like so:public class MyListener {
Then add an instance of this class to the@Subscribe
public void handleEvent(AquireLockEvent event) { // handle the event } }withAsynchronousEventBus(AsyncEventBus)
method.BarbelHisto
will the publich the event to the handler. For events available inBarbelHisto
seeEventType
.
- Parameters:
listener
- the listener to register- Returns:
- the builder again
-
getContextOptions
public Map<String,Object> getContextOptions()
- Specified by:
getContextOptions
in interfaceBarbelHistoContext
-
withContextOptions
public BarbelHistoBuilder withContextOptions(Map<String,Object> contextOptions)
Allows to pass custom options to custom implementations of functions.- Parameters:
contextOptions
- the options map- Returns:
- the builder
-
getPrettyPrinter
public Function<List<Bitemporal>,String> getPrettyPrinter()
- Specified by:
getPrettyPrinter
in interfaceBarbelHistoContext
-
withPrettyPrinter
public BarbelHistoBuilder withPrettyPrinter(Function<List<Bitemporal>,String> prettyPrinter)
Register custom pretty printer forDocumentJournal
s.- Parameters:
prettyPrinter
- the custom printer- Returns:
- the builder again
-
getMode
public BarbelMode getMode()
- Specified by:
getMode
in interfaceBarbelHistoContext
-
withMode
public BarbelHistoBuilder withMode(BarbelMode mode)
Set theBarbelMode
of thisBarbelHisto
instance. Default isBarbelMode.POJO
. SeeBarbelHisto
for more details on modes.- Parameters:
mode
- the mode- Returns:
- the builder again
-
getJournalUpdateStrategyProducer
public Function<BarbelHistoContext,BiConsumer<DocumentJournal,Bitemporal>> getJournalUpdateStrategyProducer()
- Specified by:
getJournalUpdateStrategyProducer
in interfaceBarbelHistoContext
-
withJournalUpdateStrategyProducer
public BarbelHistoBuilder withJournalUpdateStrategyProducer(Function<BarbelHistoContext,BiConsumer<DocumentJournal,Bitemporal>> journalUpdateStrategy)
Set the strategy how to update a journal. Core functionality usually not customized by clients. Default isEmbeddingJournalUpdateStrategy
.- Parameters:
journalUpdateStrategy
- the custom strategy- Returns:
- the builder again
-
getPojoCopyFunctionSupplier
public Supplier<UnaryOperator<Object>> getPojoCopyFunctionSupplier()
- Specified by:
getPojoCopyFunctionSupplier
in interfaceBarbelHistoContext
-
withPojoCopyFunctionSupplier
public BarbelHistoBuilder withPojoCopyFunctionSupplier(Supplier<UnaryOperator<Object>> pojoCopyFunction)
Set a custom POJO copy function. Required if clients use specific POJOs that cannot be copied by the defaultRitsClonerCopyFunction
.- Parameters:
pojoCopyFunction
- the custom copy function- Returns:
- the builder again
-
getGson
public com.google.gson.Gson getGson()
- Specified by:
getGson
in interfaceBarbelHistoContext
-
withGson
public BarbelHistoBuilder withGson(com.google.gson.Gson gson)
Define a customGson
for use withBarbelHisto
. Clients may have specific requirements here.- Parameters:
gson
- the customGson
- Returns:
- the builder again
-
getPojoProxyingFunctionSupplier
public Supplier<BiFunction<Object,BitemporalStamp,Object>> getPojoProxyingFunctionSupplier()
- Specified by:
getPojoProxyingFunctionSupplier
in interfaceBarbelHistoContext
-
withPojoProxyingFunctionSupplier
public BarbelHistoBuilder withPojoProxyingFunctionSupplier(Supplier<BiFunction<Object,BitemporalStamp,Object>> proxyingFunction)
Customize the proxying inBarbelMode.POJO
. Default isCachingByteBuddyProxyingFunction
. Clients may want to use more specific proxying functions with their POJOs.- Parameters:
proxyingFunction
- the custom proxying function- Returns:
- the builder again
-
getJournalStore
public Map<Object,DocumentJournal> getJournalStore()
- Specified by:
getJournalStore
in interfaceBarbelHistoContext
-
withJournalStore
public BarbelHistoBuilder withJournalStore(Map<Object,DocumentJournal> journalStore)
Define the collection that storesDocumentJournal
instances. Note thatDocumentJournal
always works on the backbone collection set inwithBackboneSupplier(Supplier)
and will never "own" data.- Parameters:
journalStore
- the journal store collection- Returns:
- the builder again
-
getBackboneSupplier
public <T> Supplier<com.googlecode.cqengine.IndexedCollection<T>> getBackboneSupplier()
- Specified by:
getBackboneSupplier
in interfaceBarbelHistoContext
-
withBackboneSupplier
public <T> BarbelHistoBuilder withBackboneSupplier(Supplier<com.googlecode.cqengine.IndexedCollection<T>> backbone)
The backbone collection ofBarbelHisto
. This collection actually contains the complete version data. Objects stored here are never exposed directly to clients, only copies are exposed. Adopt that collection to anyIndexedCollection
of cqengine. SeePersistence
, i.e.DiskPersistence
andOffHeapPersistence
for flavors of different persistence options here. Default istConcurrentIndexedCollection
usingOnHeapPersistence
.
If clients decide to useDiskPersistence
orOffHeapPersistence
inBarbelMode.POJO
they need to add thePersistenceConfig
annotation additionally to their POJO classes.
@PersistenceConfig(serializer=BarbelPojoSerializer.class, polymorphic=true)
OnHeapPersistence
and regardless of the de-facto serializer you choose inwithPersistenceSerializerProducer(Function)
. TheBarbelPojoSerializer
will forward processing to theAdaptingKryoSerializer
by default. If you define a different target serializer,BarbelPojoSerializer
will be forward requests to that custom serializer.
The backbone collection should not be shared across multiple instances ofBarbelHisto
. If you use persistent collections, store theBarbelHisto
instance as singleton bean to your application. Multiple threads are allowed to access thatBarbelHisto
instance.- Type Parameters:
T
- the type to manage- Parameters:
backbone
- the collection for the backbone- Returns:
- the builder again
- See Also:
- https://github.com/npgall/cqengine
-
getVersionIdGenerator
public Supplier<String> getVersionIdGenerator()
- Specified by:
getVersionIdGenerator
in interfaceBarbelHistoContext
-
withVersionIdGenerator
public BarbelHistoBuilder withVersionIdGenerator(Supplier<String> versionIdGenerator)
Clients may want to implememt their own version id generator. Make sure it will be unique. Default isUUIDGenerator
.- Parameters:
versionIdGenerator
- the custom version id generator- Returns:
- the builder
-
getActivity
public String getActivity()
- Specified by:
getActivity
in interfaceBarbelHistoContext
-
withActivity
public BarbelHistoBuilder withActivity(String activity)
The activity stored when creating records. Adopt this to process names or the like.- Parameters:
activity
- the activity to store in record entries- Returns:
- the builder again
-
withUser
public BarbelHistoBuilder withUser(String user)
The user stored when creating records. Adopt this to user names or the like.- Parameters:
user
- the user to store in record entries- Returns:
- the builder again
-
getUser
public String getUser()
- Specified by:
getUser
in interfaceBarbelHistoContext
-
getPersistenceSerializerProducer
public Function<BarbelHistoContext,com.googlecode.cqengine.persistence.support.serialization.PojoSerializer<Bitemporal>> getPersistenceSerializerProducer()
- Specified by:
getPersistenceSerializerProducer
in interfaceBarbelHistoContext
-
withPersistenceSerializerProducer
public BarbelHistoBuilder withPersistenceSerializerProducer(Function<BarbelHistoContext,com.googlecode.cqengine.persistence.support.serialization.PojoSerializer<Bitemporal>> persistenceSerializerProducer)
Clients may want to decide how data is serialized into persistent storage. Default isAdaptingKryoSerializer
. To validate if your POJO is serializable callAdaptingKryoSerializer.validateObjectIsRoundTripSerializable(BarbelHistoContext, Object)
.- Parameters:
persistenceSerializerProducer
- the producer of the serializer- Returns:
- the builder again
-
-