The best option might very well be to insert the item objects as well and to write<br><br>  
 $doc: Document(issued==true)<br>   $job: Job(type==JobType.VALIDATE, item == $doc)<br><br>-W<br><br><br><div class="gmail_quote">On 11 October 2011 15:10, hsherlock <span dir="ltr">&lt;<a href="mailto:citadela@gmail.com">citadela@gmail.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div><div></div><div class="h5">I have a following scenario in which a complex logic (distributed over<br>

multiple .DRL files) need to process incoming jobs as fast as possible. A<br>
job definition looks something like describing what to do (type), what to<br>
process (item) with some additional data supplied (args).<br>
<br>
enum JobType<br>
{<br>
        VALIDATE,<br>
        SEND<br>
}<br>
<br>
class Job<br>
{<br>
        String type;<br>
        Object item;<br>
        Object[] args;<br>
}<br>
<br>
In order to implement the processing I need to put the business logic into<br>
rules which fire depending on the kind of processing requested and type of<br>
the item passed:<br>
<br>
rule &quot;process [VALIDATION] on [Document]&quot;<br>
        when<br>
                $job: Job(type==JobType.VALIDATE)<br>
                $doc: Document(issued==true) from $job.item<br>
        then<br>
                insert(new DocumentAlreadyIssuedFact());<br>
end<br>
<br>
rule &quot;process [SENDING] on [Message]&quot;<br>
        when<br>
                $job: Job(type==JobType.SEND)<br>
                $msg: Message() from $job.item<br>
        then<br>
                //do the sending<br>
end<br>
<br>
Unfortunately this does not work and results in ClassCastException being<br>
thrown, because it looks that Drools tries to cast any passed item to the<br>
class expected by the particular rule. In my opinion behaviour one can<br>
expect from Drools here is to first match the item class to the one expected<br>
by the rule and on success to perform the type casting.<br>
Is it a Drools bug or a missing feature?<br>
<br>
So after stidying the documention and example code I found only one way to<br>
workaround this – by using eval and instanceof which should have its<br>
performance implications due to extensive use of the eval.<br>
<br>
</div></div>rule &quot;process [VALIDATION] on [Document]&quot;<br>
        when<br>
                $job: Job(type==JobType.VALIDATE)<br>
                eval(($job.item instanceof Document))<br>
<div class="im">                $doc: Document(issued==true) from $job.item<br>
        then<br>
                insert(new DocumentAlreadyIssuedFact());<br>
end<br>
<br>
rule &quot;process [SENDING] on [Message]&quot;<br>
        when<br>
                $job: Job(type==JobType.SEND)<br>
</div>                eval(($job.item instanceof Message))<br>
<div class="im">                $msg: Message() from $job.item<br>
        then<br>
                //do the sending<br>
end<br>
<br>
Such an implementation works, but I see it as some form of workaround as my<br>
feeling is that it will not allow the optimizations of Drools to shine.<br>
<br>
Please recommend more effective and elegant way of implementing this.<br>
<br>
Thank you in advance<br>
<br>
--<br>
</div>View this message in context: <a href="http://drools.46999.n3.nabble.com/Typecasting-problem-tp3412518p3412518.html" target="_blank">http://drools.46999.n3.nabble.com/Typecasting-problem-tp3412518p3412518.html</a><br>

<div><div></div><div class="h5">Sent from the Drools: User forum mailing list archive at Nabble.com.<br>
<br>
_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
</div></div></blockquote></div><br>