Event-based systems comprise a plurality of independent program parts or components that communicate by way of notifications. Events generally correspond to notable conditions that cause a change of state such as sensor output, user action, or component message. In other words, an event is a message that indicates that something has happened. Event-based programs and/or portion thereof begin, wait for events, perform some action, and continue until explicitly terminated. By contrast, batch programs begin, perform one or more actions, and stop.
Event-based programs are implemented with two main and tightly coupled components: event triggers (or sources, or senders) and event handlers (or sinks, or receivers). Triggers emit a signal or notification upon detecting the occurrence of an event. One or more event handlers respond to this notification by performing an action specific to the event. For example, upon detection of a button click, an event, some functionality is performed related to the click. Stated differently, a sender can detect an event and transmit a notification to a listening receiver, which can perform some designated action.
In addition to simple events, event-based systems can support more complex processing of composite events. Composite events are events that are derived from or somehow related to one or more other events. For example, combination of two or more events by way of operators such as “and” and “or” result in a composite event. Furthermore, events can be causally related such that the occurrence of a first event causes a second event, for instance. Compositional events are conventionally realized by adding handlers to source and/or composite events that trigger dependent events in a cascading fashion, for instance.
Most all programs, including event-based programs, are subject to errors or abnormal conditions. Such conditions, also called exceptions, (e.g., divide by zero, null pointer reference, out of memory . . . ) correspond to special events that trigger invocation of an exception handler. Exceptions are handled by dedicated systems so as to segment normal from abnormal operation. Conventionally, try-catch blocks are employed around a group of statements that might produce or throw an exception.
The following presents a simplified summary in order to provide a basic understanding of some aspects of the disclosed subject matter. This summary is not an extensive overview. It is not intended to identify key/critical elements or to delineate the scope of the claimed subject matter. Its sole purpose is to present some concepts in a simplified form as a prelude to the more detailed description that is presented later.
Briefly described, the subject disclosure pertains to lazy and stateless events. In accordance with one aspect of the disclosure, addition of handlers to event triggers is deferred until a programmer specified handler is identified. Furthermore, event handlers can be composed in conjunction with event compositions. More specifically, handlers can be computed with respect to a specified event as well as events from which the specified event depends. Such computed handlers can then be propagated up to one or more related source events and invoked upon triggering of the source event. Since handlers are not accumulated on composite events, the events are stateless. Furthermore, events can be said to be lazy as handler addition is deferred and composite event handlers are invoked from one or more related source events rather than composite events.
To the accomplishment of the foregoing and related ends, certain illustrative aspects of the claimed subject matter are described herein in connection with the following description and the annexed drawings. These aspects are indicative of various ways in which the subject matter may be practiced, all of which are intended to be within the scope of the claimed subject matter. Other advantages and novel features may become apparent from the following detailed description when considered in conjunction with the drawings.
a-b are graphical representations of exemplary code snippets illustrating the difference between conventional and composed event handlers.
Systems and methods pertaining to lazy and stateless events are described in detail hereinafter. Handlers are lazily added to events. More specifically, event handler addition is deferred until a programmer specified handler is added. Composite event handlers can also be composed and propagated to one or more related source events. This further provides laziness, enables equivalent functionality, and stateless composite events.
Various aspects of the subject disclosure are now described with reference to the annexed drawings, wherein like numerals refer to like or corresponding elements throughout. It should be understood, however, that the drawings and detailed description relating thereto are not intended to limit the claimed subject matter to the particular form disclosed. Rather, the intention is to cover all modifications, equivalents, and alternatives falling within the spirit and scope of the claimed subject matter.
Referring initially to
Conventional event-based systems compose events by creating traditional “trigger+event” style events at each composition. For example in C#, field-like events are declared by marking a field like declaration with the event keyword as follows:
If another class, say “Y,” then builds a composite event it would typically be done by similarly declaring a new event on “Y” and then hooking up the new event to the underlying event. Consumers of “Y” hook handlers to the new event “Y” as follows:
Effectively, class “Y” has become stateful. When an event handler for “Bar” is added, it is accumulated inside “Y.” When the event “Foo” is raised with a value, the handler added by “Y” is invoked. This handler then raises the same value on the event “Bar.” Then, “Bar” invokes its attached handlers.
While straightforward, this approach suffers from several drawbacks. First, a mechanism to raise an event is created for each composition. That is, handlers registered on “Y” are added to the event “Bar.” Second, although “Y” hooks up the firing of “Foo” to fire “Bar,” how does it get unhooked? Lifetime is now not dependent on the handlers that the programmer adds and removes from “Bar,” but rather on the implicit handler added to “Foo” as well as those handlers that the programmer adds. Third, execution is not adequately deferred. As soon as composition occurs, things start to happen. In particular, as soon as a constructor for Y is called, a handler is added to “X's” “Foo” event that will cause “Bar” to be raised. Further, if side effects are specified in combinators, then they begin to occur independently from the addition of handlers.
System 100 resolves these drawbacks among other things. When events are composed, handlers are not implicitly added to related source events, thereby reducing the number of triggers required. Furthermore, handler addition is deferred until a user/programmer actually adds a handler to a composite event, and programmer specified handlers can be added to one or more related source events. Among other things, triggers and handlers are decoupled and enable lazy and stateless events.
Turning attention to
More specifically, the handler generation component 220 can produce a computed or composed hander that can be added to a source event such that the composite event is stateless and functionality is equivalent. In other words, behavior of a computed or composed handler specified on a source is the same as if the handler is added directly to the composed event. Furthermore, it is to be appreciated that the handler generation component 220 can perform more of an iterative or recursive process where the specified hander is associate with a composed event that itself related to at least one other composite event.
Referring to
What follows is a description of one particular implementation and associated examples. It is to be appreciated that the claimed subject matter is not meant to be limited by the following specific implement/embodiment. Rather, it is provide to facilitate clarity and understanding with respect to claimed aspects.
a and 5b provide a graphical illustration issued addressed by the claimed subject matter.
In this conventional approach, a trigger “Foo(n)” 510 is raised to on an event “Foo” 520. Event 520 is associated with a handler 530 (“x=>Bar(x)”) that triggers event “Bar” 540. The event “Bar” can then execute a plurality of associated handlers.
By contract and in accordance with an aspect of the claimed subject matter, a lazy solution is closer to the exemplary code snippet below.
In this case, adding a handler to the “Bar” event in “Y” immediately adds a handler to the underlying event “Foo” in “X.” As a result, “Y” does not accumulate any handlers itself and is purely stateless. It just forwards adding (or removing) the handler to “X.”
The distinction between approaches may be clarified by way of analogy. Consider a line of firefighters that need to move water from a tap to a fire. One possibility is for each firefighter to empty his/her bucket of water into a neighbor's bucket (conventional handler approach). The other is to hand over the whole bucket to the neighbor. In the latter case, the line is stateless; no one keeps a bucket for himself or herself.
Note that the event “Bar” in the above example is not a conventional trigger-event pair. It only includes the ability to add and remove handlers. Furthermore, when a user adds a handler to “Bar,” the handler is actually added to “Foo.” When the event “Foo” is raised, the handlers that were added to “Bar” will be raised directly, as shown in
In accordance with one aspect of the claimed subject matter, events can be first class program constructs. Conventionally, events are tightly coupled to classes, for example, much like class properties. However, events can be produced that behave as other first class program constructs such as integers. In other words, events can be created and passed around, among other things.
Turning to
Utilizing first class events, events can be composed utilizing continuation monads. For example, the “Select” combinator can be implemented using closures, such as anonymous inner-classes which implement the laziness as follows:
Note that no handlers are added to “e” until a handler is added to the result of the “Select” combinatory. Further, where implemented in a language that does not support closures such as anonymous delegates or anonymous inner classes, the anonymous closure design pattern can be implemented explicitly with native constructs or the like.
Referring to
It is to be appreciated that in accordance with one aspect of the claimed subject matter, each component accomplishes its purpose in its entirety and only that purpose. Contrast this with conventional trigger-event pair composition where event composition is handler composition (e.g., event composition component 710 and handler composition component 720 collapsed into one).
To facilitate clarity and understanding with respect to event processing or execution consider the following exemplary code:
This code illustrates composition of five events “e1,” “e2,” “e3,” “e4,” and “e5,”where “e1” and “e2” are source events while the other are composite events. In accordance with one aspect of the claimed subject matter, a dependency construct can be generated to capture dependencies expressed in the code.
Referring to
Handler invocation can begin when a trigger raises an event. For example: “trigger1.Raise(1),” which is the same as “if (1% 2=0) Console.WriteLine(1/3).” Recall that when a programmer adds a handler to “e5” 810, handlers were really only added to “e1” 850 and “e2” 840. They were computed based on the lazy events used for the various combinators. Therefore, when an event is raised, the computed handlers are directly invoked and no other triggers need to be raised because of the composition of handlers.
Sometime after a handler is added to an event, handler removal can be initiated where desired. In accordance with one aspect, the “Add” method can return a remove method, but this is not necessary. If a separate remove function is used, then a map should be maintained by each combinatory for each handler, computed handler pair.
According to another aspect, a single event handler can in fact include more than one handler or category of handler. For example, a handler can include values or continuations associated with successful execution and exceptional execution, amongst others. In this scenario, the “Add” method (or associated mechanisms) can be modified to take additional handlers as the exemplary code below illustrates. Composition can still be deferred, but a decision should be made about how the data flows between various categories of handlers:
The aforementioned systems, mechanisms, and the like have been described with respect to interaction between several components. It should be appreciated that such systems and components can include those components or sub-components specified therein, some of the specified components or sub-components, and/or additional components. Sub-components could also be implemented as components communicatively coupled to other components rather than included within parent components. Further yet, one or more components and/or sub-components may be combined into a single component to provide aggregate functionality. Communication between systems, components and/or sub-components can be accomplished in accordance with either a push and/or pull model. The components may also interact with one or more other components not specifically described herein for the sake of brevity, but known by those of skill in the art.
Furthermore, as will be appreciated, various portions of the disclosed systems above and methods below can include or consist of artificial intelligence, machine learning, or knowledge or rule based components, sub-components, processes, means, methodologies, or mechanisms (e.g., support vector machines, neural networks, expert systems, Bayesian belief networks, fuzzy logic, data fusion engines, classifiers . . . ). Such components, inter alia, can automate certain mechanisms or processes performed thereby to make portions of the systems and methods more adaptive as well as efficient and intelligent.
In view of the exemplary systems described supra, methodologies that may be implemented in accordance with the disclosed subject matter will be better appreciated with reference to the flow charts of
Referring to
Turning attention to
The word “exemplary” or various forms thereof are used herein to mean serving as an example, instance, or illustration. Any aspect or design described herein as “exemplary” is not necessarily to be construed as preferred or advantageous over other aspects or designs. Furthermore, examples are provided solely for purposes of clarity and understanding and are not meant to limit or restrict the claimed subject matter or relevant portions of this disclosure in any manner. It is to be appreciated that a myriad of additional or alternate examples of varying scope could have been presented, but have been omitted for purposes of brevity.
Furthermore, all or portions of the subject innovation may be implemented as a method, apparatus or article of manufacture using standard programming and/or engineering techniques to produce software, firmware, hardware, or any combination thereof to control a computer to implement the disclosed innovation. The term “article of manufacture” as used herein is intended to encompass a computer program accessible from any computer-readable device or media. For example, computer readable media can include but are not limited to magnetic storage devices (e.g., hard disk, floppy disk, magnetic strips . . . ), optical disks (e.g., compact disk (CD), digital versatile disk (DVD) . . . ), smart cards, and flash memory devices (e.g., card, stick, key drive . . . ). Additionally it should be appreciated that a carrier wave can be employed to carry computer-readable electronic data such as those used in transmitting and receiving electronic mail or in accessing a network such as the Internet or a local area network (LAN). Of course, those skilled in the art will recognize many modifications may be made to this configuration without departing from the scope or spirit of the claimed subject matter.
In order to provide a context for the various aspects of the disclosed subject matter,
With reference to
The system memory 1416 includes volatile and nonvolatile memory. The basic input/output system (BIOS), containing the basic routines to transfer information between elements within the computer 1412, such as during start-up, is stored in nonvolatile memory. By way of illustration, and not limitation, nonvolatile memory can include read only memory (ROM). Volatile memory includes random access memory (RAM), which can act as external cache memory to facilitate processing.
Computer 1412 also includes removable/non-removable, volatile/non-volatile computer storage media.
The computer 1412 also includes one or more interface components 1426 that are communicatively coupled to the bus 1418 and facilitate interaction with the computer 1412. By way of example, the interface component 1426 can be a port (e.g., serial, parallel, PCMCIA, USB, FireWire . . . ) or an interface card (e.g., sound, video, network . . . ) or the like. The interface component 1426 can receive input and provide output (wired or wirelessly). For instance, input can be received from devices including but not limited to, a pointing device such as a mouse, trackball, stylus, touch pad, keyboard, microphone, joystick, game pad, satellite dish, scanner, camera, other computer, and the like. Output can also be supplied by the computer 1412 to output device(s) via interface component 1426. Output devices can include displays (e.g., CRT, LCD, plasma . . . ), speakers, printers, and other computers, among other things.
The system 1500 includes a communication framework 1550 that can be employed to facilitate communications between the client(s) 1510 and the server(s) 1530. The client(s) 1510 are operatively connected to one or more client data store(s) 1560 that can be employed to store information local to the client(s) 1510. Similarly, the server(s) 1530 are operatively connected to one or more server data store(s) 1540 that can be employed to store information local to the servers 1530.
Client/server interactions can be utilized with respect with respect to various aspects of the claimed subject matter. By way of example and not limitation, one or more of the aforementioned components and/or actions can be embodied as a network or web service. Additionally or alternatively, a program include lazy and/or stateless events can be split for execution across a client 1510 and a server 1530, wherein communications are performed over the communication framework 1550.
What has been described above includes examples of aspects of the claimed subject matter. It is, of course, not possible to describe every conceivable combination of components or methodologies for purposes of describing the claimed subject matter, but one of ordinary skill in the art may recognize that many further combinations and permutations of the disclosed subject matter are possible. Accordingly, the disclosed subject matter is intended to embrace all such alterations, modifications, and variations that fall within the spirit and scope of the appended claims. Furthermore, to the extent that the terms “includes,” “contains,” “has,” “having” or variations in form thereof are used in either the detailed description or the claims, such terms are intended to be inclusive in a manner similar to the term “comprising” as “comprising” is interpreted when employed as a transitional word in a claim.
This application is related to U.S. patent application Ser. No. ______ [Atty. Ref.: MS325084.01/MSFTP2422US, Meijer, et al.], entitled UNIFIED EVENT PROGRAMMING AND QUERIES, filed Nov. 25, 2008, U.S. patent application Ser. No. ______ [Atty. Ref.: MS325083.01/MSFTP2423US, Meijer, et al.], entitled EXCEPTIONAL EVENTS, and U.S. patent application Ser. No. ______ [Atty. Ref: MS325086.01/MSFTP2424US, Dyer, et al.], entitled EXPOSING ASYNCHRONOUS MECHANISMS AS FIRST-CLASS EVENTS, all of even date. The entireties of these applications are incorporated herein by reference.