Custom State Managers

Custom state managers can be created and added to runners to utilize new data sources, if needed.

Base State Managers

All state managers extend the abstract StateManager class or one of its subclasses.

public class MyStateManager<T> extends StateManager<T>{

  /** 
   * Constructor with provided "alias", event runner which owns the manager
   * as well as all the configurations available to the runner
   */
  public MyStateManager(String name, EventRunner runner, Map<String, String> config) {
    super(name, runner, config);
  }
  
  /** 
   * Function called during initialization of a state manager, typically
   * used to establish connections.
   */
  @Override
  public void configure() throws HotException {
  }
  
  /** 
   * Function called when the runner performs a commit action, typically
   * used to process buffers or commit to external systems.
   */
  @Override
  public void commit() throws HotException {
  }
  
  /** 
   * Function called during termination of a state manager, typically
   * used to close connections with external systems.
   */
  @Override
  public void close() throws IOException {
  }
  
  /**
   * Function called for reading a single record for given id from
   * the state manager and returning selected data fields.
   * Data can be returned in any format preferred by the target
   * system, as convertToAggregate function is called for the output.
   */
  @Override
  public Object getRawValueByID(String ID, String fields[]) throws HotException {  
  }

  /**
   * Function called for reading a list of records for given ids from
   * the state manager and returning selected data fields.
   * Data can be returned in any format preferred by the target
   * system, as convertToAggregate function is called for the output.
   */
  public Stream getRawStreamByID(String[] IDs, String fields[]) throws HotException {
  }

  /**
   * Function called for streaming records from
   * the state manager and returning selected data fields.
   * Data can be returned in any format preferred by the target
   * system, as convertToAggregate function is called for the output.
   * Typically limit and skip are also applied on the returned stream.
   */
   public Stream getRawStream(String fields[]) throws HotException {
   }

  /**
   * Function called for translating target system specific records
   * into aggregates of T type, usually utilizing JSON manipulation
   * or similar conversion techniques.
   */
   public Aggregate<T> convertToAggregate(Object object) throws HotException {
   }

}
circle-info

For optimization purposes, additional state manager functionssuch as getCount() can be also overridden.

circle-info

If the state manager implementation doesn't require a database-side field selection, it can be implemented locally using JsonUtil.keepFields function as well.

State managers can also implement the following optional methods to allow re-establishing connections when there is a disruption:

Writeable State Managers

State managers which are writeable (i.e. can allow changes on their records) extend a WriteableStateManager class, implementing the following functions.

While it is possible to implement a new state manager extending WriteableStateManager class, two specialized subclasses are also provided for simpler implementation.

End State Managers

End state managers keep the latest version of aggregate records after update operations and are the most commonly used types of state managers. Following functions are implemented by these classes:

The following functions are implemented by EndStateManager, but use optimistic locking with separate read & write steps, so state manager implementations that support optimized atomic operations can override them as well:

Journal Store Managers

Journal store managers store impacts applied on aggregate records, providing basis for event sourcing implementations. These managers provide ability to "playback" historical versions of aggregates as well. Following functions are implemented by this type of state manager classes:

Read Functions

Write Functions

circle-info

A special JournalStoreManager subclass also exists (SingleJournalStoreManager), allowing use of any EndStateManager as an event sourcing base, without implementing a custom state manager class.

Special Interfaces

Some state managers implement a list of special interfaces, for performance improvement purposes or additional functionalities.

Bulkable Interface

This interface allows execution of a batch list of update operations all at once on the target system (used when buffer is enabled or write operations include multiple actions).

circle-exclamation

Queryable Interface

This interface allows use of a query manager implementation to perform certain read operations (e.g. query by ids, select fields) in a more optimized manner.

Journalable Interface

This interface allows storing and reading journal records regarding updates applied on a state manager, typically used for translating pulse records to journal records in CDC operations.

Customizable Interface

This interface allows storing and reading custom data elements, which enrich/override aggregate data for specific use cases (e.g. dislaying different content for different customer segments).

ID Generators

ID generators allow automated assignment of unique ID values to new aggregate records on state managers. All ID generators create String IDs and require the following functions:

If an ID generator uses number based IDs (e.g. sequential, random numbers), it can be implemented using NumberGenerator class and used together with NumberIDGenerator instead as well, with the following functions:

circle-info

Parent ID generator classes provide additional functionalities for all their subclasses (e.g. applying prefixes, fillers).

Last updated