Search in sources :

Example 1 with EntryPointId

use of org.drools.core.rule.EntryPointId in project drools by kiegroup.

the class InputMarshaller method readFactHandle.

public static InternalFactHandle readFactHandle(MarshallerReaderContext context) throws IOException, ClassNotFoundException {
    int type = context.stream.readInt();
    int id = context.stream.readInt();
    long recency = context.stream.readLong();
    long startTimeStamp = 0;
    long duration = 0;
    boolean expired = false;
    long activationsCount = 0;
    if (type == 2) {
        startTimeStamp = context.stream.readLong();
        duration = context.stream.readLong();
        expired = context.stream.readBoolean();
        activationsCount = context.stream.readLong();
    }
    int strategyIndex = context.stream.readInt();
    Object object = null;
    ObjectMarshallingStrategy strategy = null;
    // This is the old way of de/serializing strategy objects
    if (strategyIndex >= 0) {
        strategy = context.resolverStrategyFactory.getStrategy(strategyIndex);
    } else // This is the new way
    if (strategyIndex == -2) {
        String strategyClassName = context.stream.readUTF();
        if (!StringUtils.isEmpty(strategyClassName)) {
            strategy = context.resolverStrategyFactory.getStrategyObject(strategyClassName);
            if (strategy == null) {
                throw new IllegalStateException("No strategy of type " + strategyClassName + " available.");
            }
        }
    }
    // If either way retrieves a strategy, use it
    if (strategy != null) {
        object = strategy.read(context.stream);
    }
    EntryPoint entryPoint = null;
    if (context.readBoolean()) {
        String entryPointId = context.readUTF();
        if (entryPointId != null && !entryPointId.equals("")) {
            entryPoint = ((RuleRuntime) context.wm).getEntryPoint(entryPointId);
        }
    }
    EntryPointId confEP;
    if (entryPoint != null) {
        confEP = ((NamedEntryPoint) entryPoint).getEntryPoint();
    } else {
        confEP = context.wm.getEntryPoint();
    }
    ObjectTypeConf typeConf = context.wm.getObjectTypeConfigurationRegistry().getObjectTypeConf(confEP, object);
    InternalFactHandle handle = null;
    switch(type) {
        case 0:
            {
                handle = new DefaultFactHandle(id, object, recency, (WorkingMemoryEntryPoint) entryPoint, typeConf != null && typeConf.isTrait());
                break;
            }
        case 1:
            {
                handle = new QueryElementFactHandle(object, id, recency);
                break;
            }
        case 2:
            {
                handle = new EventFactHandle(id, object, recency, startTimeStamp, duration, (WorkingMemoryEntryPoint) entryPoint, typeConf != null && typeConf.isTrait());
                ((EventFactHandle) handle).setExpired(expired);
                ((EventFactHandle) handle).setActivationsCount(activationsCount);
                break;
            }
        default:
            {
                throw new IllegalStateException("Unable to marshal FactHandle, as type does not exist:" + type);
            }
    }
    return handle;
}
Also used : ObjectMarshallingStrategy(org.kie.api.marshalling.ObjectMarshallingStrategy) WorkingMemoryEntryPoint(org.drools.core.WorkingMemoryEntryPoint) NamedEntryPoint(org.drools.core.common.NamedEntryPoint) EntryPoint(org.kie.api.runtime.rule.EntryPoint) WorkingMemoryEntryPoint(org.drools.core.WorkingMemoryEntryPoint) NamedEntryPoint(org.drools.core.common.NamedEntryPoint) EntryPoint(org.kie.api.runtime.rule.EntryPoint) DefaultFactHandle(org.drools.core.common.DefaultFactHandle) ObjectTypeConf(org.drools.core.reteoo.ObjectTypeConf) EntryPointId(org.drools.core.rule.EntryPointId) QueryElementFactHandle(org.drools.core.common.QueryElementFactHandle) EventFactHandle(org.drools.core.common.EventFactHandle) InternalFactHandle(org.drools.core.common.InternalFactHandle)

Example 2 with EntryPointId

use of org.drools.core.rule.EntryPointId in project drools by kiegroup.

the class ProtobufInputMarshaller method readFactHandle.

public static InternalFactHandle readFactHandle(MarshallerReaderContext context, EntryPoint entryPoint, FactHandle _handle) throws IOException, ClassNotFoundException {
    Object object = null;
    ObjectMarshallingStrategy strategy = null;
    if (_handle.hasStrategyIndex()) {
        strategy = context.usedStrategies.get(_handle.getStrategyIndex());
        object = strategy.unmarshal(context.strategyContexts.get(strategy), context, _handle.getObject().toByteArray(), (context.kBase == null) ? null : context.kBase.getRootClassLoader());
    }
    EntryPointId confEP;
    if (entryPoint != null) {
        confEP = ((NamedEntryPoint) entryPoint).getEntryPoint();
    } else {
        confEP = context.wm.getEntryPoint();
    }
    ObjectTypeConf typeConf = context.wm.getObjectTypeConfigurationRegistry().getObjectTypeConf(confEP, object);
    InternalFactHandle handle = null;
    switch(_handle.getType()) {
        case FACT:
            {
                handle = new DefaultFactHandle(_handle.getId(), object, _handle.getRecency(), (WorkingMemoryEntryPoint) entryPoint, typeConf != null && typeConf.isTrait());
                break;
            }
        case QUERY:
            {
                handle = new QueryElementFactHandle(object, _handle.getId(), _handle.getRecency());
                break;
            }
        case EVENT:
            {
                handle = new EventFactHandle(_handle.getId(), object, _handle.getRecency(), _handle.getTimestamp(), _handle.getDuration(), (WorkingMemoryEntryPoint) entryPoint, typeConf != null && typeConf.isTrait());
                ((EventFactHandle) handle).setExpired(_handle.getIsExpired());
                ((EventFactHandle) handle).setOtnCount(_handle.getOtnCount());
                // ((EventFactHandle) handle).setActivationsCount( _handle.getActivationsCount() );
                break;
            }
        default:
            {
                throw new IllegalStateException("Unable to marshal FactHandle, as type does not exist:" + _handle.getType());
            }
    }
    return handle;
}
Also used : DefaultFactHandle(org.drools.core.common.DefaultFactHandle) ObjectTypeConf(org.drools.core.reteoo.ObjectTypeConf) EntryPointId(org.drools.core.rule.EntryPointId) ObjectMarshallingStrategy(org.kie.api.marshalling.ObjectMarshallingStrategy) QueryElementFactHandle(org.drools.core.common.QueryElementFactHandle) EventFactHandle(org.drools.core.common.EventFactHandle) InternalFactHandle(org.drools.core.common.InternalFactHandle)

Example 3 with EntryPointId

use of org.drools.core.rule.EntryPointId in project drools by kiegroup.

the class DefaultAgenda method insertAndStageActivation.

@Override
public void insertAndStageActivation(final AgendaItem activation) {
    if (activationObjectTypeConf == null) {
        EntryPointId ep = workingMemory.getEntryPoint();
        activationObjectTypeConf = ((WorkingMemoryEntryPoint) workingMemory.getWorkingMemoryEntryPoint(ep.getEntryPointId())).getObjectTypeConfigurationRegistry().getObjectTypeConf(ep, activation);
    }
    InternalFactHandle factHandle = workingMemory.getFactHandleFactory().newFactHandle(activation, activationObjectTypeConf, workingMemory, workingMemory);
    workingMemory.getEntryPointNode().assertActivation(factHandle, activation.getPropagationContext(), workingMemory);
    activation.setActivationFactHandle(factHandle);
}
Also used : EntryPointId(org.drools.core.rule.EntryPointId) WorkingMemoryEntryPoint(org.drools.core.WorkingMemoryEntryPoint)

Example 4 with EntryPointId

use of org.drools.core.rule.EntryPointId in project drools by kiegroup.

the class ReteooRuleBuilder method addEntryPoint.

public void addEntryPoint(final String id, final InternalKnowledgeBase kBase) {
    // creates a clean build context for each subrule
    final BuildContext context = new BuildContext(kBase);
    EntryPointId ep = new EntryPointId(id);
    ReteooComponentBuilder builder = utils.getBuilderFor(ep);
    builder.build(context, utils, ep);
}
Also used : EntryPointId(org.drools.core.rule.EntryPointId)

Example 5 with EntryPointId

use of org.drools.core.rule.EntryPointId in project drools by kiegroup.

the class Rete method retractObject.

/**
 * Retract a fact object from this <code>RuleBase</code> and the specified
 * <code>WorkingMemory</code>.
 *
 * @param handle
 *            The handle of the fact to retract.
 * @param workingMemory
 *            The working memory session.
 */
public void retractObject(final InternalFactHandle handle, final PropagationContext context, final InternalWorkingMemory workingMemory) {
    EntryPointId entryPoint = context.getEntryPoint();
    EntryPointNode node = this.entryPoints.get(entryPoint);
    ObjectTypeConf typeConf = ((WorkingMemoryEntryPoint) workingMemory.getWorkingMemoryEntryPoint(entryPoint.getEntryPointId())).getObjectTypeConfigurationRegistry().getObjectTypeConf(entryPoint, handle.getObject());
    node.retractObject(handle, context, typeConf, workingMemory);
}
Also used : EntryPointId(org.drools.core.rule.EntryPointId)

Aggregations

EntryPointId (org.drools.core.rule.EntryPointId)11 WorkingMemoryEntryPoint (org.drools.core.WorkingMemoryEntryPoint)3 NamedEntryPoint (org.drools.core.common.NamedEntryPoint)3 DefaultFactHandle (org.drools.core.common.DefaultFactHandle)2 EventFactHandle (org.drools.core.common.EventFactHandle)2 InternalFactHandle (org.drools.core.common.InternalFactHandle)2 QueryElementFactHandle (org.drools.core.common.QueryElementFactHandle)2 EntryPointNode (org.drools.core.reteoo.EntryPointNode)2 ObjectTypeConf (org.drools.core.reteoo.ObjectTypeConf)2 Declaration (org.drools.core.rule.Declaration)2 ObjectMarshallingStrategy (org.kie.api.marshalling.ObjectMarshallingStrategy)2 EntryPoint (org.kie.api.runtime.rule.EntryPoint)2 AnalysisResult (org.drools.compiler.compiler.AnalysisResult)1 BoundIdentifiers (org.drools.compiler.compiler.BoundIdentifiers)1 DescrBuildError (org.drools.compiler.compiler.DescrBuildError)1 FromDescr (org.drools.compiler.lang.descr.FromDescr)1 MVELDataProvider (org.drools.core.base.dataproviders.MVELDataProvider)1 MVELCompilationUnit (org.drools.core.base.mvel.MVELCompilationUnit)1 InternalWorkingMemoryEntryPoint (org.drools.core.common.InternalWorkingMemoryEntryPoint)1 InternalKnowledgeBase (org.drools.core.impl.InternalKnowledgeBase)1