Java IoT Authors: APM Blog, Stackify Blog, XebiaLabs Blog, Liz McMillan, William Schmarzo

Related Topics: Java IoT

Java IoT: Article

Implementing Business Rules in Java

Implementing Business Rules in Java

Twenty years after it first made waves, rule-based technology is making a comeback. Java developers with an eye on the e-commerce market are becoming aware of how integrating business rules and objects in Java can help expand Java into new niches within Web-based applications. This article discusses how rules fit with Java, the types of rule engines available and how a rule engine is used to execute rules for integration into a Java applet or application.

Business rules are the fundamental policies and procedures that define or constrain a business, guiding how it functions. In modern businesses thousands of these policies and procedures are often embedded in application code, with "rule engines" ­ intelligent software components ­ frequently used as the fastest and most effective method to evaluate and execute business rules. Relying on rule engines is usually preferable to embedding rules in application logic, which makes changing and maintaining rules difficult and costly. Developers are increasingly using them, especially to reduce development and maintenance time, increase application performance, and improve application adaptability and flexibility.

In many ways Java is an ideal language for business rules because platform-independent, robust, maintainable, object-oriented Java applications more accurately reflect the structure of a business. Even though the Java language doesn't currently support rules, new tools ­ including freeware ­ are helping to overcome Java's limitations in making changes or updates. For developers, being aware of rule engines and the available tools for Java is highly applicable to the burgeoning e-commerce market. Having an approach for integrating business rules and objects in the Java language can be a boon to expanding Java into new niches within Web-based applications ­ particularly for fast-growing applications like online lending and investment management, and for the many Web personalization solutions ideally suited to business rules and rule engines.

In this article we'll also address design/implementation strategies for business rules and the changing requirements driven by the Web and by e-commerce that mean nonprogrammers must have access to the technology. It's important to note that there are other rule-based software systems, but this article will discuss only Java implementations

Rule-Based Systems: A Brief History
Rules are declarative statements that drive activity in a software application by describing the action or actions to take when a specified set of conditions is met. Rules consist of a left side ­ an "IF/WHEN" condition statement ­ and a right side ­ a "THEN" action statement.

The earliest rules technologies had their roots in artificial intelligence (AI) methodologies. MYCIN (written in LISP), developed at Stanford University in the 1970s, was the first system to use rule-based knowledge representation. Used to diagnose blood diseases and recommend treatments, MYCIN's core concept was the separation of knowledge and control. Knowledge, represented in rules, was separated from the control logic responsible for evaluating and executing the rules.

Rule-based programming reached a pinnacle in the 1980s during the AI boom. At this time many vendors marketed, and many organizations purchased, commercial rule engines. However, the combination of poor performance, an inability to integrate the technology into mainstream computer architectures and the realization that rule-based declarative programming was not the panacea it was purported to be left many organizations disenchanted with the technology.

Although the hype surrounding rule-based programming and expert systems died in the late '80s, the technology continued to be used effectively and quietly for certain types of applications. The current trend toward developing business rule applications is once again leading many mainstream organizations to evaluate the use of rule-based technology more than 20 years after its introduction.

Among the first users of the rules technology was the telecommunications industry, particularly for network management. System and network management applications are typically developed using rules. The following are examples of rules in a telecom network management application:

  • Related alarms: When a switch raises an equipment failure alarm, ignore all communication failure alarms on the associated port.
  • Maintenance activity scheduled: When maintenance activity has been scheduled on a network element, ignore all alarms raised on this piece of hardware between the maintenance start and end time.
  • Critical alarms on sensitive devices: When more than 15 alarms are detected on a network element, notify the network operator by pager. When more than five alarms are detected on a switch, notify the network operator by pager.

The class diagram associated with these rules is shown in Figure 1. If you were to develop an application to implement these rules, how would you do it? Chances are you'd code them into the methods of one or more objects. Listing 1 contains the Java code to implement these rules using a correlateAlarm() method on the Network class. The Network generates the alarms and events, which queue and are processed by the AlarmCorrelator class. The AlarmCorrelator class executes the correlateAlarm() method each time an alarm is processed.

The "correlate Alarm" method contains complex logic that becomes difficult to maintain as the number of rules increases. Typically, hundreds of such rules are implemented in a network management application. The processing time to handle the generated alarms becomes significant since all tests must be evaluated each time an alarm is received. To reduce processing time, rules are often combined into the same "IF" or "SWITCH" statement. This further obscures the code since the one-to-one relationship between the rule specification and the implementation is lost.

This type of application is difficult to develop and maintain using Java or any other procedural programming language. Java objects consist of methods for executing procedures and data members to hold the inputs and outputs of these procedures. They lack a mechanism for capturing rules that determine when and how procedures should be executed.

Enter Rule Engines
A rule engine is a software component designed to evaluate and execute rules. Since it implements all of the logic necessary to perform rule evaluation and execution, the rules can be coded as stand-alone atomic units, separate from and independent of the rest of the application logic. This makes them easier to develop and maintain. Rule engines have a proprietary rule language for writing rules. To implement an application using a rule engine, you write the rules in the rule language and embed the rule engine into your application. The rule engine integrates with the application through an API that controls the loading of rules into the rule engine, the monitoring of application objects referenced by rules and the execution of rules.

As shown in Figure 2, the rule engine as a software component is an object with attributes and methods. An application consists of the application objects and the rule engine object. The rules are loaded into the rule engine by invoking a method on the rule engine object and passing the rules ­ in a file, stream, XML representation or some other form ­ to the rule engine. To evaluate the rules, the rule engine must have visibility to the application objects referenced by rules. To provide this type of visibility, the object data members and methods referenced by rules are usually specified as public. Through a process called asserting, the rule engine's assert method introduces the objects referenced by the rules. Once the objects have been asserted to the rule engine, the rule engine maintains a set of references to the objects. The rule engine's fire rules method is then invoked to cause the rule engine to evaluate all of the loaded rules. Following evaluation, when the conditions of rules are met, the rules are executed or fired, causing their action statements to execute. The action statements of rules can modify the objects referenced by the rule engine, thereby causing more rules to become eligible to fire. The process continues until no more rules are eligible to fire, at which point control returns to the application statement following the invocation of the fire rules method.

Let's go back to the network management example. The network management rules would be implemented using a rule engine by coding the rules shown in Listing 2. These rules are shown using the Java-like syntax of JRules, a rule engine from ILOG Inc. Notice that the syntax of the rule language is declarative and has a one-to-one correspondence with the English-like rule specifications. The rule engine would be integrated into the application as an object and the rules would be loaded, objects asserted and rules fired as described previously.

The rule engine implementation results in a flexible and maintainable application design since the rules are separated from the application logic and can be maintained in a single place. The rule engine implementation is straightforward, with the evaluation of rules automatically performed by the rule engine, eliminating the need for the complex conditional logic required in the application to monitor the network objects. The use of a rule engine improves application performance since the rule engine implements an efficient pattern-matching algorithm to optimize rule evaluation. In this algorithm, known as the RETE algorithm, rules are compiled into a discrimination network that enables conditions shared by multiple rules to be evaluated just once. This enables the processing of thousands of network alarms per second.

Table 1 lists several commercial and shareware rule engines that integrate with the Java language. The rule languages implemented by the rule engines and their mechanisms of integration differ slightly.

Rule engines have been used for event-driven applications such as system and network management and workflow for some time. As we mentioned before, these applications benefit from the RETE pattern-matching algorithm implemented by the rule engine to efficiently evaluate rules against the set of referenced objects. However, rule engines are rapidly gaining acceptance as the preferred approach for implementing a new class of applications known as business rule applications.

Business Rules
The term business rule has been used to define business policies and procedures that describe or constrain the way an organization conducts business. Organizations have thousands of such business rules that define and direct how they manufacture, sell, buy and otherwise transact business. Business rules are everywhere ­ in your corporate charter, your marketing strategies, pricing policies, product and service offerings, and customer relationship management practices as well as in the legal documents that regulate your business and industry.

Business rules can be differentiated from the executable rules coded in the rule language of the rule engine since they directly represent business policy. Other types of rules, such as rules to perform data manipulation or control application-processing flow, can be coded in the rule engine. Furthermore, business rules don't require a rule engine for implementation. They can be implemented in computer systems using a variety of different approaches: for example, they can be implemented in middle-tier application servers in the methods of objects or in database stored procedures. In fact, business rules are implemented throughout computer systems.

To express and model business rules, it's desirable to use an English-like, implementation-independent representation. Such a representation allows nontechnical business people, those responsible for defining and maintaining the business rules, to understand and use them. Minimally, an English-like representation for business rules can help in creating better requirements specifications. However, some applications require that the business rules be represented and externalized in a way that permits business people to create and modify them at execution time. In other words, the application should allow the business rules to be added and changed dynamically by nontechnical users.

For the purposes of this article, we'll refer to applications with these requirements as "business rule applications." This could be clarified further as follows: in order to be considered a business rule application, the application must allow business people to define business rules using an English-like representation. Thus a claims-processing application that allows the user to modify the business rules specifying the handling of auto insurance claims and a portfolio management application that allows the user to create guidelines for buying and selling investments are both business rule applications.

Implementing Business Rules
One method of allowing business rules to be managed by business people at execution time is to create a set of parameter tables that can be stored in databases and edited via a GUI. This method is often used for applications implementing product pricing and bundling. The flexibility gained by this method is very restricted in scope, and when business policy changes fall outside the original application boundaries, substantial programming changes to the application's front end and back end are required.

As stated, a more adaptable approach is to implement the business rules using a rule engine. Since the rule languages offered by the commercial and shareware rule engines are extensive and powerful, this approach provides a more flexible architecture that is unlikely to require change when the scope of the business rules change. Some of the rule engines have an English-like, readable rule language and a rule editor that can be embedded in the application's GUI to provide runtime access to business rules. However, this approach is feasible only for technically savvy business people because the rule languages provided by rule engines are complex and extensive whether they have an English-like or a codelike representation. When users modify business rules, it's difficult for them to determine whether the rule will execute as expected. Using the full syntax of a rule language, users can create a rule that will cause the application to loop endlessly or crash.

To avoid these problems, the application must be designed to restrict the syntax and features of the rule language to a safe subset of the rule language provided by the rule engine. The restricted rule language, known as the business rule language, is usually specific to the application's business domain and uses business terminology particular to that domain. Developing a custom rule editor GUI to guide the user through the specification of rules using the business rule syntax normally provides the capability to define and modify business rules. Two types of rule editors are commonly created for business rule applications. In the first, the business rules are represented as predefined templates that allow the user to specify only the parameters of the business rule. Also used are more sophisticated rule editors that allow the user to define a rule using a business rule syntax and step the user through the rule creation process based on previous choices.

Using either approach, business rules created through the custom business rule editor can then be represented in objects or stored in a parsed format, a text string or XML representation. Executable business rules in the language of the rule engine are then generated from this intermediate representation.

For example, in a customer resource management (CRM), the business user from the marketing department may define a special new promotion for a certain group of customers. The business user creates the rule in an English-like representation using the business rule editor. An executable business rule, in the language of the rule engine, is generated from the business rule language and introduced to the rule engine. The rule engine executes in a CRM Web server-based application, as illustrated in Figure 3.

This approach, although challenging to implement, results in a powerful and flexible application in which the business rules can be changed dynamically while the application executes to immediately implement new sales policies or pricing strategies or to respond to changing regulations imposed by government or regulatory agencies.

Applications Requiring Business Rules
In today's highly competitive business environment, it's becoming increasingly necessary to externalize business rules and put them in the hands of business people. Organizations can no longer afford to wait for IT to implement changes in business policy. To gain and maintain a competitive advantage, companies must be able to immediately respond to the requirements of their customers and partners and to the initiatives and actions of their competitors.

Business rule applications exist in virtually every business domain. Let's look at a selection of typical business rule applications in the areas of e-commerce personalization, loan underwriting and customer relationship management.

E-Commerce Personalization
As more companies extend their sales and marketing functions from traditional channels to the Web, the capability of personalizing each customer's experience becomes essential in order to attract, satisfy and retain customers. With the Web comes the ability to apply the concepts of one-to-one marketing and to replace the old "one size fits all" approach with individually tailored offers.

Rule-based personalization uses specific information about individual Web site visitors to precisely tailor the content displayed. By capturing the needs, interests, preferences and motivations of the individuals that visit a Web site, and applying business rules against that information, visitors can be provided with information and recommendations that will be relevant to them. Web merchants can make visitors aware of interesting promotions, offer them discounts based on their purchasing history and take advantage of opportunities to cross-sell and upsell without offending them. Here are some typical rules:

  • If Shopping Cart contains more than $100 worth of CDs, give $5 off the next purchase.
  • If Customer purchased a Pilot III last week, show all Pilot accessories.
  • If Customer traveled to Europe within the last year, send notification of European travel promotions.
Some larger merchants are developing their own personalization solutions using business rules. By externalizing the business rules, they create a more flexible solution that can be changed by their marketing personnel, enabling them to immediately implement new promotions or offer new products. Vendors such as BEA and IBM are offering flexible personalization solutions that allow the merchant to define and modify these types of rules in their respective WebLogic Commerce Server and WebSphere Commerce Suite. Using these personalization solutions, merchants can create Web sites that intelligently interact with customers.

Mortgage Loan Underwriting
Lenders have been developing rule-based underwriting applications for the last decade. In these systems, rules are used to simulate the decision-making process of a human underwriter. As competitive pressures have increased in the mortgage industry, lenders have developed more loan products to offer flexible alternatives to homebuyers. At the same time, the credit policy organizations within lending institutions are defining new rules to ensure that risk is managed at an acceptable level for these new loan products. Additionally, lenders must frequently comply with regulations imposed by the federal government and the policies of the secondary mortgage institutions.

To implement and maintain the large number of rules required in these underwriting applications, many lenders are developing business rule applications that allow the marketing department to define new loan products and credit policy to define new risk management rules. For example:

  • If borrower is a first-time homebuyer, offer the no-down-payment option.
  • If the lien type is a second mortgage, the borrower's occupancy status must be principal residence.
  • If the transaction is a cash-out refinance, the loan-to-value ratio must be less than or equal to 85%.

Telecom Customer Care and Billing
Competition and deregulation have combined to make the customer all-important to the telecom industry. In order to excel, service providers must continually offer the customer new services at competitive prices. Moreover, they must be able to react immediately to market changes from competition, customer demand or technological advances. These market pressures force the companies to constantly search for new ways to stimulate business through service packages and pricing schemes, and to run aggressive sales campaigns with attractive promotions and discounts.

The most innovative applications for customer care and billing are business rule applications because they offer time-saving, cost-effective ways to impart outstanding flexibility and customization for managing ever-changing rates and promotions. Business rules help companies secure customer loyalty by allowing them to target individual needs.

The long distance market is extremely competitive. To attract and keep customers, companies are offering special rates and discounts. For example:

  • If destination is a preferred number, give a 50% discount on call.
  • If customer is a member of nickel nights plan and call time is after 5 p.m., billing rate is $0.05 per minute.
To be effective, these promotions must be incorporated into the billing system. Externalizing the business rules in the billing system and allowing the marketing department to define and modify them provides this flexibility.

Implementing business rules using a rule engine is an increasingly popular approach due to their ability to create a flexible, adaptable, high-performance application. In this article we discussed rules and rule engines and how to integrate the rule engine into a Java application. We also examined how business rules applications are developed using a rule engine. In the second installment of this series we'll examine in more depth the implemention of business rules using Java rule engines.

More Stories By Colleen McClintock

Colleen McClintock, product manager for JRules at ILOG, Inc., has more than 15 years of industry
experience specializing in planning, design and implementation of rule-based systems and the integration of rules and objects.

More Stories By Carole Ann Berlioz

Carole Ann Berlioz, a field sales engineer for the Telecommunications Business Unit at ILOG, Inc., has over five years of international experience in design, recommendation and development of data visualization, intelligent agents and integrated architecture components using OO technologies.

Comments (0)

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.

@ThingsExpo Stories
In his session at 21st Cloud Expo, Carl J. Levine, Senior Technical Evangelist for NS1, will objectively discuss how DNS is used to solve Digital Transformation challenges in large SaaS applications, CDNs, AdTech platforms, and other demanding use cases. Carl J. Levine is the Senior Technical Evangelist for NS1. A veteran of the Internet Infrastructure space, he has over a decade of experience with startups, networking protocols and Internet infrastructure, combined with the unique ability to it...
"There's plenty of bandwidth out there but it's never in the right place. So what Cedexis does is uses data to work out the best pathways to get data from the origin to the person who wants to get it," explained Simon Jones, Evangelist and Head of Marketing at Cedexis, in this SYS-CON.tv interview at 21st Cloud Expo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA.
"Cloud Academy is an enterprise training platform for the cloud, specifically public clouds. We offer guided learning experiences on AWS, Azure, Google Cloud and all the surrounding methodologies and technologies that you need to know and your teams need to know in order to leverage the full benefits of the cloud," explained Alex Brower, VP of Marketing at Cloud Academy, in this SYS-CON.tv interview at 21st Cloud Expo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clar...
Large industrial manufacturing organizations are adopting the agile principles of cloud software companies. The industrial manufacturing development process has not scaled over time. Now that design CAD teams are geographically distributed, centralizing their work is key. With large multi-gigabyte projects, outdated tools have stifled industrial team agility, time-to-market milestones, and impacted P&L stakeholders.
Gemini is Yahoo’s native and search advertising platform. To ensure the quality of a complex distributed system that spans multiple products and components and across various desktop websites and mobile app and web experiences – both Yahoo owned and operated and third-party syndication (supply), with complex interaction with more than a billion users and numerous advertisers globally (demand) – it becomes imperative to automate a set of end-to-end tests 24x7 to detect bugs and regression. In th...
"Akvelon is a software development company and we also provide consultancy services to folks who are looking to scale or accelerate their engineering roadmaps," explained Jeremiah Mothersell, Marketing Manager at Akvelon, in this SYS-CON.tv interview at 21st Cloud Expo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA.
"MobiDev is a software development company and we do complex, custom software development for everybody from entrepreneurs to large enterprises," explained Alan Winters, U.S. Head of Business Development at MobiDev, in this SYS-CON.tv interview at 21st Cloud Expo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA.
SYS-CON Events announced today that CrowdReviews.com has been named “Media Sponsor” of SYS-CON's 22nd International Cloud Expo, which will take place on June 5–7, 2018, at the Javits Center in New York City, NY. CrowdReviews.com is a transparent online platform for determining which products and services are the best based on the opinion of the crowd. The crowd consists of Internet users that have experienced products and services first-hand and have an interest in letting other potential buye...
"IBM is really all in on blockchain. We take a look at sort of the history of blockchain ledger technologies. It started out with bitcoin, Ethereum, and IBM evaluated these particular blockchain technologies and found they were anonymous and permissionless and that many companies were looking for permissioned blockchain," stated René Bostic, Technical VP of the IBM Cloud Unit in North America, in this SYS-CON.tv interview at 21st Cloud Expo, held Oct 31 – Nov 2, 2017, at the Santa Clara Conventi...
SYS-CON Events announced today that Telecom Reseller has been named “Media Sponsor” of SYS-CON's 22nd International Cloud Expo, which will take place on June 5-7, 2018, at the Javits Center in New York, NY. Telecom Reseller reports on Unified Communications, UCaaS, BPaaS for enterprise and SMBs. They report extensively on both customer premises based solutions such as IP-PBX as well as cloud based and hosted platforms.
"Space Monkey by Vivent Smart Home is a product that is a distributed cloud-based edge storage network. Vivent Smart Home, our parent company, is a smart home provider that places a lot of hard drives across homes in North America," explained JT Olds, Director of Engineering, and Brandon Crowfeather, Product Manager, at Vivint Smart Home, in this SYS-CON.tv interview at @ThingsExpo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA.
Coca-Cola’s Google powered digital signage system lays the groundwork for a more valuable connection between Coke and its customers. Digital signs pair software with high-resolution displays so that a message can be changed instantly based on what the operator wants to communicate or sell. In their Day 3 Keynote at 21st Cloud Expo, Greg Chambers, Global Group Director, Digital Innovation, Coca-Cola, and Vidya Nagarajan, a Senior Product Manager at Google, discussed how from store operations and ...
It is of utmost importance for the future success of WebRTC to ensure that interoperability is operational between web browsers and any WebRTC-compliant client. To be guaranteed as operational and effective, interoperability must be tested extensively by establishing WebRTC data and media connections between different web browsers running on different devices and operating systems. In his session at WebRTC Summit at @ThingsExpo, Dr. Alex Gouaillard, CEO and Founder of CoSMo Software, presented ...
WebRTC is great technology to build your own communication tools. It will be even more exciting experience it with advanced devices, such as a 360 Camera, 360 microphone, and a depth sensor camera. In his session at @ThingsExpo, Masashi Ganeko, a manager at INFOCOM Corporation, introduced two experimental projects from his team and what they learned from them. "Shotoku Tamago" uses the robot audition software HARK to track speakers in 360 video of a remote party. "Virtual Teleport" uses a multip...
A strange thing is happening along the way to the Internet of Things, namely far too many devices to work with and manage. It has become clear that we'll need much higher efficiency user experiences that can allow us to more easily and scalably work with the thousands of devices that will soon be in each of our lives. Enter the conversational interface revolution, combining bots we can literally talk with, gesture to, and even direct with our thoughts, with embedded artificial intelligence, whic...
SYS-CON Events announced today that Evatronix will exhibit at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Evatronix SA offers comprehensive solutions in the design and implementation of electronic systems, in CAD / CAM deployment, and also is a designer and manufacturer of advanced 3D scanners for professional applications.
Leading companies, from the Global Fortune 500 to the smallest companies, are adopting hybrid cloud as the path to business advantage. Hybrid cloud depends on cloud services and on-premises infrastructure working in unison. Successful implementations require new levels of data mobility, enabled by an automated and seamless flow across on-premises and cloud resources. In his general session at 21st Cloud Expo, Greg Tevis, an IBM Storage Software Technical Strategist and Customer Solution Architec...
To get the most out of their data, successful companies are not focusing on queries and data lakes, they are actively integrating analytics into their operations with a data-first application development approach. Real-time adjustments to improve revenues, reduce costs, or mitigate risk rely on applications that minimize latency on a variety of data sources. In his session at @BigDataExpo, Jack Norris, Senior Vice President, Data and Applications at MapR Technologies, reviewed best practices to ...
An increasing number of companies are creating products that combine data with analytical capabilities. Running interactive queries on Big Data requires complex architectures to store and query data effectively, typically involving data streams, an choosing efficient file format/database and multiple independent systems that are tied together through custom-engineered pipelines. In his session at @BigDataExpo at @ThingsExpo, Tomer Levi, a senior software engineer at Intel’s Advanced Analytics gr...
When talking IoT we often focus on the devices, the sensors, the hardware itself. The new smart appliances, the new smart or self-driving cars (which are amalgamations of many ‘things’). When we are looking at the world of IoT, we should take a step back, look at the big picture. What value are these devices providing? IoT is not about the devices, it’s about the data consumed and generated. The devices are tools, mechanisms, conduits. In his session at Internet of Things at Cloud Expo | DXWor...