COMPOSITE EVENT PROCESSING IN A FUZZY XML DATABASE SYSTEM Hemal Mehta B.E, Gujarat University, India, 2007 PROJECT Submitted in partial satisfaction of the requirements for the degree of MASTER OF SCIENCE in COMPUTER SCIENCE at CALIFORNIA STATE UNIVERSITY, SACRAMENTO SPRING 2011 COMPOSITE EVENT PROCESSING IN A FUZZY XML DATABASE SYSTEM A Project by Hemal Mehta Approved by: __________________________________, Committee Chair Ying Jin, Ph.D __________________________________, Second Reader Jinsong Ouyang, Ph.D ____________________________ Date ii Student: Hemal Mehta I certify that this student has met the requirements for format contained in the University format manual, and that this project is suitable for shelving in the Library and credit is to be awarded for the Project. __________________________, Graduate Coordinator Nikrouz Faroughi, Ph.D Department of Computer Science iii ________________ Date Abstract of COMPOSITE EVENT PROCESSING IN A FUZZY XML DATABASE SYSTEM by Hemal Mehta In the real world, information can be ambiguous. Fuzzy logic is used to describe information in the way near to natural languages. The current system supports simple mutating events and temporal events. In this project, I have implemented a system which supports composite events using fuzzy logic over XML database systems. Composite event consists of collection of events that satisfy some pattern. A composite event is created by combining base events. This project defines different types of composite events, specify the decomposition constraints, and handle the processing of composite events for fuzzy active rules. The project has an interface for specifying a rule and an interface for users to specify queries. The queries are checked with the event handler, and if matched, composite event occurs and an action based on that event also occurs. _______________________, Committee Chair Ying Jin, Ph.D _______________________ Date iv DEDICATION To my father and mother who let me pursue my dreams. v ACKNOWLEDGEMENTS I would like to express my gratitude to all those people who gave me the possibility to complete this project. I would like to thank Dr. Ying Jin, my project advisor, whose help, valuable suggestions and encouragement helped me in all the time of the project development and research. It was pleasure that Dr. Jin allowed me to work on this project with her. I am very grateful for her support with flexibility of time which helped me work fulltime along with researching on the project. Her time and support really helped in completion of this project. I would also like to thank Dr. Jinsong Ouyang for being my second reader. I would also like to thank Dr. Nikrouz Faroughi, Graduate Coordinator of Computer Science Department, for his support. Finally, I would like to thank my family and friends, especially Hitesh Wadhwani and Bhumi Patel, and colleagues, for their constant support and inspiration during this project. vi TABLE OF CONTENTS Page Dedication ........................................................................................................................................ v Acknowledgements ......................................................................................................................... vi List of Figures ................................................................................................................................. ix Chapter 1. INTRODUCTION ....................................................................................................................... 1 2. RELATED WORK ...................................................................................................................... 3 2.1 Fuzzy Concepts Overview................................................................................................... 3 2.2 Composite Events ................................................................................................................ 4 2.3 Tools and Technology ......................................................................................................... 5 2.3.1 XML........................................................................................................................... 5 2.3.2 Oracle Berkeley DB XML Database ......................................................................... 6 2.3.3 XQuery..................................................................................................................... 10 2.3.4 Boolean Parser ......................................................................................................... 12 3. ARCHITECTURE AND LANGUAGE .................................................................................... 13 3.1 System Architecture .......................................................................................................... 13 3.2 Bookstore Application ....................................................................................................... 15 3.3 Composite Event and Rule Definition............................................................................... 16 4. EVENT PROCESSING AND IMPLEMENTATION ............................................................... 23 vii 5. TEST AND RESULTS .............................................................................................................. 29 5.1 Validate Rule Insert ........................................................................................................... 29 5.2 Validate Rule and Event Processing.................................................................................. 33 6. SUMMARY AND FUTURE WORK........................................................................................ 41 Appendix A Bookstore Application............................................................................................... 43 Bibliography .................................................................................................................................. 45 viii LIST OF FIGURES Page Figure 1 Oracle Berkeley DB XML................................................................................................. 7 Figure 2 Sample Java code to interact with XML DB ..................................................................... 9 Figure 3 Sample Java code for XPath query .................................................................................. 11 Figure 4 System Architecture ........................................................................................................ 13 Figure 5 Sample Bookstore Database ............................................................................................ 15 Figure 6 An Example of Event.xml file ......................................................................................... 17 Figure 7 An Example of validevents.xml file ................................................................................ 18 Figure 8 An Example of Composite Events................................................................................... 19 Figure 9 Event file for Order_Conflict Rule .................................................................................. 20 Figure 10 Crule file for Order_Conflict rule.................................................................................. 20 Figure 11 Crule file for Special_Discount rule .............................................................................. 21 Figure 12 Runtime event for composite event processing ............................................................. 24 Figure 13 An Example of eventlog.xml file .................................................................................. 25 Figure 14 Rule Insert 1 .................................................................................................................. 30 Figure 15 Rule Insert 2 .................................................................................................................. 31 Figure 16 Rule Insert 3 .................................................................................................................. 32 Figure 17 Event 1 for Discount Rule ............................................................................................. 34 Figure 18 Event 2 for Discount Rule ............................................................................................. 35 ix Figure 19 Event 1 for Order Conflict Rule .................................................................................... 36 Figure 20 Event 2 for Order Conflict Rule .................................................................................... 37 Figure 21 Event 1 for Special Discount Rule ................................................................................ 38 Figure 22 Event 2 for Special Discount Rule ................................................................................ 39 Figure 23 Event 3 for Special Discount Rule ................................................................................ 40 x 1 Chapter 1 INTRODUCTION Fuzzy logic theory was first presented by L. A. Zadeh [1]. Traditional XML databases have support for the storage and management of crisp XML data. We can specify the schema, store data, and specify queries in a precise manner. In the real world, there exists a lot ambiguous data, which might not be convenient to define precisely and store directly in traditional databases. For an example, “The Water is warm”. Here water is the fuzzy or a linguistic variable and hot is the linguistic value. The converted crisp logical statement can be, “The Water is 110F degree”. Active database systems extend traditional database systems by providing the functionality of event management [2]. Users specify the event occurred within the database, and also what kind of condition-action to handle the event using active rules. Once a rule is defined, the database system executes the rule automatically upon the occurrence of the defined event. An active rule consists of three components: an event, a condition, and an action. The condition specifies the queries over the database. Action consists of Insert, Update, Select query or combination of them over the database. Usually, when the condition is true (or non-empty result), the action can be performed to update the databases or execute application procedures. Active rules are supported in a limited form in commercial relational database systems, such as Oracle [3]. Research in projects by S. Veerappan [4] and C. Madalli [5] incorporated a rule specification and execution environment in a fuzzy XML database. The research presented in the project by S. Veerappan [4] and C. Madalli [5] incorporated both fuzzy data and querying fuzzy data using fuzzy expressions within an XQuery based query statement. 2 This project extends the work of S. Veerappan [4] and C. Madalli [5] by introducing composite events into the system. In a real world application, sometimes it is a combination of multiple events, which is called a composite event and which determines a situation to react, rather than a single one. Composite event consists of collection of events that satisfy some pattern. A composite event is created by combining base events. Base events are also called primitive events. Base events can be in conjunction, disjunction, or sequence etc. [6]. A composite event is derived by computational processes. This project defines different types of composite events, specifies the decomposition constraints, and handles the processing of composite events for fuzzy active rules. The implementation revises the event handler component to reflect event composition. The code was written in java, and XML files are used for rule engine specification. The java code is written using Open Source Eclipse IDE, which is an open source IDE for java developers. This project implemented an interface for specifying a rule and an interface for users to specify queries. The current version implementation was built using Oracle Berkeley DB XML [7]. The rest of this report is organized as follows. Chapter 2 introduces and presents the related study, technology and tools used for this project. Chapter 3 covers the system architecture, sample bookstore application database, representation of composite rules, and required XML files structure. Chapter 4 explains the implementation and composite rule processing. Chapter 5 addresses the various test cases used to test the application. Chapter 6 concludes this report with project summary and future work. 3 Chapter 2 RELATED WORK 2.1 Fuzzy Concepts Overview Fuzzy logic was introduced by L. A. Zadeh [1], while he was trying to contemplate how to program a software for handwriting recognition, and has been applied to many research fields and applications. The membership function in a fuzzy set is not a matter of true or false but is a matter of degree. As explained in the previous example, “The water is Warm”, Warm explains a degree of an attribute temperature of water. Human can manipulate and understand this fuzzy logic easily, but it needs additional processing for a program and a database. Linguistic variable is a variable whose values are words or sentences in a natural or artificial language. The linguistic variables are those where the meaning remain constant but form varies. Linguistic variables represent both the input and output variables of the system you are controlling. For example, a room heater, you will have two input linguistic variables: current temperature and desired temperature, and one output linguistic variable: heater setting. Every linguistic variable has a range of expected values. For example, the range of current temperature can be 40 to 100 degrees. Out of that range, the range of desired temperature can only be 50 to 80 degrees. A fuzzy variable becomes a linguistic variable when it is modified with descriptive words, such as fast, very slow, real low, very big, negative small etc. The main function of linguistic variables is to provide a means of working with the complex systems as being too complex to handle by conventional mathematics and engineering formulas. Linguistic variables 4 appear in control systems with feedback loop and can be related to each other with conditional, "if-then" statements. For example, if the room is too heated, then turn off the room heater. Fuzzy logic helps extending computer capabilities to deal with inaccurate and ambiguous information. A fuzzy algorithm is a procedure, usually a computer program, made up of executable statements relating linguistic variables and control actions. In the project work by C. Madalli [5], he explained rule processing over simple mutation events. And in the project work by S. Veerappan [4], she explained the support of fuzzy data storage. Studies on composite events have been conducted in relational databases, such as [8], and enterprise application integration environments [9]. This project introduces rule processing on composite events with fuzzy logic. Fuzzy logic is an area of soft computing, enabling a computer system to reason with uncertainty. A fuzzy inference system consists of set of if-then rules defined over fuzzy sets. Fuzzy sets generalize the concept of traditional set by allowing the membership degree to be a value between 0 and 1 [1]. 2.2 Composite Events M. Bernauer, G. Kappel, and G. Kramler[10] explored composite event detection in XML Documents. They explained composite event detection using event algebra Snoop, as it is extensible and well defined for XML. In another research by G. Xu, J. Ma and T Huang [11], a XML-based composite event model that consists of the temporal logical model and the event composite pattern was presented. Based on the composite event model, a subscription language (EXML-QL) is introduced by extending XML-QL language to support the XML-based composite event computing. None of these researches shows specifying an action on composite event detection. 5 Primitive events might not be sufficient in all the applications. Sometimes, rather than a single primitive event, a combination of multiple events is required to determine a situation to react. Composite events are the composition of primary mutation events. Primary events can be composed by three operators: AND, OR, and SEQ (sequence) in our system. For example, if a customer orders a same book twice within 24 hours, and the book quantity is high, then give 20% discount on the second order. In another example, one event is “a user creates a book order to order a book” (event 1); another event is “purchase order of the bookstore is deleted” (event2). An example rule triggered by the event is: if the customer order and the purchase order are for the same book, and if the book quantity is 0 and book popularity is very low (so it is not meaningful for the bookstore to order more), notify the customer that they are unable to fulfill the order or their order will be cancelled. 2.3 Tools and Technology 2.3.1 XML XML is a markup language for documents containing structured information [12]. XML can be defined by a number of related specifications [12]: Extensible Markup Language (XML) 1.0 This defines the syntax of XML. XML Pointer Language (XPointer) and XML Linking Language (XLink) This defines a standard way to represent links between XML resources. In addition to simple links, like HTML's <a> tag, XML has a way to define links between multiple 6 resources and links between read-only resources. XPointer describes how to address a resource and XLink describes how to associate two or more resources. Extensible Style Language (XSL) XSL defines the standard style sheet language for XML. 2.3.2 Oracle Berkeley DB XML Database Berkeley DB enables the development of data management solutions with custom requirements[7]. Berkeley DB has a collection of well-proven building-block technologies, which can address any application need varying from the hand-held device to the datacenter, from a local storage solution to a world-wide distributed one, from kilobytes to petabytes. Berkeley DB’s software library is written in C. It has API bindings for various languages like, C++, PHP, Java, Ruby, Perl, Python, Smalltalk, Tcl, and most other programming languages. 7 Oracle Berkeley DB XML BDB XML API Documents Indexes XML Content Nodes XQuery Optimizer Query Execution Container Figure 1 Oracle Berkeley DB XML Berkeley DB XML supports XQuery 1.0 and XPath 2.0, XML Namespaces, schema validation, naming and cross-container operations and document streaming. The XQuery engine uses cost-based query optimizer and supports pre-compiled query execution with embedded variables. Large documents can be stored intact as well as can be broken up into nodes, enabling more efficient retrieval and partial document updates. Berkeley DB XML supports flexible indexing of XML nodes, elements, attributes and meta-data. This also enables the fastest, most efficient retrieval of data. Berkeley DB XML provides transactional access, automatic recovery, content compression, on-disk data encryption with AES, fail-over to a hot standby, and replication for high availability. Store, index and query key/value meta-data related to the XML 8 documents as well. Berkeley DB XML provides fast, reliable and scalable persistence for applications that need to manage XML content. Figure 2 is an example of code, how you can create an XMLManager class to do database operations using java. You can use multiple XMLManager to do multiple operations. When we have a user event, and a condition action event of a fuzzy rule, we need to create XMLManager to handle multiple events. XmlDocuments are stored as individual nodes in the container. It means, each record in the underlying database contains a single leaf node, its attributes and attribute values if any, and its text nodes, if any. myManager.createQueryContext() is used to create a query context, and myManager.Query method is used to execute a XPath query on the DB. Always close the XMLContainer and XMLManager when no longer needed. 9 import com.sleepycat.dbxml.XmlContainer; import com.sleepycat.dbxml.XmlException; import com.sleepycat.dbxml.XmlManager; ... XmlManager myManager = null; XmlContainer myContainer = null; XmlContainer myContainer2 = null; try { myManager = new XmlManager(); myManager.setDefaultContainerType(XmlContainer.NodeContainer); // Open the container. If it does not currently exist, // then create it. myContainer = myManager.createContainer(strDBPath + "data.dbxml"); // Obtain a second handle to the container. This container is closed // when its last handle is closed. myContainer2 = myManager.openContainer(strDBPath + "data.dbxml"); // Get a query context XmlQueryContext context = myManager.createQueryContext(); myManager.query(XPathQuery, context); } catch (XmlException e) { // Exception handling goes here } finally { try { if (myContainer != null) { myContainer.close(); } if (myContainer2 != null) { myContainer2.close(); } if (myManager != null) { myManager.close(); } } catch (XmlException ce) { // Exception handling goes here } } Figure 2 Sample Java code to interact with XML DB 10 2.3.3 XQuery XQuery is a query and functional programming language, designed to query collections of XML data[13]. XQuery is a standardized language for relating documents, databases, Web pages and almost everything. XQuery is very widely implemented, powerful and yet easy to learn[14]. Using XQuery, one can perform database operations like, Insert, Update, Delete, on an XML database or a file. XQuery is built on XPath and is a W3C recommendation. In this project, most of XML operations on files, such as rules file or an event file, are done using XQuery. <cond_action> part in a rule can easily be specified using XQuery. Similar to traditional databases, XQuery also has sort or join functions which can be performed on XML data. In this project, there is a separate XMLUtility.java file which contains functions for doing XPath queries on a file or a XML document in a string format. EvaluateFileXPathQuery and EvaluateStringXPathQuery are the two functions which serves this purpose. EvaluateFileXPathQuery function takes filename and an XPath query as its arguments. Similarly a string XML document and a XPath query are the arguments to the EvaluateStringXPathQuery. Figure 3 shows a code example for EvaluateFileXPathQuery. 11 public static Object EvaluateFileXPathQuery(String fileName, String XPathExpr, String strResultType) { try { DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance(); domFactory.setNamespaceAware(true); DocumentBuilder builder = domFactory.newDocumentBuilder(); Document doc = builder.parse(fileName); XPath xpath = XPathFactory.newInstance().newXPath(); // XPath Query for showing all nodes value XPathExpression expr = xpath.compile(XPathExpr); Object result = null; if(strResultType.toLowerCase() == "string") result = expr.evaluate(doc, XPathConstants.STRING); else result = expr.evaluate(doc, XPathConstants.NODESET); return result; } catch(ParserConfigurationException e) { e.printStackTrace(); } catch(SAXException e) { e.printStackTrace(); } catch(IOException e) { e.printStackTrace(); } catch(XPathExpressionException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } return null; } Figure 3 Sample Java code for XPath query 12 2.3.4 Boolean Parser JBooleanExpression is an opensource, simple Java API to evaluate a Boolean String Expression like "!true&&false||true" [15]. JBooleanExpression parses a boolean string expression and returns a boolean primitive type. When we specify an <event_composion> as “event1 and event2 within-24-hours”, the project code checks for event1 and event2 with current event or in the event log, and then converts that into a Boolean String Expression. This expression is then evaluated with JBooleanExpression, to determine if the rule matches or not. 13 Chapter 3 ARCHITECTURE AND LANGUAGE 3.1 System Architecture The system architecture is shown in Figure 4. Users define fuzzy active rules using the Rule Specification Interface. The Rule Parser parses user-defined rules and stores the rules in the rule repository. The Fuzzy Metadata keeps track of meta-knowledge over vague representation of data. In the fuzzy logic, a linguistic variable (e.g. “temperature”) has a linguistic value (e.g. “high”). Linguistic variable is correlated to numerical values through membership functions. Membership functions can be formed in different distributions. Other architecture components consult the metadata at static and run time for parsing and execution. Query Interface Active Rule Specification Interface Event Handler Primitive Event Handler Temporal Event Handler Composite Event Handler Event and Rule Parser Fuzzy Query Processor Fuzzy Metadata Active Rule Repository Rule Engine Figure 4 System Architecture XML DB 14 At static time, Active Rule Specification interface is used for specifying Rules. the format of the rules files will be explained in the section 3.3. The interface has two options to specify rules. First is, user can insert entire rule node, in an XML format. Another option is to add XML elements individually, where user can specify number of events, and can enter element details for each of those events. Event and Rule Parser is a java file, which processes the rule. Fuzzy to Crisp rule conversion is done in this part. Then the rule is saved in the Active Rule Repository. The Active Rule Repository contains a number of XML files. The rules are broken down in XML files. Crule.xml file contains the rule with event names. Event.xml file has description for those events with filtering parameters. This way user can specify a Fuzzy rule using any number of events. At runtime, Query Interface is used to accept a user input. The input can be Insert, Replace or Delete query. The query is in a XQuery format, as we are using XML DB. The user input is then parsed through Event Handler component of the system. This project introduced Composite Event Handler, with retaining functionality of Primitive Event Handler and Temporal Event Handler from the projects by S. Verappan [4] and C. Madalli[5]. Fuzzy Query Processor checks the user input against Fuzzy Metadata, and then passes it to the Rule Engine. The Rule Engine compares the user query against Active Rule Repository. It determines, if it is an event or not, and whether the query can trigger a rule, comparing with the Rule Base. The Fuzzy Query Processor, executes the user query to the XML DB. The Rule Engine executes conditions and action(s), over the XML DB. 15 3.2 Bookstore Application This project uses a Bookstore application to demonstrate the fuzzy logic processing. The Bookstore database is an XML database, created using Berkeley DB XML [7]. This database contains a series of nodes related to Books. Following is an example of a sample Bookstore database. <Bookstore> <Book> <book_ID>1</book_ID> <title>Harry Potter and the Order of the Phoenix</title> <author> <author_fname>J.K.</author_fname> <author_lname>Rowling</author_lname> </author> <price>10</price> <year_published>2004</year_published> <publisher>Scholastic, Inc.</publisher> <genre>Fiction</genre> <popularity>LOW</popularity> <popularity_min>25.0</popularity_min> <popularity_max>75.0</popularity_max> <quantity_in_stock>3200</quantity_in_stock> </Book> </Bookstore> Figure 5 Sample Bookstore Database Purchase_Order is used to specify the book ordered from the publisher. A Purchase_Order node contains information on the orders made for books in the bookstore database. Purchase_Order node has the attributes such as Book_Id, quantity, the date the order was placed, and the price at which these copies are being purchased. The order_filled information signifies whether the bookstore received the book from the publisher or not. 16 Also whenever a Sales Record is created, Sales_Order entry is made after corrosponding Book. Sales_Record node contains information on the books sold. Sales_Record node has the following attributes: Order Id, Book Id, Customer Id, quantity, sale price. A Discount_information node contains data about the discounts that have been offered for a book in the inventory. Discount_information node has these attributes: Book Id, discount_percent, validity_start_date, validity_end_date etc. The attributes of Discount_information node provide information on the discounted books and the time period between which the discount is valid. There can be any number of nodes related to a book can be specified. User can insert these nodes using XPath query. The database can have fuzzy values for attributes like popularity or quantity of a book. The database structure can be found in Appendix A. 3.3 Composite Event and Rule Definition To construct a composite event, there has to be at least two primitive events. For example, a discount rule explained in the Section 2.2, if a customer orders a same book twice within 24 hours and the book quantity is high then give 20% discount on the second order, has two similar primitive events. In this example, both the primitive events are Customer Order. Another example would be, if the customer order and the purchase order are for the same book, and if the book quantity is 0 and book popularity is very low notify the customer that they are unable to fulfill the order or their order will be cancelled. Here first primitive event is Customer Order, and second primitive event is, purchase order. 17 There can be any number of primitive events, more than two, to construct a composite event. In this project, event.xml file is used to specify primitive events. Following is an example of event.xml file. <event> <event_name>event1</event_name> <event_type>insert</event_type> <event_node>Customer_Order</event_node> <filter_attribute1>customer_ID</filter_attribute1> <doc>c_order1</doc> </event> <event> <event_name>event2</event_name> <event_type>insert</event_type> <event_node>Customer_Order</event_node> <filter_attribute1>customer_ID</filter_attribute1> <doc>c_order2</doc> </event> Figure 6 An Example of Event.xml file All the valid events, that can be logged by eventlog.xml file, are checked with validevents.xml file as shown in Figure 7 below. Validevents.xml restricts the events that can be logged by eventlog.xml. If the event enter by a user matches with an event in validevents.xml file, that event will be logged in the eventlog.xml file, which can be used for future processing when checking for composite events. 18 <event> <event_type>insert</event_type> <event_node>Customer_Order</event_node> </event> <event> <event_type>insert</event_type> <event_node>Purchase_Order</event_node> </event> Figure 7 An Example of validevents.xml file Figure 8 shows Discount Rule as explained in the Section 2.2. This rule consists of a composite event which has two primitive events: event1 and event2. Each event has the same format as the simple events. <event_composition> specifies how to compose the primitive events defined in Figure 6. When we need to use more than two events, we can use parentheses to specify the nesting of composition, for e.g., (event1 AND event2) SEQ event3. For each composition, users can define the difference of time between two events. For example, “event1 AND event2 WITHIN-24-hours” specifies that only when event1 and event2 happen within 24 hours, the rule condition is satisfied. We can use minutes, hours, and days for the time constraints. One composite event can trigger multiple rules. Users can specify <priority> to define rule execution orders. 1 is the highest priority to be executed first. <cond_action> specifies the condition to check and the action to perform. <cond_action> part is based on the XQuery standard. Fuzzy expressions can be specified in the condition evaluation. For example, quantity_in_stock = HIGH. The underlying storage of the popularity can be a linguistic value, or a crisp value. External Variables c_order1 and c_order2 are identified by “#” in the rule. They are event binding variables passed from the event. In Figure 8, the user has defined c_order1 and 19 c_order2 in <doc> to specify which documents to insert. If two orders are from the same customer and for the same book, it means the condition in condition action matched, a discount will be given. <rule> <rulename>Discount_on_purchase</rulename> <event_composition> event1 SEQ event2 within-24-hours </event_composition> <filter1>=</filter1> <priority>1</priority> <cond_action>let $book := collection("data")/Bookstore return if(#c_order1/Customer_Order/book_ID = #c_order2/Customer_Order/book_ID and #c_order1/Customer_Order/customer_ID = #c_order2/Customer_Order/customer_ID and $book[book_ID = #c_order1/Customer_Order/book_ID]/quantity_in_stock/text() = HIGH) then let $val := $book/Customer_Order[order_ID/text() = #c_order2/Customer_Order/order_ID]/order_total/text() return if($val > 0) then replace value of node $book/Customer_Order[order_ID/text() = #c_order2/Customer_Order/order_ID]/order_total/text() with ($val - ($val * 10 div 100)) else () else() </cond_action> </rule> Figure 8 An Example of Composite Events Another example of Order_Conflict rule contains two primitive events: event3 and event4 as follows: 20 <event> <event_name>event3</event_name> <event_type>insert</event_type> <event_happen>after</event_happen> <event_node>Customer_Order</event_node> <filter_attribute1>book_ID</filter_attribute1> <doc>c_order</doc> </event> <event> <event_name>event4</event_name> <event_type>delete</event_type> <event_happen>before</event_happen> <event_node>Purchase_Order</event_node> <filter_attribute1>book_ID</filter_attribute1> <doc>p_order</doc> </event> Figure 9 Event file for Order_Conflict Rule Following is example for Order_Conflict rule: <rule> <rulename>Order_Conflict</rulename> <event_composition>event3 and event4 within-24-hours </event_composition> <filter1>=</filter1> <priority>1</priority> <condaction>let $book := collection("data")/Bookstore let $c_bookID := #c_order/Customer_Order/book_ID let $p_bookID := #p_order/Purchase_Order/book_ID return if($c_bookID = $p_bookID) then if($book/Book[book_ID/text() = $c_bookID]/quantity_in_stock/text() = 0) then "echo Order cannot be processed" else () else () </condaction> </rule> Figure 10 Crule file for Order_Conflict rule 21 When a customer order is placed, and within 24 hours, if the purchase order gets deleted then an order conflict has occurred. The filter attribute on this rule checks whether the book id for the customer order placed and the book id for the purchase order getting deleted are same, then this rule becomes true. In that case the action is executed. The action checks for the quantity of the book and also the popularity. If the quantity is zero, and the popularity is low, then it is not wise to make a purchase order again. So it notifies the user that the order cannot be processed. <rule> <rulename>Special_Discount_on_future_purchase</rulename> <event_composition> (event5 seq event6 within-10-days) or (event7 seq event8 within-24-hours) </event_composition> <filter1>=</filter1> <priority>1</priority> <condaction>let $book := collection("data")/Bookstore return if(#cust_order1/Customer_Order/book_ID = #cust_order2/Customer_Order/book_ID and #cust_order1/Customer_Order/customer_ID = #cust_order2/Customer_Order/customer_ID) then let $val := $book/Customer_Order[order_ID/text() = #cust_order2/Customer_Order/order_ID]/order_total/text() return if($val &gt; 0) then replace value of node $book/Customer_Order[order_ID/text() = #cust_order2/Customer_Order/order_ID]/order_total/text() with ($val - ($val * 25 div 100)) else () if (#cust_order3/Customer_Order/customer_ID = #cust_order4/Customer_Order/customer_ID) then let $val := $book/Customer_Order[order_ID/text() = #cust_order4/Customer_Order/order_ID]/order_total/text() return if($val &gt; 0) then replace value of node $book/Customer_Order[order_ID/text() = #cust_order4/Customer_Order/order_ID]/order_total/text() with ($val - ($val * 25 div 100)) else ()</condaction> </rule> Figure 11 Crule file for Special_Discount rule 22 Figure 11 is an example of special discount rule, which is an extension to the discount rule. Here we changed the Discount Rule to Special Discount Rule. The rule terminology is: If a customer orders same book within 10 days, or different books within 24 hours, then give 25% discount on the later order. This special discount rule has 4 events. First and second events check for the same book_ID as well as same customer_ID and the duration constraint is 10 days. Third and fourth events check for the same customer_ID and the duration constraint is 24 hours. All the events are similar to the Discount Rule. More explanation on how these events are processed is presented in the next section. Composite event processing involves processing of all of these xml files, and a few operations on the Berkeley DB XML also. 23 Chapter 4 EVENT PROCESSING AND IMPLEMENTATION Composite event processing is more complicated than primitive event processing, as a rule is no longer triggered immediately by the occurrence of an event. It may relay on the occurrence of other events. So, an event log is used to keep tracks of event occurrence. Events are logged in eventlog.xml file. Based on the event history provided by the event log, event composition can be performed. At static time, when a user specifies a rule, the system saves the rule in the Fuzzy Rule Base. Fuzzy Rule Base contains all the rules defined by users. The system created by S. Vereppan[4] and C. Madalli [5] then parses the rule generates corresponding crisp rules. The crisp rule is stored in the Active Rule Repository. Based on the event_composition part of the rule, a rule can be triggered by a primitive event, or a composite event. At run time, the event handler parses the user input, XQuery insert or update statement, and generates a XML document as shown in Figure 12. This XML document contains all necessary data from the user inserted query, for further processing. As explaned in the section 3.3, a rule can contain time constraint, which checks the time between the two primitive events. So the event time is also captured. 24 <event> <event_type>insert</event_type> <event_node>Customer_Order</event_node> <event_variable> <Customer_Order> <order_ID>1</order_ID> <book_ID>1</book_ID> <customer_ID>1</customer_ID> <quantity>100</quantity> <order_total>1000</order_total> </Customer_Order> </event_variable> <doc>c_order1</doc> <event_datetime>2011/04/09 15:57:30</event_datetime> </event> Figure 12 Runtime event for composite event processing This event contains, event type whether its an Insert or Delete or Replace event. Event Node contains which event node is being affected by the user query. In the case of Insert ot Replace, event_variable contains the exact node, from the user query. In the case of Delete, event_variable contains the node that is going to be deleted. Also this event contains current datetime, which is used to calculate the time difference between two events during event composition. This event is validated against validevents.xml file. Validevent.xml is consistent with the Active Rule Repository. The event portion of a rule in the Active Rule Repository has en entry in Validevent.xml, with simplified information. If it is a valid event, then the event will be recorded, with current date and time, in the eventlog.xml file as shown in Figure 13. Eventlog.xml file keeps track of all the events occurred in the system till date. 25 <event id="1"> <event_type>insert</event_type> <event_happen>after</event_happen> <event_node>Customer_Order</event_node> <event_variable> <Customer_Order> <order_ID>1</order_ID> <book_ID>1</book_ID> <customer_ID>1</customer_ID> <quantity>100</quantity> <order_total>1000</order_total> </Customer_Order> </event_variable> <doc>c_order1</doc> <event_datetime>2011/04/09 15:57:30</event_datetime> </event> <event id="2"> <event_type>insert</event_type> <event_happen>after</event_happen> <event_node>Customer_Order</event_node> <event_variable> <Customer_Order> <order_ID>1</order_ID> <book_ID>1</book_ID> <customer_ID>1</customer_ID> <quantity>100</quantity> <order_total>1000</order_total> </Customer_Order> </event_variable> <doc>c_order</doc> <event_datetime>2011/04/09 15:57:30</event_datetime> </event> Figure 13 An Example of eventlog.xml file After initial processing on the user query, Event Handler consults the Rule Base to check the rules triggered by the event. If this is a primitive event to trigger a rule, the Event Handler invokes the Rule Engine to execute the rule. If multiple rules are triggered, the rules are executed sequentially according to the defined priorities. 26 The Event Handler also handles composite events. An EventSet(c_e) = {e1, e2, …em} can be defined for each composite event c_e. A RuleSet(c_e)= {r1, r2,…rn} can be defined for a set of rules triggered by the composite event c_e. If a user inputs a command that raises an event ei, from the EventSet(c_e), then ei will be added to the event log. This ei has the similar format to the event shown in Figure 12. The Event Handler goes to the Active Rule Base and checks all the rules triggered by c_e. The rule processing is done by checking all the elements of the rule. For each rule rx from the RuleSet(c_e), the Event Handler first evaluates the <event_composition> element. For example, Figure 8 shows the composition as “event1 SEQ event2 WITHIN-24-hours”. In the case of a composite event with SEQ operator, when event2 happens, the Event Handler has to veryfy if event1 happened before event 2. Event Handler also has to check the duration between the two events, as this rule also specifies the duration for this composite event, within 24 hours. Event Log has event_datetime element, which intends when the event occurred. If true, then this composite event has occured. For event ei raised by a user input command, the Event Handler searches the event log to check whether there is any instance of ej, other than ex, where ej EventSet(c_e). After determining if ej occured, the event_composition element can be evaluated to see whether this composite event c_e occurs or not. As event_composition element contains time and operators, Event Handler needs to check for the duration between ei and ej. According to the <priority> element on the rule, when a composite event c_e occurs, all the rules triggered by c_e will be executed by the Rule Engine. 27 If there are multiple occurances of ej appears in the event log, each instance of ej can form an instance of c_e. Each instance of c_e has to be evaluated by the Event Handler to check whether the instance really occurs or not, depending on related event instances in EventSet(c_e), the operators, and the time restrictions. This can become a performance bottleneck when there are hundreds or thousands of events logged in theeventlog.xml. To improve the performance, <filter_attribute> are introduced in the rule as an optional parameter, as shown in the example in Figure 6. User can specify upto 10 filter attributes, defined using <filter_attributei>. This will identify the attribute name useful for event composition. For example, in our Order Conflict rule example, the order placed by a customer, and the purchase order which is being deleted, have to be for the same book_ID. So “Book_ID” can be used to distinguish different events. In the rule definition, shown in Figure 8, users can define corresponding <filteri> with a comparison such as =, <, and >. In this example, among all the events in the event logs raised by insert Customer_Order, once an instance of event 2 happens, i.e. delete Purchase_Order, we only search for the instance that has the same Book_ID. In this project, when a user enters a query, it is processed, and a event is generated, as shown in figure 12. If it doesn’t trigger a rule by itself, the event is stored in eventlog.xml file, for future processing. Now another event occurs, which might trigger a rule in conjuction with the first event. The event.java file processes both the events, and extracts required parameters, used in condition action part of the rule. This parameters are used with a pound sign (“#”). This parameters are replace from the event’s event_variable part. As an example, from Figure 12, if the parameter to be replaced is #c_order1/customer_order/customer_ID, then it is replace with 1. XQuery functions are used to perform this operation. When all the parameters are replace with 28 corresponding values, now rule’s condition action is ready to be executed. So the user query is executed, and the condition action part is then executed. The second event is also being logged in eventlog.xml file. We will use the example in Figure 10 to further explain event processing. In Figure 10, the a composite event is “event1 and event2”. First the java code looks for event1 node in the event.xml file. This event1 contains event_type and event_node. These values are matched against the user query. If it is true, then event2 is processed, get the node information from event.xml file, and this time check against the eventlog.xml file. If the event has occurred than both event1 and event2 became true. The alternate case can also be there, where event2 matches with the user event, and look for event1 in the eventlog.xml. Now event1 and event2, both are replaced with string “true”. Then “and’ is replaced with “&&”. Now the event composition becomes “true && true” as a string. This string is passed to the BooleanExpression.readLeftToRight[] function. This function translates string into boolean parser, and evaluates the expression. So in our example, “true && true” should be evaluated to true, and so the rule is matched. Now based on priority element value on the rule, this rule will be executed after the user event. In this project, the rule replacement rules are as follows. “and” is replaced with “&&”, “or” is replaced with “||”. “seq” is also replaced with &&, but to make sure the event sequence, the last event has to match with the current user event, and all previous events should be matched against eventlog.xml file. 29 Chapter 5 TEST AND RESULTS This section contains different test cases and results performed on this system. It is necessary to make sure the rules should be processed correctly when a matching composite event occurs. 5.1 Validate Rule Insert The goal of this test is to make sure that user can insert a rule with both the options. First option is to insert the entire rule node as an XML string. Second option is to insert the rule node, element-by-element. This rule insert was successfully done by the executing ManageRules.java file. Figure 14 shows rule insert by XML node string, and Figure 15 shows rule insert by elementby-element option. For the both the cases, composite event was added to crule.xml file, and primitive events consisted in the composite event were added to the event.xml file. Also when a new event was inserted, an entry was made in validevents.xml file if it doesn’t match any existing events. Figure 16 shows rule insert for a composite event consisting 3 primitive events. To make it simple, the third rule extends the example shown in Figure 14, by specifying three orders instead of two, to get a discount. 30 Enter 1 if you want to insert entire node, Enter 2 if you want to insert rule by specifying individual elements: 1 Please provide number of events you want to insert for this rule: 2 Enter Event1 <event><event_name>event1</event_name><event_type>insert</event_typ e><event_happen>after</event_happen><event_node>Customer_Order</eve nt_node><filter_attribute1>customer_ID</filter_attribute1><doc>c_or der1</doc></event> Event Added !! Enter Event2 <event><event_name>event2</event_name><event_type>insert</event_typ e><event_happen>after</event_happen><event_node>Customer_Order</eve nt_node><filter_attribute1>customer_ID</filter_attribute1><doc>c_or der2</doc></event> Event Added !! Enter Rule <rule><rulename>Discount_on_future_purchase</rulename>< event_composition> event1 seq event2 within-1-hour </ event_composition><filter1>=</filter1><priority>1</priority><condac tion>let $book := collection("data")/Bookstore return if(#c_order1/Customer_Order/book_ID = #c_order2/Customer_Order/book_ID and #c_order1/Customer_Order/customer_ID = #c_order2/Customer_Order/customer_ID) then let $val := $book/Customer_Order[order_ID/text() = #c_order2/Customer_Order/order_ID]/order_total/text() return if($val &gt; 0) then replace value of node $book/Customer_Order[order_ID/text() = #c_order2/Customer_Order/order_ID]/order_total/text() with ($val ($val * 10 div 100)) else () else ()</condaction></rule> Rule Added !! Figure 14 Rule Insert 1 31 Enter 1 if you want to insert entire node, Enter 2 if you want to insert rule by specifying individual elements: 2 Please provide number of events you want to insert for this rule: 2 Last event in the events file is: event2 Start your events from number: 3 Enter Event3 event_name: event3 event_type: insert event_happen: after event_node: Customer_Order doc: c_order Please enter number of filter attributes for this event (Maximum 10 - Enter 0 for none): 1 Please enter filter attributes and filter comparison operators : filter_attribute1 : book_ID filter_value1 : = Event Added !! Enter Event4 event_name: event4 event_type: delete event_happen: before event_node: Purchase_Order doc: p_order Please enter number of filter attributes for this event (Maximum 10 - Enter 0 for none): 1 Please enter filter attributes and filter comparison operators : filter_attribute1 : book_ID filter_value1 : = Event Added !! --------------------------------------------Enter Rulename: Order_Conflict Enter Event Rule: (event3 and event4) within-24-hours Enter Priority: 1 Enter Condition Action: let $book := collection("data")/Bookstore let $c_bookID := #c_order/Customer_Order/book_ID let $p_bookID := #p_order/Purchase_Order/book_ID return if($c_bookID = $p_bookID) then if($book/Book[book_ID/text() = $c_bookID]/quantity_in_stock/text() = 0) then "echo Order cannot be processed" else () else () Rule Added !! Figure 15 Rule Insert 2 32 Enter 1 if you want to insert entire node, Enter 2 if you want to insert rule by specifying individual elements: 1 Please provide number of events you want to insert for this rule: 3 Enter Event5 <event><event_name>event5</event_name><event_type>insert</event_typ e><event_happen>after</event_happen><event_node>Customer_Order</eve nt_node><filter_attribute1>customer_ID</filter_attribute1><doc>c_or der5</doc></event> Event Added !! Enter Event6 <event><event_name>event6</event_name><event_type>insert</event_typ e><event_happen>after</event_happen><event_node>Customer_Order</eve nt_node><filter_attribute1>customer_ID</filter_attribute1><doc>c_or der6</doc></event> Event Added !! Enter Event7 <event><event_name>event7</event_name><event_type>insert</event_typ e><event_happen>after</event_happen><event_node>Customer_Order</eve nt_node><filter_attribute1>customer_ID</filter_attribute1><doc>c_or der7</doc></event> Event Added !! Enter Rule <rule><rulename>Special_Discount_on_future_purchase</rulename>< event_composition> event5 seq event6 seq event7 within-24-hours </ event_composition><filter1>=</filter1><priority>1</priority><condac tion>let $book := collection("data")/Bookstore return if(#c_order5/Customer_Order/book_ID = #c_order6/Customer_Order/book_ID and #c_order6/Customer_Order/book_ID = #c_order7/Customer_Order/book_ID and #c_order5/Customer_Order/customer_ID = #c_order6/Customer_Order/customer_ID and #c_order6/Customer_Order/customer_ID = #c_order7/Customer_Order/customer_ID) then let $val := $book/Customer_Order[order_ID/text() = #c_order7/Customer_Order/order_ID]/order_total/text() return if($val &gt; 0) then replace value of node $book/Customer_Order[order_ID/text() = #c_order7/Customer_Order/order_ID]/order_total/text() with ($val ($val * 10 div 100)) else () else ()</condaction></rule> Rule Added !! Figure 16 Rule Insert 3 33 5.2 Validate Rule and Event Processing This test should make sure that when a user enters a query, if it matches any of the rules, then the rule should be valid, and the condition action should be executed. Here two events need to be executed to check for a composite event rule can trigger. Figure 17 demonstrates the first event execution output, and Figure 18 demonstrates the second event execution. At the end of second event execution, a composite event rule is matched, and corresponding condition action is executed. Figures 19 and Figure 20 demonstrates an example for the Order_Conflict rule. Figure 21, 22 and 23 show events for the special discount rule. 34 Enter an Xquery Command: insert nodes <Customer_Order><order_ID>1</order_ID><book_ID>1</book_ID><customer_ ID>1</customer_ID><quantity>100</quantity><order_total>1000</order_t otal></Customer_Order>after collection("data")/Bookstore/Book[book_ID=1] Event type: insert split 'nodes' Start is : insert End is : <Customer_Order><order_ID>1</order_ID><book_ID>1</book_ID><customer_ ID>1</customer_ID><quantity>100</quantity><order_total>1000</order_t otal></Customer_Order>after collection("data")/Bookstore/Book[book_ID=1] split 'after' Start is : <Customer_Order><order_ID>1</order_ID><book_ID>1</book_ID><customer_ ID>1</customer_ID><quantity>100</quantity><order_total>1000</order_t otal></Customer_Order> End is : collection("data")/Bookstore/Book[book_ID=1] Replaced event : <Customer_Order><order_ID>1</order_ID><book_ID>1</book_ID><customer_ ID>1</customer_ID><quantity>100</quantity><order_total>1000</order_t otal></Customer_Order>after collection("data")/Bookstore/Book[book_ID=1] Root element of the doc : rules Evaluating rules database which has : 2 rules RULE '0' did not Match !! RULE '1' did not Match !! Root element of crule: rules Evaluating rules database which has : 2 rules Event Added !! Event Added !! Event executed successfully !! Figure 17 Event 1 for Discount Rule 35 Enter an Xquery Command: insert nodes <Customer_Order><order_ID>2</order_ID><book_ID>1</book_ID><customer _ID>1</customer_ID><quantity>200</quantity><order_total>2000</order _total></Customer_Order>after collection("data")/Bookstore/Book[book_ID=1] Event type: insert split 'nodes' Start is : insert End is : <Customer_Order><order_ID>2</order_ID><book_ID>1</book_ID><customer _ID>1</customer_ID><quantity>200</quantity><order_total>2000</order _total></Customer_Order>after collection("data")/Bookstore/Book[book_ID=1] split 'after' Start is : <Customer_Order><order_ID>2</order_ID><book_ID>1</book_ID><customer _ID>1</customer_ID><quantity>200</quantity><order_total>2000</order _total></Customer_Order> End is : collection("data")/Bookstore/Book[book_ID=1] Replaced event : <Customer_Order><order_ID>2</order_ID><book_ID>1</book_ID><customer _ID>1</customer_ID><quantity>200</quantity><order_total>2000</order _total></Customer_Order>after collection("data")/Bookstore/Book[book_ID=1] Root element of the doc : rules Evaluating rules database which has : 2 rules RULE '0' Matched !! RULE '1' did not Match !! Root element of crule: rules Evaluating rules database which has : 2 rules Event Added !! CONDITION ACTION IS : let $book := collection("data")/Bookstore return if(1 = 1 and 1 = 1) then let $val := $book/Customer_Order[order_ID/text() = 2]/order_total/text() return if($val > 0) then replace value of node $book/Customer_Order[order_ID/text() = 2]/order_total/text() with ($val - ($val * 10 div 100)) else () else () RULENAME of the Rule invoked by this event is : Discount_on_future_purchase Event executed successfully !! Condition action executed successfully !! Event Added !! Figure 18 Event 2 for Discount Rule 36 Enter an Xquery Command: insert nodes <Customer_Order><order_ID>1</order_ID><book_ID>1</book_ID><customer _ID>1</customer_ID><quantity>100</quantity><order_total>1000</order _total></Customer_Order>after collection("data")/Bookstore/Book[book_ID=1] Event type: insert split 'nodes' Start is : insert End is : <Customer_Order><order_ID>1</order_ID><book_ID>1</book_ID><customer _ID>1</customer_ID><quantity>100</quantity><order_total>1000</order _total></Customer_Order>after collection("data")/Bookstore/Book[book_ID=1] split 'after' Start is : <Customer_Order><order_ID>1</order_ID><book_ID>1</book_ID><customer _ID>1</customer_ID><quantity>100</quantity><order_total>1000</order _total></Customer_Order> End is : collection("data")/Bookstore/Book[book_ID=1] Replaced event : <Customer_Order><order_ID>1</order_ID><book_ID>1</book_ID><customer _ID>1</customer_ID><quantity>100</quantity><order_total>1000</order _total></Customer_Order>after collection("data")/Bookstore/Book[book_ID=1] Root element of the doc : rules Evaluating rules database which has : 2 rules RULE '0' did not Match !! RULE '1' did not Match !! Root element of crule: rules Evaluating rules database which has : 2 rules Event Added !! Event Added !! Event executed successfully !! Figure 19 Event 1 for Order Conflict Rule 37 Enter an Xquery Command: delete nodes collection("data")/Bookstore/Purchase_Order[book_ID=1] Event type: delete End is : collection("data")/Bookstore/Purchase_Order[book_ID=1] End of evt node: collection("data")/Bookstore/Purchase_Order[book_ID=1] Replaced event : collection("data")/Bookstore/Purchase_Order[book_ID=1] Root element of the doc : rules Evaluating rules database which has : 2 rules RULE '0' did not Match !! RULE '1' Matched !! Root element of crule: rules Evaluating rules database which has : 2 rules Event Added !! CONDITION ACTION IS : let $book := collection("data")/Bookstore let $c_bookID := 1 let $p_bookID := 1 return if($c_bookID = $p_bookID) then if($book/Book[book_ID/text() = $c_bookID]/quantity_in_stock/text() = 0) then "echo Order cannot be processed" else () else () RULENAME of the Rule invoked by this event is : Order_Conflict Condition action executed successfully !! Event executed successfully !! Figure 20 Event 2 for Order Conflict Rule 38 Enter an Xquery Command: insert nodes <Customer_Order><order_ID>1</order_ID><book_ID>1</book_ID><customer _ID>1</customer_ID><quantity>100</quantity><order_total>1000</order _total></Customer_Order>after collection("data")/Bookstore/Book[book_ID=1] Event type: insert split 'nodes' Start is : insert End is : <Customer_Order><order_ID>1</order_ID><book_ID>1</book_ID><customer _ID>1</customer_ID><quantity>100</quantity><order_total>1000</order _total></Customer_Order>after collection("data")/Bookstore/Book[book_ID=1] split 'after' Start is : <Customer_Order><order_ID>1</order_ID><book_ID>1</book_ID><customer _ID>1</customer_ID><quantity>100</quantity><order_total>1000</order _total></Customer_Order> End is : collection("data")/Bookstore/Book[book_ID=1] Replaced event : <Customer_Order><order_ID>1</order_ID><book_ID>1</book_ID><customer _ID>1</customer_ID><quantity>100</quantity><order_total>1000</order _total></Customer_Order>after collection("data")/Bookstore/Book[book_ID=1] Root element of the doc : rules Evaluating rules database which has : 2 rules RULE '0' did not Match !! RULE '1' did not Match !! Root element of crule: rules Evaluating rules database which has : 2 rules Event Added !! Event Added !! Event executed successfully !! Figure 21 Event 1 for Special Discount Rule 39 Enter an Xquery Command: insert nodes <Customer_Order><order_ID>2</order_ID><book_ID>2</book_ID><customer _ID>1</customer_ID><quantity>200</quantity><order_total>2000</order _total></Customer_Order>after collection("data")/Bookstore/Book[book_ID=2] Event type: insert split 'nodes' Start is : insert End is : <Customer_Order><order_ID>2</order_ID><book_ID>2</book_ID><customer _ID>1</customer_ID><quantity>200</quantity><order_total>2000</order _total></Customer_Order>after collection("data")/Bookstore/Book[book_ID=2] split 'after' Start is : <Customer_Order><order_ID>2</order_ID><book_ID>2</book_ID><customer _ID>1</customer_ID><quantity>200</quantity><order_total>2000</order _total></Customer_Order> End is : collection("data")/Bookstore/Book[book_ID=2] Replaced event : <Customer_Order><order_ID>2</order_ID><book_ID>2</book_ID><customer _ID>1</customer_ID><quantity>200</quantity><order_total>2000</order _total></Customer_Order>after collection("data")/Bookstore/Book[book_ID=2] Root element of the doc : rules Evaluating rules database which has : 2 rules RULE '0' did not Match !! RULE '1' did not Match !! Root element of crule: rules Evaluating rules database which has : 2 rules Event Added !! Event Added !! Event executed successfully !! Figure 22 Event 2 for Special Discount Rule 40 Enter an Xquery Command: insert nodes <Customer_Order><order_ID>3</order_ID><book_ID>3</book_ID><customer_I D>1</customer_ID><quantity>300</quantity><order_total>3000</order_tot al></Customer_Order>after collection("data")/Bookstore/Book[book_ID=3] Event type: insert split 'nodes' Start is : insert End is : <Customer_Order><order_ID>3</order_ID><book_ID>3</book_ID><customer_I D>1</customer_ID><quantity>300</quantity><order_total>3000</order_tot al></Customer_Order>after collection("data")/Bookstore/Book[book_ID=3] split 'after' Start is : <Customer_Order><order_ID>3</order_ID><book_ID>3</book_ID><customer_I D>1</customer_ID><quantity>300</quantity><order_total>3000</order_tot al></Customer_Order> End is : collection("data")/Bookstore/Book[book_ID=3] Replaced event : <Customer_Order><order_ID>3</order_ID><book_ID>3</book_ID><customer_I D>1</customer_ID><quantity>300</quantity><order_total>3000</order_tot al></Customer_Order>after collection("data")/Bookstore/Book[book_ID=3] Root element of the doc : rules Evaluating rules database which has : 2 rules RULE '0' Matched !! RULE '1' did not Match !! Root element of crule: rules Evaluating rules database which has : 2 rules Event Added !! Event Added !! CONDITION ACTION IS : let $book := collection("data")/Bookstore return if(1 = 0 and 1 = 1) then let $val := $book/Customer_Order[order_ID/text() = 0]/order_total/text() return if($val &gt; 0) then replace value of node $book/Customer_Order[order_ID/text() = 0]/order_total/text() with ($val - ($val * 25 div 100)) else () return if (1 = 1) then let $val := $book/Customer_Order[order_ID/text() = 3]/order_total/text() return if($val &gt; 0) then replace value of node $book/Customer_Order[order_ID/text() = 3]/order_total/text() with ($val - ($val * 25 div 100)) else () RULENAME of the Rule invoked by this event is : Special_Discount_on_future_purchase Event executed successfully !! Condition action executed successfully !! Figure 23 Event 3 for Special Discount Rule 41 Chapter 6 SUMMARY AND FUTURE WORK This project has been implemented using Java. The project has incorporated Composite Events into a fuzzy active XML database system, extending the current system, developed by S. Verappan [2] and C. Madalli [3]. This fuzzy system was implemented on top of Berkeley DB XML. The application provides the user with the facility to input Rules and Composite Events. The project also provides the Event handler interface that accepts the events for the database. Events can trigger one or more rules in the repository and corresponding condition action will be executed on the database based on their priority. All these functionality has been implemented and validated with proper test cases. There are still a few extensions added to the project to enhance the system more. The project has interface to allow users to add events and rules, from the interface itself. So users who don’t know about the system much, can run the utility and add rules by themselves. This utility does not have any validations to show to the users, in case they specify incorrect rule or event. This should be fairly simple, but have to define rules, in a separate validator XML file. The system lacks intelligent error handling functionality. Whenever an error occurs, java exception handler will catch it, and display a fairly technical message, that might be easy to understand by a Java developer. But it is not that user friendly. The user interface is a Console based interface. A web interface might be a good idea compared to the console application. A new web user interface can be very user friendly. 42 Standard Java web application can be handy and a user can get better messages and interface to use the system. 43 APPENDIX A Bookstore Application This section contains sample structure of the bookstore database used for this project. The structure is similar to the projects by S. Verappan[4] and C. Madalli[5]. The bookstore database can have nodes like Book, Customer_Order, Sales_Record, Purchase_Order, Discount_Information, and can be extended as per the requirements. Following is an example of a Book Node: <Bookstore> <Book> <book_ID>1</book_ID> <title>Harry Potter and the Order of the Phoenix</title> <author> <author_fname>J.K.</author_fname> <author_lname>Rowling</author_lname> </author> <price>10</price> <year_published>2004</year_published> <publisher>Scholastic, Inc.</publisher> <genre>Fiction</genre> <popularity>LOW</popularity> <popularity_min>25.0</popularity_min> <popularity_max>75.0</popularity_max> <quantity_in_stock>3200</quantity_in_stock> </Book> </Bookstore> Following is an example of a Customer Order node: <Customer_Order> <order_ID>1</order_ID> <book_ID>1</book_ID> <customer_ID>1</customer_ID> <quantity>100</quantity> <order_total>1000</order_total> </Customer_Order> 44 Following is an example of a Purchase Order node: <Purchase_Order> <purchase_ID>1</purchase_ID> <book_ID>1</book_ID> <quantity>15</quantity> <purchase_price>30</purchase_price> </Purchase_Order> 45 BIBLIOGRAPHY [1] L. A. Zadeh, “Fuzzy Sets,” Information and Control, vol.8, (2010). Academic Press, New York, 1965. pp. 338-353. [2] N. W. Paton and O. Diaz, “Active database Systems,” (2010). ACM Computing Surveys, 31,1, March, 1999, pp. 3-27. [3] Oracle database system. (2010). In Oracle. Retrieved September 05, 2010 from Oracle Online. http://www.oracle.com/us/products/database/index.html [4] S. Veerappan, “Fuzzy Active Rules for XML Databases”. (2010). Master’s Project, California State University, Sacramento, Summer 2009. [5] C. Madalli, “Fuzzy Active Rules for XML Databases”. (2010). Master’s Project, California State University, Sacramento, Summer 2009. [6] Event Processing Glossary. (2010). In Complex Event Processing. Retrieved September 30, 2010 from Complex Event Online. http://www.complexevents.com/2008/08/31/event-processing-glossary-version-11/ [7] Berkeley DB. (2010). In Berkeley DB, Oracle Embedded Database. Retrieved August 30, 2010. From Oracle Online. http://www.oracle.com/us/products/database/berkeleydb/index.html [8] S. Chakrarvarthy, V. Krishnaprasad, E. Anwar, and S. –K. Kim, “Composite Events for Active Databases: Semantics, Contexts and Detection,” (2010). Proceedings of the 20th VLDB Conference, Santiago, Chile, 1994, pp. 606-617. [9] S. D. Urban, I. Biswas, and S. W. Dietrich,“Filtering Features for a Composite Event Definition Language,” (2010). Proceedings of the 2006 Symposium on Applications and the Internet, Phoenix, Arizona, 2006. pp. 86-89. [10] M. Bernauer, G. Kappel, and G. Kramler, “Composite Events for XML”. (2011). Proceedings of the 13th World Wide Web Conference (WWW13), New York, U.S.A., May 2004. [11] G. Xu, J. Ma and T Huang, “A XML-based Composite Event Approach”. (2010). Proceedings of the first international workshop on Interoperability of heterogeneous information systems, ACM New York, NY, USA 2005. [12] A Technical Introduction to XML. (2010). In XML. Retrieved September 05, 2010. From XML Online. http://www.xml.com/pub/a/98/10/guide0.html?page=2 46 [13] XQuery. (2010). In XQuery – Wikipedia. Retrieved September 05, 2010. From Wikipedia Online. http://en.wikipedia.org/wiki/XQuery [14] XML. (2010). In W3C XML Query (XQuery). Retrieved September 10, 2010. From W3C Online. http://www.w3.org/XML/Query/ [15] JBooleanExpression. (2011). In Evaluate Boolean String Expression with Java. Retrieved March 01, 2011. From Sourceforge Onlne. http://jboolexpr.sourceforge.net/index.htm