31. Drools - przykłady $order : Order() not Contract( this after [-*,10m] $order ) $contract : Contract() not Activation( this after [1s,134d] $contract) $activation : not Activation( this during $waitingRoom ) $contract : Contract( this coincides[15s, 10s] $order ) rule "sendParcel" when $order : Order() not CancelOrder(order == $order) then System.out.println(“sendParcel); end
84. Drools drool /drul/ – verb (used without object) 1. to water at the mouth, as in anticipation of food; salivate; drivel. 2. to show excessive pleasure or anticipation of pleasure. 3. to talk foolishly. – noun 4. saliva running down from one's mouth; drivel.
99. Drools – język opisu reguł import pl.touk.javarsovia.model.* global pl.touk.javarsovia.utils.Sender sender rule "normalClient" when $customer : Customer(status == Customer.Status.normal) $order : Order(state == Order.State.NEW, customer == $customer) then sender.send( "direct:normal" , $o); end
100. Drools – język opisu reguł rule "sendParcel" when $order : Order() $confirmation : WarehouseConfirmation(order == $order) not CancelOrder(order == $order) then sender.send( "direct:parcel" , $confirmation) end
101. Przykład użycia KnowledgeBuilder knowledgeBuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(); knowledgeBuilder.add( new ClassPathResource( "orderRules.drl" ),ResourceType.DRL); KnowledgeBase knowledgeBase = KnowledgeBaseFactory.newKnowledgeBase(); knowledgeBase.addKnowledgePackages( knowledgeBuilder.getKnowledgePackages()); StatefulKnowledgeSession statefulKnowledgeSession = knowledgeBase.newStatefulKnowledgeSession();
102. Przykład użycia - cd StatefulKnowledgeSession statefulKnowledgeSession = knowledgeBase.newStatefulKnowledgeSession(); statefulKnowledgeSession.setGlobal( "sender" , sender); Order order = new Order(); statefulKnowledgeSession.insert(order); statefulKnowledgeSession.fireAllRules();
108. Drools Fusion - Eventy declare Order @role(event) @expires(365d) @ duration ( duration ) end public class Order { public long getDuration() { return 5000; } public long getTimestamp() { return createTime.getDate(); } }
109. Drools Fusion - predykaty $order : Order() not Contract( this after [-*,-10m] $order ) $contract : Contract() not Activation( this after [1s,134d] $contract) $activation : not Activation( this during $waitingRoom ) $contract : Contract( this coincides[15s, 10s] $order )