Hi all, I'm writing Drools into my application through the JSR-94 API, and I've been considering how to deal with required inputs.
For example, I want to add a logging component to working memory so that I can create a good explanation of the results of the rule session. I need to match this as a parameter to make it available in the rule consequence. If the user doesn't add a logger, none of the logging rules will fire. It would be better if I could fire a rule that returned some kind of well-defined error state if the logger is missing, for example asserting an error object or something. There doesn't seem to be a way of matching an absence of an instance of a class in the rules - in fact, the meaning of such a rule is not entirely clear. One way I tried to do this was to count the number of loggers - and assert the count as a fact. A rule can match this fact and assert an error. The only trouble was that I had to implement modes and mode changes in the rules as well; the scaffolding code was large enough that it destroys the most important benefits of using a rule engine to begin with, i.e. recording business logic in a concise and manageable way. Has anyone tackled this? Am I missing a better approach? I am currently thinking of simply unit testing the clients to check that the inputs match the current version of the rules, and programming the clients defensively. This also started me thinking about strategies to manage change in rules. How do you make sure that old clients get a decent error state if they run rules that they no longer know how to make good inputs for. Here I decided that the best approach was a good versioning system, with major version changes indicating that a client is no longer 'binary compatible' with a set of rules. Whatever you do, because rules and code are separate, you will always have to be careful when deploying them that the clients can call rules properly, and that the results still mean the same thing that the client thinks they mean... ********************************************************************** This e-mail and any attachment is intended for the named addressee(s) only, or person authorised to receive it on their behalf. The content should be treated as confidential and the recipient may not disclose this message or any attachment to anyone else without authorisation. Unauthorised use, copying or disclosure may be unlawful. If this transmission is received in error please notify the sender immediately and delete this message from your e-mail system. Any view expressed by the sender of this message or any attachment may be personal and may not represent the view held by First Choice Holidays PLC and its subsidiaries. All electronic transmissions to and from First Choice are recorded, may be monitored and are scanned for viruses and content. E-mails containing viruses will be deleted without notification. Whilst we maintain virus checks on inbound e-mails we accept no liability for viruses or other material introduced with this message. All companies form part of the First Choice Holidays PLC group of companies. First Choice Holidays PLC Company Registration No: 48967 (England) Registered Office: First Choice House, London Road, Crawley, WestSussex RH10 9GX **********************************************************************
