use of org.drools.core.common.EventFactHandle in project drools by kiegroup.
the class TemporalEvaluatorFactoryTest method testFinishedBy.
@Test
public void testFinishedBy() {
registry.addEvaluatorDefinition(DuringEvaluatorDefinition.class.getName());
EventFactHandle foo = new EventFactHandle(1, "foo", 1, 2, 10, new DisconnectedWorkingMemoryEntryPoint("DEFAULT"));
EventFactHandle bar = new EventFactHandle(2, "bar", 1, 5, 7, new DisconnectedWorkingMemoryEntryPoint("DEFAULT"));
EventFactHandle drool = new EventFactHandle(1, "drool", 1, 2, 10, new DisconnectedWorkingMemoryEntryPoint("DEFAULT"));
EventFactHandle mole = new EventFactHandle(1, "mole", 1, 7, 6, new DisconnectedWorkingMemoryEntryPoint("DEFAULT"));
final Object[][] data = { { foo, "finishedby", bar, Boolean.TRUE }, { foo, "finishedby", drool, Boolean.FALSE }, { foo, "finishedby", mole, Boolean.FALSE }, { bar, "finishedby", foo, Boolean.FALSE }, { foo, "not finishedby", bar, Boolean.FALSE }, { foo, "not finishedby", drool, Boolean.TRUE }, { foo, "not finishedby", mole, Boolean.TRUE }, { bar, "not finishedby", foo, Boolean.TRUE }, { foo, "finishedby[1]", bar, Boolean.TRUE }, { foo, "finishedby[1]", drool, Boolean.FALSE }, { foo, "finishedby[1]", mole, Boolean.TRUE }, { bar, "finishedby[1]", foo, Boolean.FALSE }, { foo, "not finishedby[1]", bar, Boolean.FALSE }, { foo, "not finishedby[1]", drool, Boolean.TRUE }, { foo, "not finishedby[1]", mole, Boolean.FALSE }, { bar, "not finishedby[1]", foo, Boolean.TRUE }, { foo, "finishedby[3]", mole, Boolean.TRUE } };
runEvaluatorTest(data, ValueType.OBJECT_TYPE);
}
use of org.drools.core.common.EventFactHandle in project drools by kiegroup.
the class TemporalEvaluatorFactoryTest method testMeets.
@Test
public void testMeets() {
registry.addEvaluatorDefinition(DuringEvaluatorDefinition.class.getName());
EventFactHandle foo = new EventFactHandle(1, "foo", 1, 2, 8, new DisconnectedWorkingMemoryEntryPoint("DEFAULT"));
EventFactHandle bar = new EventFactHandle(2, "bar", 1, 10, 7, new DisconnectedWorkingMemoryEntryPoint("DEFAULT"));
EventFactHandle drool = new EventFactHandle(1, "drool", 1, 8, 5, new DisconnectedWorkingMemoryEntryPoint("DEFAULT"));
EventFactHandle mole = new EventFactHandle(1, "mole", 1, 11, 4, new DisconnectedWorkingMemoryEntryPoint("DEFAULT"));
final Object[][] data = { { foo, "meets", bar, Boolean.TRUE }, { foo, "meets", drool, Boolean.FALSE }, { foo, "meets", mole, Boolean.FALSE }, { foo, "not meets", bar, Boolean.FALSE }, { foo, "not meets", drool, Boolean.TRUE }, { foo, "not meets", mole, Boolean.TRUE }, { foo, "meets[1]", bar, Boolean.TRUE }, { foo, "meets[1]", drool, Boolean.FALSE }, { foo, "meets[1]", mole, Boolean.TRUE }, { foo, "meets[2]", drool, Boolean.TRUE }, { foo, "not meets[1]", bar, Boolean.FALSE }, { foo, "not meets[1]", drool, Boolean.TRUE }, { foo, "not meets[1]", mole, Boolean.FALSE }, { foo, "not meets[2]", drool, Boolean.FALSE } };
runEvaluatorTest(data, ValueType.OBJECT_TYPE);
}
use of org.drools.core.common.EventFactHandle in project drools by kiegroup.
the class ProtobufOutputMarshaller method writeFactHandle.
private static ProtobufMessages.FactHandle writeFactHandle(MarshallerWriteContext context, ObjectMarshallingStrategyStore objectMarshallingStrategyStore, InternalFactHandle handle) throws IOException {
ProtobufMessages.FactHandle.Builder _handle = ProtobufMessages.FactHandle.newBuilder();
_handle.setType(getHandleType(handle));
_handle.setId(handle.getId());
_handle.setRecency(handle.getRecency());
if (_handle.getType() == ProtobufMessages.FactHandle.HandleType.EVENT) {
// is event
EventFactHandle efh = (EventFactHandle) handle;
_handle.setTimestamp(efh.getStartTimestamp());
_handle.setDuration(efh.getDuration());
_handle.setIsExpired(efh.isExpired());
_handle.setActivationsCount(efh.getActivationsCount());
_handle.setOtnCount(efh.getOtnCount());
}
if (handle.getEqualityKey() != null && handle.getEqualityKey().getStatus() == EqualityKey.JUSTIFIED) {
_handle.setIsJustified(true);
} else {
_handle.setIsJustified(false);
}
Object object = handle.getObject();
if (object != null) {
ObjectMarshallingStrategy strategy = objectMarshallingStrategyStore.getStrategyObject(object);
Integer index = context.getStrategyIndex(strategy);
_handle.setStrategyIndex(index);
_handle.setObject(ByteString.copyFrom(strategy.marshal(context.getStrategyContext().get(strategy), (ObjectOutputStream) context, object)));
}
return _handle.build();
}
use of org.drools.core.common.EventFactHandle in project drools by kiegroup.
the class InputMarshaller method readFactHandle.
public static InternalFactHandle readFactHandle(MarshallerReaderContext context) throws IOException, ClassNotFoundException {
int type = context.readInt();
long id = context.readLong();
long recency = context.readLong();
long startTimeStamp = 0;
long duration = 0;
boolean expired = false;
long activationsCount = 0;
if (type == 2) {
startTimeStamp = context.readLong();
duration = context.readLong();
expired = context.readBoolean();
activationsCount = context.readLong();
}
int strategyIndex = context.readInt();
ObjectMarshallingStrategy strategy = null;
// This is the old way of de/serializing strategy objects
if (strategyIndex >= 0) {
strategy = context.getResolverStrategyFactory().getStrategy(strategyIndex);
} else // This is the new way
if (strategyIndex == -2) {
String strategyClassName = context.readUTF();
if (!StringUtils.isEmpty(strategyClassName)) {
strategy = context.getResolverStrategyFactory().getStrategyObject(strategyClassName);
if (strategy == null) {
throw new IllegalStateException("No strategy of type " + strategyClassName + " available.");
}
}
}
// If either way retrieves a strategy, use it
Object object = null;
if (strategy != null) {
object = strategy.read((ObjectInputStream) context);
}
EntryPoint entryPoint = null;
if (context.readBoolean()) {
String entryPointId = context.readUTF();
if (entryPointId != null && !entryPointId.equals("")) {
entryPoint = ((RuleRuntime) context.getWorkingMemory()).getEntryPoint(entryPointId);
}
}
EntryPointId confEP;
if (entryPoint != null) {
confEP = ((NamedEntryPoint) entryPoint).getEntryPoint();
} else {
confEP = context.getWorkingMemory().getEntryPoint();
}
ObjectTypeConf typeConf = context.getWorkingMemory().getObjectTypeConfigurationRegistry().getOrCreateObjectTypeConf(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;
}
use of org.drools.core.common.EventFactHandle in project drools by kiegroup.
the class ExpireJobContextTimerInputMarshaller method read.
public void read(ProtobufMarshallerReaderContext inCtx) throws IOException, ClassNotFoundException {
InternalFactHandle factHandle = inCtx.getHandles().get(inCtx.readLong());
long nextTimeStamp = inCtx.readLong();
TimerService clock = inCtx.getWorkingMemory().getTimerService();
JobContext jobctx = new ExpireJobContext(new WorkingMemoryReteExpireAction((EventFactHandle) factHandle), inCtx.getWorkingMemory());
JobHandle handle = clock.scheduleJob(job, jobctx, PointInTimeTrigger.createPointInTimeTrigger(nextTimeStamp, null));
jobctx.setJobHandle(handle);
}
Aggregations