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 SummaryFields 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 SummaryConstructors Modifier Constructor Description protectedBarbelHistoBuilder()
 - 
Method SummaryModifier 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- 
SYSTEMpublic static final String SYSTEM - See Also:
- Constant Field Values
 
 - 
SYSTEMACTIVITYpublic static final String SYSTEMACTIVITY - See Also:
- Constant Field Values
 
 - 
CLOCKpublic static final Systemclock CLOCK 
 - 
DATE_FORMATTERpublic static final DateTimeFormatter DATE_FORMATTER 
 - 
ZDT_DESERIALIZERpublic static final com.google.gson.JsonDeserializer<ZonedDateTime> ZDT_DESERIALIZER 
 - 
ZDT_SERIALIZERpublic static final com.google.gson.JsonSerializer<ZonedDateTime> ZDT_SERIALIZER 
 
- 
 - 
Method Detail- 
barbelpublic static BarbelHistoBuilder barbel() 
 - 
buildpublic <T> BarbelHisto<T> build() 
 - 
getBackbonepublic <T> com.googlecode.cqengine.IndexedCollection<T> getBackbone() - Specified by:
- getBackbonein interface- BarbelHistoContext
 
 - 
setBackboneprotected void setBackbone(com.googlecode.cqengine.IndexedCollection<?> backbone) 
 - 
postSynchronousEventpublic void postSynchronousEvent(HistoEvent event) Post an event into thesynchronousEventBus.- Specified by:
- postSynchronousEventin interface- BarbelHistoContext
- Parameters:
- event- the event posted
 
 - 
postAsynchronousEventpublic void postAsynchronousEvent(HistoEvent event) Post an async event into theasynchronousEventBus.- Specified by:
- postAsynchronousEventin interface- BarbelHistoContext
- Parameters:
- event- the event posted
 
 - 
getAsynchronousEventBuspublic com.google.common.eventbus.AsyncEventBus getAsynchronousEventBus() - Specified by:
- getAsynchronousEventBusin interface- BarbelHistoContext
 
 - 
withAsynchronousEventBuspublic BarbelHistoBuilder withAsynchronousEventBus(com.google.common.eventbus.AsyncEventBus asynchronousEventBus) Register custom Google GuavaAsyncEventBuswithBarbelHisto. SeeEventTypefor various events that clients can subscribe to.- Parameters:
- asynchronousEventBus- the- AsyncEventBus
- Returns:
- the builder again
 
 - 
getSynchronousEventBuspublic com.google.common.eventbus.EventBus getSynchronousEventBus() - Specified by:
- getSynchronousEventBusin interface- BarbelHistoContext
 
 - 
withSynchronousEventBuspublic BarbelHistoBuilder withSynchronousEventBus(com.google.common.eventbus.EventBus synchronousEventBus) Register custom Google Guava synchronousEventBuswithBarbelHisto. SeeEventTypefor various events that clients can subscribe to.- Parameters:
- synchronousEventBus- the- AsyncEventBus
- Returns:
- the builder again
 
 - 
withSynchronousEventListenerpublic 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
 
 - 
withAsynchronousEventListenerpublic 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
 
 - 
getContextOptionspublic Map<String,Object> getContextOptions() - Specified by:
- getContextOptionsin interface- BarbelHistoContext
 
 - 
withContextOptionspublic BarbelHistoBuilder withContextOptions(Map<String,Object> contextOptions) Allows to pass custom options to custom implementations of functions.- Parameters:
- contextOptions- the options map
- Returns:
- the builder
 
 - 
getPrettyPrinterpublic Function<List<Bitemporal>,String> getPrettyPrinter() - Specified by:
- getPrettyPrinterin interface- BarbelHistoContext
 
 - 
withPrettyPrinterpublic BarbelHistoBuilder withPrettyPrinter(Function<List<Bitemporal>,String> prettyPrinter) Register custom pretty printer forDocumentJournals.- Parameters:
- prettyPrinter- the custom printer
- Returns:
- the builder again
 
 - 
getModepublic BarbelMode getMode() - Specified by:
- getModein interface- BarbelHistoContext
 
 - 
withModepublic BarbelHistoBuilder withMode(BarbelMode mode) Set theBarbelModeof thisBarbelHistoinstance. Default isBarbelMode.POJO. SeeBarbelHistofor more details on modes.- Parameters:
- mode- the mode
- Returns:
- the builder again
 
 - 
getJournalUpdateStrategyProducerpublic Function<BarbelHistoContext,BiConsumer<DocumentJournal,Bitemporal>> getJournalUpdateStrategyProducer() - Specified by:
- getJournalUpdateStrategyProducerin interface- BarbelHistoContext
 
 - 
withJournalUpdateStrategyProducerpublic 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
 
 - 
getPojoCopyFunctionSupplierpublic Supplier<UnaryOperator<Object>> getPojoCopyFunctionSupplier() - Specified by:
- getPojoCopyFunctionSupplierin interface- BarbelHistoContext
 
 - 
withPojoCopyFunctionSupplierpublic 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
 
 - 
getGsonpublic com.google.gson.Gson getGson() - Specified by:
- getGsonin interface- BarbelHistoContext
 
 - 
withGsonpublic BarbelHistoBuilder withGson(com.google.gson.Gson gson) Define a customGsonfor use withBarbelHisto. Clients may have specific requirements here.- Parameters:
- gson- the custom- Gson
- Returns:
- the builder again
 
 - 
getPojoProxyingFunctionSupplierpublic Supplier<BiFunction<Object,BitemporalStamp,Object>> getPojoProxyingFunctionSupplier() - Specified by:
- getPojoProxyingFunctionSupplierin interface- BarbelHistoContext
 
 - 
withPojoProxyingFunctionSupplierpublic 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
 
 - 
getJournalStorepublic Map<Object,DocumentJournal> getJournalStore() - Specified by:
- getJournalStorein interface- BarbelHistoContext
 
 - 
withJournalStorepublic 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
 
 - 
getBackboneSupplierpublic <T> Supplier<com.googlecode.cqengine.IndexedCollection<T>> getBackboneSupplier() - Specified by:
- getBackboneSupplierin interface- BarbelHistoContext
 
 - 
withBackboneSupplierpublic <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
 
 - 
getVersionIdGeneratorpublic Supplier<String> getVersionIdGenerator() - Specified by:
- getVersionIdGeneratorin interface- BarbelHistoContext
 
 - 
withVersionIdGeneratorpublic 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
 
 - 
getActivitypublic String getActivity() - Specified by:
- getActivityin interface- BarbelHistoContext
 
 - 
withActivitypublic 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
 
 - 
withUserpublic 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
 
 - 
getUserpublic String getUser() - Specified by:
- getUserin interface- BarbelHistoContext
 
 - 
getPersistenceSerializerProducerpublic Function<BarbelHistoContext,com.googlecode.cqengine.persistence.support.serialization.PojoSerializer<Bitemporal>> getPersistenceSerializerProducer() - Specified by:
- getPersistenceSerializerProducerin interface- BarbelHistoContext
 
 - 
withPersistenceSerializerProducerpublic 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
 
 
- 
 
-