How JBoss RETE works

Rete is implemented as a rooted, acyclic, directed graph, providing an interconnected network of nodes. Its nodes have different uses and significations, and we will refer to them using appropriate names.
The network processes only beans from the working memory.

At the top of the network is the root node, also named ReteNode, where all the facts enter in the network. Next, this facts are classified into some different categories (the ObjectTypeNode), according to their beans names.
ObjectTypeNodes are the inputs nodes of the network, and represent the head of patterns from which is composed the LHS part of a rule. A pattern in JBossRules represents a tuple with some variables.
For example Good and Participant are two ObjectTypeNode nodes.

The tuples that reach the far end of the ReteOO network are the terminal nodes, representing individual rules which are activated into the Agenda.

The network between the input and terminal nodes contains two kind of nodes: 1-input nodes (AlphaNode, LeftInputAdapterNode) and 2-input nodes (BetaNodes, NotNodes, EvalNodes).

An AlphaNode represents an atomic condition like (participantName == "Susan"). The general form is a comparison of an object attribute to a literal value.
A single AlphaNode can have either an ObjectTypeNode or another AlphaNode as a predecessor. AlphaNodes are link together to form a sequence of conditions for the same object type.
For example, (participantName == "Susan") and (price >= 100). AlphaNode can have either an AlphaNode or BetaNode as a successor.
Each AlphaNode has a so called Alpha Memory, which remembers which facts have matched. If a fact matches the condition of the AlphaNode, the node will propagate the fact down the network.

BetaNodes are also called join nodes, because perform joins between groups of one or more tuples, comming from the left input to unique fact comming from the right input.
Each Beta Node has two memories: Alpha Memory (or left memory) and Beta Memory (or right memory). BetaNodes produce groups of two or more facts as its output, as they produce one output for each ordered ordered pairing of a Alpha Memory and a Beta Memory element that passes the tests in that node.
JBossRules treats as a special node the head-Beta Node of the list of Beta Nodes from the ReteOO network: it introduces a specialised LeftInputAdapterNode (LIAN) in order to connect Alpha Memory to the left input of a head-Beta Node.

As an example, we present the code of the following JBoss rules:

 package rulesForAuctionFlow;
 
 import rules.Good;
 import rules.Participant;
 import rules.Negotiation;

 rule "Validity-1"
  when
   Good($good:name)
   Participant(participantName == "Susan", goodName == $good)
  then
   // conclusion
  end
 
 rule "Validity-2"
  when
   Good($good:name)
   Participant(participantName == "Susan", goodName == $good)
   Negotiation()
  then
   // conclusion
  end
 

Node Sharing is an intrinsec optimisation of Rete network, first decribed in the original paper from 1982. JBossRules shares both pattern and join nodes. So, the couple of JBoss Rules presented above, will have, each of them, the following rete-network:

ReteRete