Transmitting Events in the EPN: Examples

1-10 Oracle Complex Event Processing Developers Guide Modify the HelloWorldAdapter’s generateHelloMessage method to use the EventTypeRepository instance to instantiate a HelloWorldEvent, then configure the event’s properties, and send the event to the helloWorldInputChannel using the StreamSender instance that Oracle CEP server injected at runtime: private void generateHelloMessage { String message = this.message + dateFormat.formatnew Date; EventType type = etr_.getEventTypeHelloWorldEvent; EventProperty messageProp = type.getPropertymessage; Object event = type.createEvent; messageProp.setValueevent, message; eventSender.sendInsertEventevent; } Receiving Events in the HelloWorldBean as a StreamSink Modify the HelloWorldBean to inject an EventTypeRepository instance at runtime using the Service annotation: Service public void setEventTypeRepositoryEventTypeRepository etr { etr_ = etr; } Modify the HelloWorldBean’s onInsertEvent method use the EventTypeRepository instance to get the type of the received insert event and get the event’s property. public void onInsertEventObject event { EventType eventType = etr_.getEventTypeevent; String prop = StringeventType.getPropertyValueevent, message; System.out.printlnTuple Message: + prop; } Sending Events from the HelloWorldBean as a StreamSource Imagine that the HelloWorldBean is connected to another component and you want to send events from the HelloWorldBean to this downstream component. First, modify the HelloWorldBean class to implement the StreamSource interface and add the required setEventSender method: public class HelloWorldBean implements StreamSource, StreamSink { private StreamSender streamSender_; public void setEventSenderStreamSender sender { streamSender_ = sender; } ... } Modify the HelloWorldBean to inject an EventTypeRepository instance at runtime by adding a setEventTypeRepository method using the Service annotation: Service public void setEventTypeRepositoryEventTypeRepository etr { Overview of Creating Oracle CEP Applications 1-11 etr_ = etr; } Modify the HelloWorldBean to use the EventTypeRepository instance to instantiate a HelloWorldEvent, then configure the event’s properties, and send the event to the downstream component using the StreamSender instance that Oracle CEP server injected at runtime: private void generateHelloMessage { String message = this.message + dateFormat.formatnew Date; EventType type = etr_.getEventTypeHelloWorldEvent; EventProperty messageProp = type.getPropertymessage; Object event = type.createEvent; messageProp.setValueevent, message; eventSender.sendInsertEventevent; }

1.1.4 EPN Assembly File

You assemble an Oracle CEP application and an Event Processing Network EPN assembly file before deploying it to the server; this EPN assembly file is an extension of the Spring framework XML configuration file. The spring-wlevs-v11_1_1_3.xsd schema file describes the structure of EPN assembly files. The structure of EPN assembly files is as follows. There is a top-level root element named beans that contains a sequence of sub-elements. Each individual sub-element contains the configuration data for an Oracle CEP component. For example: ?xml version=1.0 encoding=UTF-8? beans xmlns=http:www.springframework.orgschemabeans xmlns:xsi=http:www.w3.org2001XMLSchema-instance xmlns:osgi=http:www.springframework.orgschemaosgi xmlns:wlevs=http:www.bea.comnswlevsspring xsi:schemaLocation= http:www.springframework.orgschemabeans http:www.springframework.orgschemabeansspring-beans.xsd http:www.springframework.orgschemaosgi http:www.springframework.orgschemaosgispring-osgi.xsd http:www.bea.comnswlevsspring http:www.bea.comnswlevsspringspring-wlevs-v11_1_1_3.xsd wlevs:event-type-repository wlevs:event-type type-name=HelloWorldEvent wlevs:classcom.bea.wlevs.event.example.helloworld.HelloWorldEventwlevs:class wlevs:event-type wlevs:event-type-repository wlevs:adapter id=helloworldAdapter class=com.bea.wlevs.adapter.example.helloworld.HelloWorldAdapter wlevs:instance-property name=message value=HelloWorld - the current time is: wlevs:adapter wlevs:channel id=helloworldInputChannel event-type=HelloWorldEvent wlevs:listener ref=helloworldProcessor wlevs:source ref=helloworldAdapter wlevs:channel wlevs:processor id=helloworldProcessor 1-12 Oracle Complex Event Processing Developers Guide wlevs:channel id=helloworldOutputChannel event-type=HelloWorldEvent advertise=true wlevs:listener bean class=com.bea.wlevs.example.helloworld.HelloWorldBean wlevs:listener wlevs:source ref=helloworldProcessor wlevs:channel beans For some Oracle CEP features, you specify some configuration in the EPN assembly file and some in the component configuration file. For more information, see: ■ Section 4.3, Creating EPN Assembly Files