Interface KeyedFactStorage


public interface KeyedFactStorage
This interface represents the engine's alpha and beta memories as referenced in the RETE algorithm. Unlike the traditional approach, this engine stores fact handles in these memories instead of the facts themselves. The mapping between fact handles and their corresponding facts is managed by another memory structure, FactStorage.

Effectively, the KeyedFactStorage can be represented as a Map<Object[], Collection<FactHandle>>, where the keys are field values from facts of the same or different types.

The engine maintains as many instances of KeyedFactStorage as there are unique combinations of fields in the rules' conditions. For example, a condition like $customer.id == $invoice.billTo will result in a new KeyedFactStorage being created, with the keys being a sequence of the customer's ID and the invoice's bill-to fields.

As far as write operations are concerned, this storage behaves similarly to JarOutputStream: first, we write the memory's key, and then the fact handles themselves.

  • Method Details

    • keys

      ReIterator<MemoryKey> keys(KeyMode keyMode)
      Retrieves an iterator over the keys in the memory with the specified KeyMode.
      Parameters:
      keyMode - the mode in which the keys are retrieved
      Returns:
      an iterator over the keys in the memory
    • values

      Returns an iterator over the values in the KeyedFactStorage with the specified KeyMode and MemoryKey.
      Parameters:
      mode - the mode in which the values are retrieved
      key - the memory key
      Returns:
      an iterator over the values
    • commitChanges

      void commitChanges()
      Commits the changes made in the KeyedFactStorage.
    • clear

      void clear()
      Clears the data stored in the memory.
    • write

      void write(FieldValue partialKey)

      This method is similar to the JarOutputStream.putNextEntry(ZipEntry). However, it expects both sides to know the number of keys to be written until the write(Collection) method is called.

      Parameters:
      partialKey - The next component of the memory key.
    • write

      void write(Collection<FactHandleVersioned> factHandles)

      This method will be called after the necessary number of keys are provided via write(FieldValue). After the fact handles are provided, the implementation must reset its internal key counter and wait for the next call to write(FieldValue).

      Parameters:
      factHandles - fact handles to save under the sequence of keys