/** * This is a factory method for this Max Threads configuration. * The factory method is a best practice for the case where the * actual object construction is changed in the future. * * @param threshold the maximum number of threads for partition evaluation * * @return the actual type safe max threads configuration. */ public static MaxThreadsOption get( int threshold ) { return new MaxThreadsOption( threshold ); }
/** * This is a factory method for this Alpha Threshold configuration. * The factory method is a best practice for the case where the * actual object construction is changed in the future. * * @param threshold the threshold value for the alpha hashing option * * @return the actual type safe alpha threshold configuration. */ public static AlphaThresholdOption get( int threshold ) { return new AlphaThresholdOption( threshold ); }
/** * This is a factory method for this PermGen Threshold configuration. * The factory method is a best practice for the case where the * actual object construction is changed in the future. * * @param threshold the threshold value for the PermGen option * * @return the actual type safe PermGen threshold configuration. */ public static PermGenThresholdOption get( int threshold ) { return new PermGenThresholdOption( threshold ); }
public static KieBaseOption adaptOption(KnowledgeBaseOption option) { if (option instanceof org.drools.conf.AlphaThresholdOption) { org.drools.conf.AlphaThresholdOption legacyOption = (org.drools.conf.AlphaThresholdOption)option; return AlphaThresholdOption.get(legacyOption.getThreshold()); return CompositeKeyDepthOption.get(legacyOption.getDepth()); return MaxThreadsOption.get(legacyOption.getMaxThreads()); return PermGenThresholdOption.get(legacyOption.getThreshold());
public static SingleValueKnowledgeBaseOption adaptOption(SingleValueKieBaseOption option) { if (option instanceof AlphaThresholdOption) { AlphaThresholdOption kieOption = (AlphaThresholdOption)option; return org.drools.conf.AlphaThresholdOption.get(kieOption.getThreshold()); return org.drools.conf.CompositeKeyDepthOption.get(kieOption.getDepth()); return org.drools.conf.MaxThreadsOption.get(kieOption.getMaxThreads()); return org.drools.conf.PermGenThresholdOption.get(kieOption.getThreshold());
@Test public void testConsequenceExceptionHandlerConfiguration() { Class<? extends ConsequenceExceptionHandler> handler = DefaultConsequenceExceptionHandler.class; // setting the option using the type safe method config.setOption( ConsequenceExceptionHandlerOption.get(handler) ); // checking the type safe getOption() method assertEquals( ConsequenceExceptionHandlerOption.get(handler), config.getOption( ConsequenceExceptionHandlerOption.class ) ); // checking the string based getProperty() method assertEquals( handler.getName(), config.getProperty( ConsequenceExceptionHandlerOption.PROPERTY_NAME ) ); // setting the options using the string based setProperty() method config.setProperty( ConsequenceExceptionHandlerOption.PROPERTY_NAME, handler.getName() ); // checking the type safe getOption() method assertEquals( handler.getName(), config.getOption( ConsequenceExceptionHandlerOption.class ).getHandler().getName() ); // checking the string based getProperty() method assertEquals( handler.getName(), config.getProperty( ConsequenceExceptionHandlerOption.PROPERTY_NAME ) ); }
@Test public void testCompositeKeyDepthConfiguration() { // setting the option using the type safe method config.setOption( CompositeKeyDepthOption.get(1) ); // checking the type safe getOption() method assertEquals( CompositeKeyDepthOption.get(1), config.getOption( CompositeKeyDepthOption.class ) ); // checking the string based getProperty() method assertEquals( "1", config.getProperty( CompositeKeyDepthOption.PROPERTY_NAME ) ); // setting the options using the string based setProperty() method config.setProperty( CompositeKeyDepthOption.PROPERTY_NAME, "2" ); // checking the type safe getOption() method assertEquals( CompositeKeyDepthOption.get(2), config.getOption( CompositeKeyDepthOption.class ) ); // checking the string based getProperty() method assertEquals( "2", config.getProperty( CompositeKeyDepthOption.PROPERTY_NAME ) ); }
@Test public void testAlphaThresholdConfiguration() { // setting the option using the type safe method config.setOption( AlphaThresholdOption.get(5) ); // checking the type safe getOption() method assertEquals( AlphaThresholdOption.get(5), config.getOption( AlphaThresholdOption.class ) ); // checking the string based getProperty() method assertEquals( "5", config.getProperty( AlphaThresholdOption.PROPERTY_NAME ) ); // setting the options using the string based setProperty() method config.setProperty( AlphaThresholdOption.PROPERTY_NAME, "7" ); // checking the type safe getOption() method assertEquals( AlphaThresholdOption.get(7), config.getOption( AlphaThresholdOption.class ) ); // checking the string based getProperty() method assertEquals( "7", config.getProperty( AlphaThresholdOption.PROPERTY_NAME ) ); }
@Test public void testMaxThreadsConfiguration() { // setting the option using the type safe method config.setOption( MaxThreadsOption.get(5) ); // checking the type safe getOption() method assertEquals( MaxThreadsOption.get(5), config.getOption( MaxThreadsOption.class ) ); // checking the string based getProperty() method assertEquals( "5", config.getProperty( MaxThreadsOption.PROPERTY_NAME ) ); // setting the options using the string based setProperty() method config.setProperty( MaxThreadsOption.PROPERTY_NAME, "8" ); // checking the type safe getOption() method assertEquals( MaxThreadsOption.get(8), config.getOption( MaxThreadsOption.class ) ); // checking the string based getProperty() method assertEquals( "8", config.getProperty( MaxThreadsOption.PROPERTY_NAME ) ); }
@Test public void testPermGenThresholdConfiguration() { Assume.assumeTrue("JVM with perm gen", MemoryUtil.hasPermGen()); // setting the option using the type safe method config.setOption( PermGenThresholdOption.get(85) ); // checking the type safe getOption() method assertEquals( PermGenThresholdOption.get(85), config.getOption( PermGenThresholdOption.class ) ); // checking the string based getProperty() method assertEquals( "85", config.getProperty( PermGenThresholdOption.PROPERTY_NAME ) ); // setting the options using the string based setProperty() method config.setProperty( PermGenThresholdOption.PROPERTY_NAME, "87" ); // checking the type safe getOption() method assertEquals( PermGenThresholdOption.get(87), config.getOption( PermGenThresholdOption.class ) ); // checking the string based getProperty() method assertEquals( "87", config.getProperty( PermGenThresholdOption.PROPERTY_NAME ) ); }
protected synchronized KieBase getKieBase(final String... drls) { final KieHelper kieHelper = new KieHelper(); for (final String drl : drls) { kieHelper.addContent(drl, ResourceType.DRL); } KieBase kieBase; if (enforcedJitting) { kieBase = kieHelper.build(ConstraintJittingThresholdOption.get(0)); } else { kieBase = kieHelper.build(); } if (serializeKieBase) { kieBase = serializeAndDeserializeKieBase(kieBase); } return kieBase; }
/** * This is a factory method for this CompositeKeyDepth configuration. * The factory method is a best practice for the case where the * actual object construction is changed in the future. * * @param depth the composite key depth value * * @return the actual type safe CompositeKeyDepth configuration. */ public static CompositeKeyDepthOption get( int depth ) { return new CompositeKeyDepthOption( depth ); }
/** * This is a factory method for this Constraint Jitting Threshold configuration. * The factory method is a best practice for the case where the * actual object construction is changed in the future. * * @param threshold the threshold value for the Constraint Jitting option * * @return the actual type safe Constraint Jitting threshold configuration. */ public static ConstraintJittingThresholdOption get( int threshold ) { return new ConstraintJittingThresholdOption( threshold ); }
/** * This is a factory method for this ConsequenceExceptionHandler configuration. * The factory method is a best practice for the case where the * actual object construction is changed in the future. * * @param handler the actual consequence exception handler class to be used * * @return the actual type safe consequence exception handler configuration. */ public static ConsequenceExceptionHandlerOption get( final Class<? extends ConsequenceExceptionHandler> handler ) { return new ConsequenceExceptionHandlerOption( handler ); }
public static IndexPrecedenceOption determineIndexPrecedence(String mode) { if ( PATTERN_ORDER.getValue().equalsIgnoreCase( mode ) ) { return PATTERN_ORDER; } else if ( EQUALITY_PRIORITY.getValue().equalsIgnoreCase( mode ) ) { return EQUALITY_PRIORITY; } throw new IllegalArgumentException( "Illegal enum value '" + mode + "' for IndexPrecedence" ); }
@Test public void testJittingEnum() { final String drl = "import " + AnEnum.class.getCanonicalName() + ";\n" + " rule R1 \n" + " when \n" + " $enumFact: AnEnum(this == AnEnum.FIRST)\n" + " then \n" + " end "; final KieHelper kieHelper = new KieHelper(); kieHelper.addContent( drl, ResourceType.DRL ); final KieBase kieBase = kieHelper.build(ConstraintJittingThresholdOption.get(0)); final KieSession kieSession = kieBase.newKieSession(); kieSession.insert(AnEnum.FIRST); Assertions.assertThat(kieSession.fireAllRules()).isEqualTo(1); }
@Test public void testJittingEnumAttribute() { final String drl = "import " + AnEnum.class.getCanonicalName() + ";\n" + "import " + FactWithEnum.class.getCanonicalName() + ";\n" + " rule R1 \n" + " when \n" + " $factWithEnum: FactWithEnum(enumValue == AnEnum.FIRST) \n" + " then \n" + " end "; final KieHelper kieHelper = new KieHelper(); kieHelper.addContent( drl, ResourceType.DRL ); final KieBase kieBase = kieHelper.build(ConstraintJittingThresholdOption.get(0)); final KieSession kieSession = kieBase.newKieSession(); kieSession.insert(new FactWithEnum(AnEnum.FIRST)); Assertions.assertThat(kieSession.fireAllRules()).isEqualTo(1); } }
@Test public void testMvelJitDivision() { // DROOLS-2928 String drl = "import " + Person.class.getName() + ";\n" + "rule R1 when\n" + " Person( name == \"John\", $age1 : age )\n" + " Person( name == \"Paul\", age > ((2*$age1)/3) )\n" + "then end\n"; KieSession ksession = new KieHelper().addContent(drl, ResourceType.DRL).build(ConstraintJittingThresholdOption.get(0)).newKieSession(); Person john = new Person("John", 20); ksession.insert(john); Person paul = new Person("Paul", 20); ksession.insert(paul); int fired = ksession.fireAllRules(); assertEquals(1, fired); } }