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 Summary
Modifier and TypeMethodDescriptionvoidclear()Clears the data stored in the memory.voidCommits the changes made in the KeyedFactStorage.Retrieves an iterator over the keys in the memory with the specifiedKeyMode.voidwrite(Collection<FactHandleVersioned> factHandles) This method will be called after the necessary number of keys are provided viawrite(FieldValue).voidwrite(FieldValue partialKey) This method is similar to theJarOutputStream.putNextEntry(ZipEntry).
-
Method Details
-
keys
Retrieves an iterator over the keys in the memory with the specifiedKeyMode.- 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 theKeyedFactStoragewith the specifiedKeyModeandMemoryKey.- Parameters:
mode- the mode in which the values are retrievedkey- 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
This method is similar to the
JarOutputStream.putNextEntry(ZipEntry). However, it expects both sides to know the number of keys to be written until thewrite(Collection)method is called.- Parameters:
partialKey- The next component of the memory key.
-
write
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 towrite(FieldValue).- Parameters:
factHandles- fact handles to save under the sequence of keys
-