How to Create an Oracle CEP Event Type as a JavaBean Using the Event Type Repository Editor

Overview of Oracle CEP Events 2-7 Example 2–4 MarketEvent Class package com.bea.wlevs.example.algotrading.event; import java.util.Date; public final class MarketEvent { private final Long timestamp; private final String symbol; private final Double price; private final Long volume; private final Long latencyTimestamp; public MarketEventfinal Long timestamp, final String symbol, final Double price, final Long volume, final Long latencyTimestamp { this.timestamp = timestamp; this.symbol = symbol; this.price = price; this.volume = volume; this.latencyTimestamp = latencyTimestamp; } public Double getPrice { return price; } public String getSymbol { return symbol; } public Long getTimestamp { return timestamp; } public Long getLatencyTimestamp { return latencyTimestamp; } public Long getVolume { return volume; } } 2. Compile the JavaBean that represents your event type. 3. Open the EPN in the Oracle CEP IDE for Eclipse. The EPN editor opens as Figure 2–1 shows. 2-8 Oracle Complex Event Processing Developers Guide Figure 2–1 EPN Editor For more information, see Section 6.1, Opening the EPN Editor .

4. Click the Event Types tab.

The Event Type tab appears as Figure 2–2 shows. Figure 2–2 Event Type Repository Editor

5. Click Add Event Type green plus sign.

A new event is added to the Event Type Definitions list with default name newEvent as Figure 2–3 shows. Overview of Oracle CEP Events 2-9 Figure 2–3 Event Type Repository Editor - JavaBean Event

6. In the Event Type Definitions list, select newEvent.

The properties of this event appear in the Event Type Details area as Figure 2–3 shows.

7. Enter a name for this event in the Type name field.

8. Click Properties defined in Java bean.

9. Enter the fully qualified class name of your JavaBean class in the Class field.

For example com.bea.wlevs.example.algotrading.event.MarketEvent.

10. Click the Save button in the Eclipse tool bar or type CTRL-S.

The event is now in the event type repository. You can use the event type repository editor: a. To view the corresponding event type definition in the EPN assembly file, double-click the event type in the Event Type Definitions area. b. To delete this event, select the event type in the Event Type Definitions area and click Delete Event Type red x. 11. Use the event type: ■ Reference the event types as standard JavaBeans in the Java code of the adapters and business logic POJO in your application. public void onEventList newEvents throws RejectEventException { for Object event : newEvents { MarketEvent marketEvent = MarketEvent event; System.out.printlnPrice: + marketEvent.getPrice; } } ■ Access the event types from Oracle CQL and EPL rules: The following Oracle CQL rule shows how you can reference the MarketEvent in a SELECT statement: 2-10 Oracle Complex Event Processing Developers Guide query id=helloworldRule [CDATA[ select MarketEvent.price from marketEventChannel [Now] ]] query

2.2.2 How to Create an Oracle CEP Event Type as a JavaBean Manually

This procedure describes how to create and register an Oracle CEP event type as a JavaBean manually. Alternatively, you can create and register your event type as a JavaBean using the Oracle CEP IDE for Eclipse event type repository editor see Section 2.2.1, How to Create an Oracle CEP Event Type as a JavaBean Using the Event Type Repository Editor . To create an Oracle CEP event type as a Java bean manually: 1. Create a JavaBean class to represent your event type. Follow standard JavaBeans programming guidelines. See the JavaBeans Tutorial at http:java.sun.comdocsbookstutorialjavabeans for additional details. Oracle recommends that, if possible, you make your event type JavaBeans immutable to improve performance. For more information, see Section 2.1.1, Event Type Instantiation and Immutability . When you design your event, you must restrict your design to the even data types that Section 2.1.3.1, Event Types Specified as JavaBean or Java Class describes. Example 2–5 shows the MarketEvent which is implemented by the com.bea.wlevs.example.algotrading.event.MarketEvent class. Example 2–5 MarketEvent Class package com.bea.wlevs.example.algotrading.event; import java.util.Date; public final class MarketEvent { private final Long timestamp; private final String symbol; private final Double price; private final Long volume; private final Long latencyTimestamp; public MarketEventfinal Long timestamp, final String symbol, final Double price, final Long volume, final Long latencyTimestamp { this.timestamp = timestamp; this.symbol = symbol; this.price = price; this.volume = volume; this.latencyTimestamp = latencyTimestamp; } public Double getPrice { return price; } public String getSymbol { return symbol; Overview of Oracle CEP Events 2-11 } public Long getTimestamp { return timestamp; } public Long getLatencyTimestamp { return latencyTimestamp; } public Long getVolume { return volume; } } 2. Compile the JavaBean that represents your event type. 3. Register your JavaBean event type in the Oracle CEP event type repository: a. To register declaratively, edit the EPN assembly file using the wlevs:event-type-repository element wlevs:event-type child element as Example 2–6 shows. Example 2–6 EPN Assembly File event-type-repository wlevs:event-type-repository wlevs:event-type type-name=MarketEvent wlevs:class com.bea.wlevs.example.algotrading.event.MarketEvent wlevs:class wlevs:event-type wlevs:event-type-repository b. To register programatically, use the EventTypeRepository class as Example 2–7 shows. Example 2–7 Programmatically Registering an Event EventTypeRepository rep = getEventTypeRepository; rep.registerEventType MarketEvent, com.bea.wlevs.example.algotrading.event.MarketEvent.getClass ; For more information, see Section 2.7, Accessing the Event Type Repository . 4. Use the event type: ■ Reference the event types as standard JavaBeans in the Java code of the adapters and business logic POJO in your application. public void onEventList newEvents throws RejectEventException { for Object event : newEvents { MarketEvent marketEvent = MarketEvent event; System.out.printlnPrice: + marketEvent.getPrice; } } ■ Access the event types from Oracle CQL and EPL rules: The following Oracle CQL rule shows how you can reference the MarketEvent in a SELECT statement: