Stream and Relation Sinks

Overview of Creating Oracle CEP Applications 1-9 batch of events for each event type of insert, update, and delete. If there is no event of a particular kind, then the corresponding Collection will be an empty Collection. For more information, see Section 9.1.6, Batch Processing Channels .

1.1.3.4 Transmitting Events in the EPN: Examples

The following example is based on the HelloWorld example that Figure 1–1 shows. It is modified here to illustrate: ■ Creating the HelloWorldEvent as a Tuple Event ■ Sending Events from the HelloWorldAdapter as a StreamSource ■ Receiving Events in the HelloWorldBean as a StreamSink ■ Sending Events from the HelloWorldBean as a StreamSource Figure 1–1 The HelloWorld Example Event Processing Network For more information, see: ■ Chapter 14, Configuring Custom Adapters ■ Chapter 15, Configuring Custom Event Beans ■ Chapter 16, Configuring Custom Spring Beans ■ HelloWorld Example in the Oracle Complex Event Processing Getting Started Creating the HelloWorldEvent as a Tuple Event First, create the tuple event in the EPN assembly file: wlevs:event-type-repository wlevs:event-type type-name=HelloWorldEvent wlevs:properties wlevs:property name=message type=char length=1000 wlevs:properties wlevs:event-type wlevs:event-type-repository Sending Events from the HelloWorldAdapter as a StreamSource Modify the HelloWorldAdapter to inject an EventTypeRepository instance at runtime by adding a setEventTypeRepository method using the Service annotation: Service public void setEventTypeRepositoryEventTypeRepository etr { etr_ = etr; } 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 {