WEBLOGIC PORTAL rules engines used in the dynamic business logic
Abstract: WEBLOGIC PORTAL rules engine to achieve dynamic business logic
<tr> <td>
Introduction
Always demand business applications with the trend of changes in business environment of constant change. Decision-making is rarely static, and competitive pressure for business logic in the design and realization of flexibility to quickly adapt to changing needs. Usually, the business logic of the changes must be completed by the developer, and then conducted a number of thorough testing, and this will be a very time-consuming process. Changes in the application procedures are completed, the need to be re-deployed to the server, the need to stay in a scheduled downtime, to prevent the user application can not be used.
In this regard, a better solution is through the application of a set of rules to achieve certain business decisions. These rules have not been compiled into applications, but in the run-time reader and application. In this way, without code changes or stop the running application can change these rules.
WebLogic Portal includes a basic rule engine for the WebLogic Platform applications benefit from the rules. Although the engine is not fully functional product, but we will demonstrate how its WebLogic Integration Business Processes (JPDs) used for business logic to provide a flexible and dynamic Implementation Mechanism, thus eliminating the need to amend the rules and only re-deploy applications procedures.
First, we will look at in the text of the examples of the use of applications, and on how the rules will be injected into the engine WLI process in order to achieve business logic. Then, we would carefully study the rules themselves, and how to define business logic of these rules will ultimately be described in the operation of the system changes in the business rules used by the mechanism.
Examples of applications
We will develop an example application transactions in the business process as rules for the use of examples. The transaction application is a financial transaction processes simplified version of the process using the engine rules call JPD business processes and building. The sample application using different sets of portfolio transactions, and in accordance with a group from the definition of business rules will be the formation of the sub-block for the implementation, perhaps in order to reduce commission. Of course, here is the application is incomplete, but it is sufficient to demonstrate how the application in the real world the use of rules engines. There are complete source code available for download on the readme file which provides construction and operation of the application note.
In explaining how to develop such applications, we first go through the door on some of the rules of the engine briefly summarized to understand their working methods. Readers familiar with the general assumption here that the rules of technology.
Rules engine and its working methods
Figure 1 illustrates the basic rules engine situation. The engine in accordance with a set of rules to deal with the initial set of facts, and these rules from the engines obtained from the outside. Initial fact-filled engine for the working memory. By the rules of the facts in the working memory assessment, if it satisfies the conditions of a rule, will be the implementation of response actions. Normally, a rule of action will add a new memory of the facts and repeat the process until all the applications End rules. Then optional filters to select a specific category of objects to the call to return to the side. Controls can interface access rules engine, it also can be used to set attributes (such as the location of the rules set document).
Figure 1: The rules engine is a component of EJB packaging. Repository repeatedly applied to the rules to the facts in the working memory in order to obtain new facts. Reasoning can not be carried out to the circumstances, the working memory filtered to return to the items of interest.
WLI call from the process rules engine
Let us realize from the transaction for the JPD business processes, to see how we can add to the rules engine call. In the process of adding WLI rules WebLogic Portal can be used as part of the Rules Executor Control (rules for the implementation of controls). For this example, we only use the controls provided in the method and characteristics of a subset. Controls on the rules of the annotated documents can be found in some reference materials.
Here assumed that developers use WebLogic Workshop integrated development environment to create new processes applications. Then in the application process in the creation of a project. Because the default portal under control in the process of the project, and therefore the need for these controls and rules engines imported into the EJB applications. Then, the control input and output to insert in the JPD. WLI process in the use of the portal rules engine basic steps are as follows:
Import rules engines to applications:
- In the application contains rules engines.
- P13n_controls library will be added to the application.
Dealing with input and output:
- To add input variables and the outcome.
- Create a Rules Executor control.
- In the process of adding a WLI Control Send With Return nodes.
- Initial data preparation for the creation of Java code.
- Add a node to process the results iteration.
- Create rule sets.
Later we will be more detailed discussion of each of these steps.
In the application contains rules engine
Rules engine included in the following documents:
/ Weblogic81/p13n/lib/p13n_ejb.jar
To the application contains the engine Right click Workshop integrated development environment in the Modules folder, and choose Add Module. Navigate to the jar file, and choose Open.
P13n_controls library will be added to the application
To make rules gateway controls can be used in the application process, please right-click Workshop integrated development environment in the Libraries folder, and choose Add Library. The controls at:
Navigation of this document, click the Open button.
To add input and variable results
Used here Rules Executor control requires an object array as input and returns a result of iterators. In the Workshop integrated development environment to create value for these variables, so that we can in the next step through a graphical user interface to create controls. To accomplish this task, please Data Palette for the variable click the Add button, type the name of the input variables, and type Java type java.lang.Object []. Use the same method to create Java types java.util.Iterator output variables.
The creation of a Control Rules Executor
To create a control rules, click Control Data Palette in the Add button. From the menu, select Portal Controls -> Rules Executor. Type a name for the controls, and press Create button.
In the process of adding a WLI Control Send With Return node
Will just drag and drop controls to create the process to create a control node to the actual transfer rules engines. In the examples, we will use the controls of evaluateRuleSet () method. Send Data from the panel, the method of choice for the front of the input parameters and the creation of the input variables. The use of panels choose to return to Receive Data variables to obtain the results of the implementation of the rules. In the Property Editor window controls for the corresponding type attribute values.
Initial data preparation for the creation of Java code
In the creation of the input variables, we also did not assign it, so it is necessary to write code to accomplish this task. This variable is a Java Object array, which provides input to the initial conditions of the rules of the facts. Can create a new Perform node to initialize the array, or through the use of the Source View Control Send node add the code to set the value of the variable.
Add a node to process the results iterative
Rules Executor controls every calculation method will return a result of iterators. Write code, the use of the value of achieving the results of the implementation of the rules iteration. If there is no designated filter categories, this iteration of the rules engine will return to the memory of all the work value. Including the original input, as well as to meet any conditions in the implementation of the rules of action when added to the value of memory. Adding to the target of iterators return a Result of the targets of such getObject () method can return to action in the rules of the content of the actual object.
Create rules set
Using XML Editor, in / META-INF/data create a directory of extensions. Rls document. Rules are usually added to the subdirectory in the rulesets.
Business logic rules
We have just demonstrated how the business processes into rules engines. Let us now look at how to use the rules engine, as well as how to prepare mapped to the business rules of rules.
Rules consists of two parts: the application of the rules must be really conditions, and when the conditions will be met implementation of the action. Therefore, we must use in the application of the rules of procedure, designers must first define what objects and attributes in the test conditions of the rules of the rules writers is visible. Rules allowing the engine in a condition called arbitrary number of measures. This structure definition JavaBean as a way to facilitate the initial composition of the facts set of targets, rules engines use these facts to carry out the initial reasoning. Bean can use the method to get access to the value of testing conditions.
Rules quoted by the Java objects need to create it from the WLI processes and rules engine itself are visible. This avoids the JPD these objects and processes in the same package, more precisely, they should be established in the same application procedures as part of the Java projects. Then, the target can be package.class markers in the rules file (. Rls) and the application process JPD.
In our example of the transaction, the transaction will be different groups so that we can implement a block. To achieve this goal, we define that two bean related to the object. The first is the Trade bean, it said individual trading orders. This bean attributes that the share of transactions, as well as the number of shares desired price. Any decision to block the transaction, which may be useful to the value of this should be considered as a method of the public get bean properties, in order to be able to use it in the rules. The second is the Block bean bean, which can store all attribute set according to a coming together of different transactions. This bean attributes include any of the rules can be used to determine big enough orders to information. These attributes can be average price of the transaction or the total dollar share of the total number, and so on.
To our applications achieve functional block, the first to use rules to define whether a transaction only on the need to implement its own sufficient (that is, it is only a single transaction includes the block), or if this is not the case, then What attributes should be used with other transactions will be gathered in order to form a block. Gathered in a transaction to the appropriate block, will be the second call rules engine to determine whether the block completed. For example, suppose we want to have such a rule:
- Rule 1: No more than 5,000 stocks and the single transaction as a block and should be implemented.
- Rule 2: by the same investment managers have the same markings ordered the transaction should be together.
- Rule 3: total value of more than, 000 block should be implemented.
Call rules and conditions associated with the object of the method is easy, as in the following example shows, this is a rule of the conditions:
In this example, if the fact that we have a Trade object, the rules engine will then call its getQuantity () method and the results compared with 5000 integer. If it is greater than or equal to 5000, while the condition is true.
The second part of the rules to meet the conditions for the implementation of the action when the list. The most common moves are: the creation of a new object, it added to the rules engine to assess conditions on the facts. Rules engines continue to rule iteration until drawn from the facts can not be more reasoning; to add new object moves will lead to another round of the conditions assessment cycle. As we will see, you can create any type of object, and the definition of applications with a specific significance of the various types. Here skills, the application designers can define a group of rich enough action to include those who may be called to the rules of writers meet the business needs of the mission.
In our sample application transactions, all movements will be created by the rules will be added to the engine used on the work of the new object. Set some rules to add a simple String object. Said that the target from the original interpreting facts in the middle of the fact that they can be in the rules engine further reasoning, but the process JPD will not explain in any form. Other rules will create Beans.Action category of object. These included rules when conditions will be met implementation of the actual process orders. JPD processes will be implemented and support category known movements gathered order to block the implementation of transactions and transactions. In this simple example, there are only two known in the order: Creating (and implementation) orders, the use of the designated properties gathered a transaction. Rule 2 in front of the action and the use of attributes symbol aggregation manager for the action are as follows:
Response to the movement, and support the process of JPD for the current trading and investment manager for symbol, a symbol to identify with the same investment manager and the non-implementation of the transaction, and these transactions gathered to the same block.
Complete a transaction in the gathering, the second Rules Executor will once again call control rules engine to assess the rules, should decide whether or not to block the implementation of the transaction. 3 based on business rules, the rules are as follows:
This time, our analysis Beans.Block object, and access to property and the amount threshold for comparison. If the condition is met, the use of concentrated work to create an order to add a Beans.Action object, which is the implementation of the notification process orders block the signal.
Let us take a closer analysis process JPD. There are calls for the rules engine Control Send node code. As we can see, the Rules Executor node using a control to assess the rule set, the control returns a iterators. Through its attributes (not given), the controls will filter results, only to return to the subject of Beans.Action category. Through these objects, the code will be extracted action orders and execution of the request for action. As previously mentioned, if the movement is gathering the transaction, the process will be used to update the block as an input on the rules engine start the second call. Through the implementation of appropriate action on the results of the second iteration cycle.
Public void rulesExecutorControlEvaluateRuleSet () throws Exception (/ / Execute the Rules using facts as the input / / # START: CODE GENERATED - PROTECTED SECTION - you can safely / / Add code above this comment in this method. # / / / / Input transform / / Return method call this.results = rulesExecutorControl.evaluateRuleSet (this.facts); / / Output transform / / Output assignments / / # END: CODE GENERATED - PROTECTED SECTION - you can safely / / Add code below this comment in this method . # / / / * Iterate over the results of rules execution. This assumes that results are filtered to return only items of the Beans.Action class. The command property from the Action is expected to be either the string "create," in which case a Block trade can be executed from the single discrete Trade, or it is expected to be a list of attributes describing the Block that this Trade should be incorporated into * / while (results.hasNext ()) (String action = (( Action) results.next ()). getCommand (); if (action.equals ( "create")) (new Block (trade)). execute (); / / single-trade else (/ / Aggregate trade into an intermediate Block trade.aggregate (blockStorage, action); / * Call the rules engine a second time, this time using the resulting Block as the only input. This is to determine if the resulting Block now meets the criteria to execute the order. Again, results are assumed to be filtered by the control to return only the Actions * / Block block = trade.getBlock (); Object blockFacts = new Object [] [1]; blockFacts [0] = block; Iterator blockResults = blockRulesCntl.evaluateRuleSet (blockFacts); while (blockResults.hasNext ()) (action = ((Action) blockResults.next ()). getCommand (); if (action.equals ( "create")) block.execute ();))) )
Dynamic Rules
WebLogic Portal is one of the characteristics of Datasync function, which can be revised after the redeployment to the data in the cluster portal applications. Because the rules engine portal from Datasync storage area was in its rules document, the application's business rules can be in the running to make changes in the system, without the need to stop the application. Datasync and for the update on the data Datasync Web applications of other information, please refer to WebLogic Portal documents.
By default, Datasync Web applications will be deployed in the conventional portal applications. However, our sample application is a WLI process applications, which must be manually included in the Datasync. In the Workshop integrated development environment work in the completion of these Right click Modules folder, and choose Add Module. Then, select the following documentation:
/ Weblogic81/p13n/lib/datasync.war
In the cluster, the application procedure should only Datasync deployed to the management server.
In order to clarify how the operation of the application changes in the rules, including examples of the application of two different rules document, the two documents will be included in the transaction for the poly Manifold optional rules. As already described the default rule (as defined in traderules.rls document), the second set (altrules.rls) definition of the rules are as follows:
- Will be marked in accordance with all the transactions Poly Manifold.
- Implementation includes 3,000 shares or more blocks.
Dynamic to see the implementation of these rules, the first to use the test data provided by the examples of applications running. No need to stop or re-deploy server applications directly to the preservation of the original rules of a new document, and replace documents from the rules:
/ META-INF/data/rulesets/altrules.rls
Copy to:
/ META-INF/data/rulesets/traderules.rls
Examples of data running again, then find a different orders.
Note that the example does not need to run the domain Datasync Web application to update the rules. This is because the sample domain platform to develop model runs. In this mode, automatic polling Datasync / META-INF/data directory and its subdirectories to search changes, the files can be changed automatically re-deployed to the application. In the production domain, the need to use the Web application to the redeployment of data. Recommended steps are, first of all, for all the documents that had been updated to create a jar file, the jar file should be in the root directory data. Then, Datasync Web applications using the Bootstrap Data features include a redeployment to the new rules jar files.
Download
You can download examples of the use of this program's source code: SampleApp.zip (2MB)
Concluding remarks
WLI processes with applications when used together, achieve Portal Rules Engine is a powerful tool business logic. It is very easy to WLI merger process, and can be used to assess the JavaBean rules conditions, or as an extension of the implementation of rules to assess the outcome of the action. Finally, Datasync provided by the characteristics of the dynamic update capability makes business logic more flexible, and can not change under the premise of Java code to adapt to changing needs, so there is no need to deploy applications.
</ Td> </ tr> </ table>↑ Back
Tags: weblogic






