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 ofBarbelHistoif required. Defaults are defined inBarbelHistoContext.- Author:
- Niklas Schlimm
-
-
Field Summary
Fields Modifier and Type Field Description static SystemclockCLOCKstatic DateTimeFormatterDATE_FORMATTERstatic StringSYSTEMstatic StringSYSTEMACTIVITYstatic com.google.gson.JsonDeserializer<ZonedDateTime>ZDT_DESERIALIZERstatic com.google.gson.JsonSerializer<ZonedDateTime>ZDT_SERIALIZER
-
Constructor Summary
Constructors Modifier Constructor Description protectedBarbelHistoBuilder()
-
Method Summary
Modifier and Type Method Description static BarbelHistoBuilderbarbel()<T> BarbelHisto<T>build()StringgetActivity()com.google.common.eventbus.AsyncEventBusgetAsynchronousEventBus()<T> com.googlecode.cqengine.IndexedCollection<T>getBackbone()<T> Supplier<com.googlecode.cqengine.IndexedCollection<T>>getBackboneSupplier()Map<String,Object>getContextOptions()com.google.gson.GsongetGson()Map<Object,DocumentJournal>getJournalStore()Function<BarbelHistoContext,BiConsumer<DocumentJournal,Bitemporal>>getJournalUpdateStrategyProducer()BarbelModegetMode()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.EventBusgetSynchronousEventBus()StringgetUser()Supplier<String>getVersionIdGenerator()voidpostAsynchronousEvent(HistoEvent event)Post an async event into theasynchronousEventBus.voidpostSynchronousEvent(HistoEvent event)Post an event into thesynchronousEventBus.protected voidsetBackbone(com.googlecode.cqengine.IndexedCollection<?> backbone)BarbelHistoBuilderwithActivity(String activity)The activity stored when creating records.BarbelHistoBuilderwithAsynchronousEventBus(com.google.common.eventbus.AsyncEventBus asynchronousEventBus)Register custom Google GuavaAsyncEventBuswithBarbelHisto.BarbelHistoBuilderwithAsynchronousEventListener(Object listener)Add a synchronous event listener to theAsyncEventBus.<T> BarbelHistoBuilderwithBackboneSupplier(Supplier<com.googlecode.cqengine.IndexedCollection<T>> backbone)The backbone collection ofBarbelHisto.BarbelHistoBuilderwithContextOptions(Map<String,Object> contextOptions)Allows to pass custom options to custom implementations of functions.BarbelHistoBuilderwithGson(com.google.gson.Gson gson)Define a customGsonfor use withBarbelHisto.BarbelHistoBuilderwithJournalStore(Map<Object,DocumentJournal> journalStore)Define the collection that storesDocumentJournalinstances.BarbelHistoBuilderwithJournalUpdateStrategyProducer(Function<BarbelHistoContext,BiConsumer<DocumentJournal,Bitemporal>> journalUpdateStrategy)Set the strategy how to update a journal.BarbelHistoBuilderwithMode(BarbelMode mode)Set theBarbelModeof thisBarbelHistoinstance.BarbelHistoBuilderwithPersistenceSerializerProducer(Function<BarbelHistoContext,com.googlecode.cqengine.persistence.support.serialization.PojoSerializer<Bitemporal>> persistenceSerializerProducer)Clients may want to decide how data is serialized into persistent storage.BarbelHistoBuilderwithPojoCopyFunctionSupplier(Supplier<UnaryOperator<Object>> pojoCopyFunction)Set a custom POJO copy function.BarbelHistoBuilderwithPojoProxyingFunctionSupplier(Supplier<BiFunction<Object,BitemporalStamp,Object>> proxyingFunction)Customize the proxying inBarbelMode.POJO.BarbelHistoBuilderwithPrettyPrinter(Function<List<Bitemporal>,String> prettyPrinter)Register custom pretty printer forDocumentJournals.BarbelHistoBuilderwithSynchronousEventBus(com.google.common.eventbus.EventBus synchronousEventBus)Register custom Google Guava synchronousEventBuswithBarbelHisto.BarbelHistoBuilderwithSynchronousEventListener(Object listener)Add a synchronous event listener to theEventBus.BarbelHistoBuilderwithUser(String user)The user stored when creating records.BarbelHistoBuilderwithVersionIdGenerator(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:
getBackbonein interfaceBarbelHistoContext
-
setBackbone
protected void setBackbone(com.googlecode.cqengine.IndexedCollection<?> backbone)
-
postSynchronousEvent
public void postSynchronousEvent(HistoEvent event)
Post an event into thesynchronousEventBus.- Specified by:
postSynchronousEventin interfaceBarbelHistoContext- Parameters:
event- the event posted
-
postAsynchronousEvent
public void postAsynchronousEvent(HistoEvent event)
Post an async event into theasynchronousEventBus.- Specified by:
postAsynchronousEventin interfaceBarbelHistoContext- Parameters:
event- the event posted
-
getAsynchronousEventBus
public com.google.common.eventbus.AsyncEventBus getAsynchronousEventBus()
- Specified by:
getAsynchronousEventBusin interfaceBarbelHistoContext
-
withAsynchronousEventBus
public BarbelHistoBuilder withAsynchronousEventBus(com.google.common.eventbus.AsyncEventBus asynchronousEventBus)
Register custom Google GuavaAsyncEventBuswithBarbelHisto. SeeEventTypefor various events that clients can subscribe to.- Parameters:
asynchronousEventBus- theAsyncEventBus- Returns:
- the builder again
-
getSynchronousEventBus
public com.google.common.eventbus.EventBus getSynchronousEventBus()
- Specified by:
getSynchronousEventBusin interfaceBarbelHistoContext
-
withSynchronousEventBus
public BarbelHistoBuilder withSynchronousEventBus(com.google.common.eventbus.EventBus synchronousEventBus)
Register custom Google Guava synchronousEventBuswithBarbelHisto. SeeEventTypefor 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@Subscribepublic void handleEvent(AquireLockEvent event) { // handle the event } }withSynchronousEventListener(Object)method.BarbelHistowill publish events to the handler. For events available inBarbelHistoseeEventType.
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@Subscribepublic void handleEvent(AquireLockEvent event) { // handle the event } }withAsynchronousEventBus(AsyncEventBus)method.BarbelHistowill the publich the event to the handler. For events available inBarbelHistoseeEventType.
- Parameters:
listener- the listener to register- Returns:
- the builder again
-
getContextOptions
public Map<String,Object> getContextOptions()
- Specified by:
getContextOptionsin 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:
getPrettyPrinterin interfaceBarbelHistoContext
-
withPrettyPrinter
public BarbelHistoBuilder withPrettyPrinter(Function<List<Bitemporal>,String> prettyPrinter)
Register custom pretty printer forDocumentJournals.- Parameters:
prettyPrinter- the custom printer- Returns:
- the builder again
-
getMode
public BarbelMode getMode()
- Specified by:
getModein interfaceBarbelHistoContext
-
withMode
public BarbelHistoBuilder withMode(BarbelMode mode)
Set theBarbelModeof thisBarbelHistoinstance. Default isBarbelMode.POJO. SeeBarbelHistofor more details on modes.- Parameters:
mode- the mode- Returns:
- the builder again
-
getJournalUpdateStrategyProducer
public Function<BarbelHistoContext,BiConsumer<DocumentJournal,Bitemporal>> getJournalUpdateStrategyProducer()
- Specified by:
getJournalUpdateStrategyProducerin 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:
getPojoCopyFunctionSupplierin 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:
getGsonin interfaceBarbelHistoContext
-
withGson
public BarbelHistoBuilder withGson(com.google.gson.Gson gson)
Define a customGsonfor 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:
getPojoProxyingFunctionSupplierin interfaceBarbelHistoContext
-
withPojoProxyingFunctionSupplier
public BarbelHistoBuilder withPojoProxyingFunctionSupplier(Supplier<BiFunction<Object,BitemporalStamp,Object>> proxyingFunction)
Customize the proxying inBarbelMode.POJO. Default isCachingCGLibProxyingFunction. 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:
getJournalStorein interfaceBarbelHistoContext
-
withJournalStore
public BarbelHistoBuilder withJournalStore(Map<Object,DocumentJournal> journalStore)
Define the collection that storesDocumentJournalinstances. Note thatDocumentJournalalways 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:
getBackboneSupplierin 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 anyIndexedCollectionof cqengine. SeePersistence, i.e.DiskPersistenceandOffHeapPersistencefor flavors of different persistence options here. Default istConcurrentIndexedCollectionusingOnHeapPersistence.
If clients decide to useDiskPersistenceorOffHeapPersistenceinBarbelMode.POJOthey need to add thePersistenceConfigannotation additionally to their POJO classes.
This is always required if you not use the@PersistenceConfig(serializer=BarbelPojoSerializer.class, polymorphic=true)OnHeapPersistenceand regardless of the de-facto serializer you choose inwithPersistenceSerializerProducer(Function). TheBarbelPojoSerializerwill forward processing to theAdaptingKryoSerializerby default. If you define a different target serializer,BarbelPojoSerializerwill be forward requests to that custom serializer.
The backbone collection should not be shared across multiple instances ofBarbelHisto. If you use persistent collections, store theBarbelHistoinstance as singleton bean to your application. Multiple threads are allowed to access thatBarbelHistoinstance.- 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:
getVersionIdGeneratorin 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:
getActivityin 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:
getUserin interfaceBarbelHistoContext
-
getPersistenceSerializerProducer
public Function<BarbelHistoContext,com.googlecode.cqengine.persistence.support.serialization.PojoSerializer<Bitemporal>> getPersistenceSerializerProducer()
- Specified by:
getPersistenceSerializerProducerin 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
-
-