public override void compileFirstJoin(ICondition condition, Rule.IRule rule) { ObjectCondition cond = (ObjectCondition)condition; ObjectTypeNode otn = ruleCompiler.findObjectTypeNode(cond.TemplateName); // the LeftInputAdapterNode is the first node to propogate to // the first joinNode of the rule LIANode node = new LIANode(ruleCompiler.Engine.nextNodeId()); // if the condition doesn't have any nodes, we want to Add it to // the objectType node if one doesn't already exist. // otherwise we Add it to the last AlphaNode if (cond.Nodes.Count == 0) { // try to find the existing LIANode for the given ObjectTypeNode // if we don't do this, we end up with multiple LIANodes // descending directly from the ObjectTypeNode LIANode existingLIANode = ruleCompiler.findLIANode(otn); if (existingLIANode == null) { otn.addSuccessorNode(node, ruleCompiler.Engine, ruleCompiler.Memory); cond.addNode(node); } else { existingLIANode.incrementUseCount(); cond.addNode(existingLIANode); } } else { // Add the LeftInputAdapterNode to the last alphaNode // In the case of node sharing, the LIANode could be the last // alphaNode, so we have to check and only Add the node to // the condition if it isn't a LIANode BaseAlpha old = (BaseAlpha)cond.LastNode; //if the last node of condition has a LIANode successor, //the LIANode should be shared with the new CE followed by another CE. // Houzhanbin,10/16/2007 BaseNode[] successors = (BaseNode[])old.SuccessorNodes; for (int i = 0; i < successors.Length; i++) { if (successors[i] is LIANode) { cond.addNode(successors[i]); return; } } if (!(old is LIANode)) { old.addSuccessorNode(node, ruleCompiler.Engine, ruleCompiler.Memory); cond.addNode(node); } } }
/// <summary> /// For now just attach the node and don't bother with node sharing /// </summary> /// <param name="existing">- an existing node in the network. it may be /// an ObjectTypeNode or AlphaNode</param> /// <param name="alpha">The alpha.</param> /// <param name="cond">The cond.</param> protected internal virtual void attachAlphaNode(BaseAlpha existing, BaseAlpha alpha, ICondition cond) { if (alpha != null) { try { BaseAlpha share = null; share = shareAlphaNode(existing, alpha); if (share == null) { existing.addSuccessorNode(alpha, ruleCompiler.Engine, ruleCompiler.Memory); // if the node isn't shared, we Add the node to the Condition // object the node belongs to. cond.addNewAlphaNodes(alpha); } else if (existing != alpha) { // the node is shared, so instead of adding the new node, // we Add the existing node share.incrementUseCount(); cond.addNode(share); ruleCompiler.Memory.removeAlphaMemory(alpha); if (alpha.successorCount() == 1 && alpha.SuccessorNodes[0] is BaseAlpha) { // Get the Current node from the new AlphaNode BaseAlpha nnext = (BaseAlpha)alpha.SuccessorNodes[0]; attachAlphaNode(share, nnext, cond); } } } catch (AssertException e) { // send an event with the correct error CompileMessageEventArgs ce = new CompileMessageEventArgs(this, EventType.ADD_NODE_ERROR); ce.Message = alpha.toPPString(); ruleCompiler.notifyListener(ce); } } }
/// <summary> /// For now just attach the node and don't bother with node sharing /// </summary> /// <param name="existing">- an existing node in the network. it may be /// an ObjectTypeNode or AlphaNode</param> /// <param name="alpha">The alpha.</param> /// <param name="cond">The cond.</param> protected internal virtual void attachAlphaNode(BaseAlpha existing, BaseAlpha alpha, ICondition cond) { if (alpha != null) { try { BaseAlpha share = null; share = shareAlphaNode(existing, alpha); if (share == null) { existing.addSuccessorNode(alpha, ruleCompiler.Engine, ruleCompiler.Memory); // if the node isn't shared, we Add the node to the Condition // object the node belongs to. cond.addNewAlphaNodes(alpha); } else if (existing != alpha) { // the node is shared, so instead of adding the new node, // we Add the existing node share.incrementUseCount(); cond.addNode(share); ruleCompiler.Memory.removeAlphaMemory(alpha); if (alpha.successorCount() == 1 && alpha.SuccessorNodes[0] is BaseAlpha) { // Get the Current node from the new AlphaNode BaseAlpha nnext = (BaseAlpha) alpha.SuccessorNodes[0]; attachAlphaNode(share, nnext, cond); } } } catch (AssertException e) { // send an event with the correct error CompileMessageEventArgs ce = new CompileMessageEventArgs(this, EventType.ADD_NODE_ERROR); ce.Message = alpha.toPPString(); ruleCompiler.notifyListener(ce); } } }