Search in sources :

Example 1 with RuleBasePartitionId

use of org.drools.core.common.RuleBasePartitionId in project drools by kiegroup.

the class FactHandleMarshallingTest method createEventFactHandle.

private InternalFactHandle createEventFactHandle(StatefulKnowledgeSessionImpl wm, InternalKnowledgeBase kBase) {
    // EntryPointNode
    Rete rete = kBase.getRete();
    NodeFactory nFacotry = CoreComponentFactory.get().getNodeFactoryService();
    RuleBasePartitionId partionId = RuleBasePartitionId.MAIN_PARTITION;
    EntryPointNode entryPointNode = nFacotry.buildEntryPointNode(1, partionId, false, rete, EntryPointId.DEFAULT);
    WorkingMemoryEntryPoint wmEntryPoint = new NamedEntryPoint(EntryPointId.DEFAULT, entryPointNode, wm);
    EventFactHandle factHandle = new EventFactHandle(1, new Person(), 0, (new Date()).getTime(), 0, wmEntryPoint);
    return factHandle;
}
Also used : EntryPointNode(org.drools.core.reteoo.EntryPointNode) Rete(org.drools.core.reteoo.Rete) NodeFactory(org.drools.core.reteoo.builder.NodeFactory) RuleBasePartitionId(org.drools.core.common.RuleBasePartitionId) NamedEntryPoint(org.drools.kiesession.entrypoints.NamedEntryPoint) EventFactHandle(org.drools.core.common.EventFactHandle) WorkingMemoryEntryPoint(org.drools.core.WorkingMemoryEntryPoint) Person(org.drools.mvel.compiler.Person) Date(java.util.Date)

Example 2 with RuleBasePartitionId

use of org.drools.core.common.RuleBasePartitionId in project drools by kiegroup.

the class FactHandleMarshallingTest method createEventFactHandle.

private InternalFactHandle createEventFactHandle(StatefulKnowledgeSessionImpl wm, InternalKnowledgeBase kBase) {
    // EntryPointNode
    Rete rete = kBase.getRete();
    NodeFactory nFacotry = kBase.getConfiguration().getComponentFactory().getNodeFactoryService();
    RuleBasePartitionId partionId = RuleBasePartitionId.MAIN_PARTITION;
    EntryPointNode entryPointNode = nFacotry.buildEntryPointNode(1, partionId, false, (ObjectSource) rete, EntryPointId.DEFAULT);
    WorkingMemoryEntryPoint wmEntryPoint = new NamedEntryPoint(EntryPointId.DEFAULT, entryPointNode, wm);
    EventFactHandle factHandle = new EventFactHandle(1, (Object) new Person(), 0, (new Date()).getTime(), 0, wmEntryPoint);
    return factHandle;
}
Also used : EntryPointNode(org.drools.core.reteoo.EntryPointNode) Rete(org.drools.core.reteoo.Rete) NodeFactory(org.drools.core.reteoo.builder.NodeFactory) RuleBasePartitionId(org.drools.core.common.RuleBasePartitionId) NamedEntryPoint(org.drools.core.common.NamedEntryPoint) EventFactHandle(org.drools.core.common.EventFactHandle) WorkingMemoryEntryPoint(org.drools.core.WorkingMemoryEntryPoint) Person(org.drools.compiler.Person) Date(java.util.Date)

Example 3 with RuleBasePartitionId

use of org.drools.core.common.RuleBasePartitionId in project drools by kiegroup.

the class BuildUtils method attachNode.

/**
 * Attaches a node into the network. If a node already exists that could
 * substitute, it is used instead.
 *
 * @param context
 *            The current build context
 * @param candidate
 *            The node to attach.
 *
 * @return the actual attached node that may be the one given as parameter
 *         or eventually one that was already in the cache if sharing is enabled
 */
public <T extends BaseNode> T attachNode(BuildContext context, T candidate) {
    BaseNode node = null;
    RuleBasePartitionId partition = null;
    if (candidate.getType() == NodeTypeEnums.EntryPointNode) {
        // entry point nodes are always shared
        node = context.getRuleBase().getRete().getEntryPointNode(((EntryPointNode) candidate).getEntryPoint());
        // all EntryPointNodes belong to the main partition
        partition = RuleBasePartitionId.MAIN_PARTITION;
    } else if (candidate.getType() == NodeTypeEnums.ObjectTypeNode) {
        // object type nodes are always shared
        Map<ObjectType, ObjectTypeNode> map = context.getRuleBase().getRete().getObjectTypeNodes(context.getCurrentEntryPoint());
        if (map != null) {
            ObjectTypeNode otn = map.get(((ObjectTypeNode) candidate).getObjectType());
            if (otn != null) {
                // adjusting expiration offset
                otn.mergeExpirationOffset((ObjectTypeNode) candidate);
                node = otn;
            }
        }
        // all ObjectTypeNodes belong to the main partition
        partition = RuleBasePartitionId.MAIN_PARTITION;
    } else if (isSharingEnabledForNode(context, candidate)) {
        if ((context.getTupleSource() != null) && NodeTypeEnums.isLeftTupleSink(candidate)) {
            node = context.getTupleSource().getSinkPropagator().getMatchingNode(candidate);
        } else if ((context.getObjectSource() != null) && NodeTypeEnums.isObjectSink(candidate)) {
            node = context.getObjectSource().getObjectSinkPropagator().getMatchingNode(candidate);
        } else {
            throw new RuntimeException("This is a bug on node sharing verification. Please report to development team.");
        }
    }
    if (node != null && !areNodesCompatibleForSharing(context, node)) {
        node = null;
    }
    if (node == null) {
        // only attach() if it is a new node
        node = candidate;
        // new node, so it must be labeled
        if (partition == null) {
            // if it does not has a predefined label
            if (context.getPartitionId() == null) {
                // if no label in current context, create one
                context.setPartitionId(context.getRuleBase().createNewPartitionId());
            }
            partition = context.getPartitionId();
        }
        // set node whit the actual partition label
        node.setPartitionId(context, partition);
        node.attach(context);
    } else {
        // shared node found
        mergeNodes(node, candidate);
        // undo previous id assignment
        context.releaseId(candidate);
        if (partition == null && context.getPartitionId() == null) {
            partition = node.getPartitionId();
            // if no label in current context, create one
            context.setPartitionId(partition);
        }
    }
    // adds the node to the context list to track all added nodes
    context.getNodes().add(node);
    node.addAssociation(context, context.getRule());
    return (T) node;
}
Also used : EntryPointNode(org.drools.core.reteoo.EntryPointNode) RuleBasePartitionId(org.drools.core.common.RuleBasePartitionId) BaseNode(org.drools.core.common.BaseNode) ObjectTypeNode(org.drools.core.reteoo.ObjectTypeNode) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

RuleBasePartitionId (org.drools.core.common.RuleBasePartitionId)3 EntryPointNode (org.drools.core.reteoo.EntryPointNode)3 Date (java.util.Date)2 WorkingMemoryEntryPoint (org.drools.core.WorkingMemoryEntryPoint)2 EventFactHandle (org.drools.core.common.EventFactHandle)2 Rete (org.drools.core.reteoo.Rete)2 NodeFactory (org.drools.core.reteoo.builder.NodeFactory)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Person (org.drools.compiler.Person)1 BaseNode (org.drools.core.common.BaseNode)1 NamedEntryPoint (org.drools.core.common.NamedEntryPoint)1 ObjectTypeNode (org.drools.core.reteoo.ObjectTypeNode)1 NamedEntryPoint (org.drools.kiesession.entrypoints.NamedEntryPoint)1 Person (org.drools.mvel.compiler.Person)1