use of org.drools.core.common.EventFactHandle in project drools by kiegroup.
the class StrictAnnotationTest method testJavaSqlTimestamp.
@Test
public void testJavaSqlTimestamp() {
String str = "package " + Message.class.getPackage().getName() + "\n" + "@Role( Role.Type.EVENT ) @Timestamp( \"startTime\" ) @Duration( \"duration\" )\n" + "declare " + Message.class.getCanonicalName() + "\n" + "end\n";
Map<String, String> kieModuleConfigurationProperties = new HashMap<>();
kieModuleConfigurationProperties.put(LanguageLevelOption.PROPERTY_NAME, LanguageLevelOption.DRL6_STRICT.toString());
KieBase kbase = KieBaseUtil.getKieBaseFromKieModuleFromDrl("test", kieBaseTestConfiguration, kieModuleConfigurationProperties, str);
KieSession ksession = kbase.newKieSession();
try {
Message msg = new Message();
msg.setStartTime(new Timestamp(10000));
msg.setDuration(1000l);
EventFactHandle efh = (EventFactHandle) ksession.insert(msg);
assertEquals(10000, efh.getStartTimestamp());
assertEquals(1000, efh.getDuration());
} finally {
ksession.dispose();
}
}
use of org.drools.core.common.EventFactHandle in project drools by kiegroup.
the class WindowNode method assertObject.
public void assertObject(final InternalFactHandle factHandle, final PropagationContext pctx, final ReteEvaluator reteEvaluator) {
EventFactHandle evFh = (EventFactHandle) factHandle;
for (AlphaNodeFieldConstraint constraint : constraints) {
if (!constraint.isAllowed(evFh, reteEvaluator)) {
return;
}
}
RightTuple rightTuple = new RightTupleImpl(evFh, this);
rightTuple.setPropagationContext(pctx);
// this is cloned, as we need to separate the child RightTuple references
InternalFactHandle clonedFh = evFh.cloneAndLink();
rightTuple.setContextObject(clonedFh);
// process the behavior
final WindowMemory memory = reteEvaluator.getNodeMemory(this);
if (!behavior.assertFact(memory.behaviorContext, clonedFh, pctx, reteEvaluator)) {
return;
}
this.sink.propagateAssertObject(clonedFh, pctx, reteEvaluator);
}
use of org.drools.core.common.EventFactHandle in project drools by kiegroup.
the class CepTest method testComplexTimestamp.
@Test
public void testComplexTimestamp() {
final String str = "import " + Message.class.getCanonicalName() + "\n" + "declare " + Message.class.getCanonicalName() + "\n" + " @role( event ) \n" + " @timestamp( getProperties().get( 'timestamp' ) - 1 ) \n" + " @duration( getProperties().get( 'duration' ) + 1 ) \n" + "end\n";
KieSession ksession = getKieSession(getCepKieModuleModel(), str);
try {
final Message msg = new Message();
final Properties props = new Properties();
props.put("timestamp", 99);
props.put("duration", 52);
msg.setProperties(props);
final EventFactHandle efh = (EventFactHandle) ksession.insert(msg);
assertEquals(98, efh.getStartTimestamp());
assertEquals(53, efh.getDuration());
} finally {
ksession.dispose();
}
}
use of org.drools.core.common.EventFactHandle in project drools by kiegroup.
the class ProtobufInputMarshaller method readFactHandle.
public static InternalFactHandle readFactHandle(ProtobufMarshallerReaderContext context, EntryPoint entryPoint, FactHandle _handle) throws IOException, ClassNotFoundException {
Object object = null;
ObjectMarshallingStrategy strategy = null;
if (_handle.hasStrategyIndex()) {
strategy = context.getUsedStrategies().get(_handle.getStrategyIndex());
object = strategy.unmarshal(context.getStrategyContexts().get(strategy), context, _handle.getObject().toByteArray(), (context.getKnowledgeBase() == null) ? null : context.getKnowledgeBase().getRootClassLoader());
}
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(_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;
}
use of org.drools.core.common.EventFactHandle in project drools by kiegroup.
the class CepEspTest method testSubclassWithLongerExpirationThanSuperWithSerialization.
@Test
public void testSubclassWithLongerExpirationThanSuperWithSerialization() {
// DROOLS-983
final String drl = "import " + SuperClass.class.getCanonicalName() + "\n" + "import " + SubClass.class.getCanonicalName() + "\n" + "\n" + "rule R1 when\n" + " $e : SuperClass()\n" + "then\n" + "end\n" + "rule R2 when\n" + " $e : SubClass()\n" + " not SubClass(this != $e)\n" + "then\n" + "end";
final KieBase kbase = KieBaseUtil.getKieBaseFromKieModuleFromDrl("cep-esp-test", kieBaseTestConfiguration, drl);
KieSession ksession = kbase.newKieSession(KieSessionTestConfiguration.STATEFUL_PSEUDO.getKieSessionConfiguration(), null);
try {
PseudoClockScheduler clock = ksession.getSessionClock();
final EventFactHandle handle1 = (EventFactHandle) ksession.insert(new SubClass());
ksession.fireAllRules();
clock.advanceTime(15, TimeUnit.SECONDS);
ksession.fireAllRules();
assertFalse(handle1.isExpired());
assertEquals(1, ksession.getObjects().size());
try {
ksession = SerializationHelper.getSerialisedStatefulKnowledgeSession(ksession, true);
} catch (final Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
clock = ksession.getSessionClock();
clock.advanceTime(10, TimeUnit.SECONDS);
ksession.fireAllRules();
assertEquals(0, ksession.getObjects().size());
} finally {
ksession.dispose();
}
}
Aggregations