Articles
Enterprise Architecture
Building your first WebLogic Event Server Application
Pages:
1,
2
Figure 5 highlights the components that make up the HelloWorld event processing network (application).

Figure 5. The HelloWorld event processing network
The application includes the following components:
Here's the code for the
HelloWorldBean:
public class HelloWorldBean implements EventSink {
public void onEvent(List newEvents) throws RejectEventException {
for (Object event: newEvents) {
HelloWorldEvent helloWorldEvent = (HelloWorldEvent) event;
System.out.println("Message Robin: " + helloWorldEvent.getMessage());
}
}
}
Listing 2. The HelloWorldBean classAs Listing 2 shows, any event handler simply needs to implement the
EventSink interface. The
onEvent() method will then be called. Note that it takes a
List of an event as an argument. This is because EPL statements can generate more that one associated event object. However, in the case of our HelloWorld example, we will only receive one event in the list.
HelloWorldAdapter, which generates events, is pretty simple. It just calls a method every 300 milliseconds which generates the event:
public class HelloWorldAdapter extends ActiveAdapter {
/* ... */
private void generateHelloMessage() {
List<helloworldevent> eventCollection = new ArrayList<helloworldevent>();
String message = this.message + dateFormat.format(new Date());
HelloWorldEvent event = new HelloWorldEvent();
event.setMessage(message);
eventCollection.add(event);
fireEvent(eventCollection, null);
}
}
Listing 3. An excerpt from the HelloWorldAdapter classAs you can see, sending a message is just a matter of subclassing
ActiveAdapter, creating an
Event instance, populating it, and then calling
fireEvent().
Once the software has been successfully installed, you can start by selecting File->New -> Project in Eclipse, and selecting Event Server Application Project (see Figure 6).
Figure 6. Getting started with a WebLogic Event Server project
The rest of the processing provided by the wizard is now rather intuitive but is described in more detail in the EventServerToolingPreview.Getting.Started.Guide.pdf provided with the BEA software.
Follow the few wizard steps, providing a new application name and the Target WebLogic Event Server runtime, and most importantly selecting the "include the HelloWorld source code" selection box. In a matter of a few seconds, a new project will be dynamically created with all of the artifacts that you will need to deploy (publish) a fully functional solution.
Before I leave you to the excitement of exploring this new world of complex event processing networks, let me highlight some of the resulting artifacts when using the Eclipse IDE Event Server Plug-in, and a few recommendations (see Figure 7).
Figure 7. Rapid application development with the Eclipse IDE
In the "src" section you can find your Java code for your Event Server project. (If you do not see any HelloWorld source, then you forgot to select the option for the "helloworld" templates to be added to this project in the wizard.) To start implementing your own, the helloworldBean.java is a good place to jump in and perhaps modify the message output associated with the events.
In the META-INF section (under Spring), you can locate the Application Spring Assembly file that wires up all of the various nodes (stages) encompassed in the solution. This is where the powerful code completion IDE capabilities can be used to create additions to your complex event processing network.
Finally, again under the META-INF section (under wlevs), you can find the EPL definition file where you can specify the wealth of statements and related clauses to query the data arriving to this application (via the adapter or adapters).
It can be challenging to construct applications (especially as you investigate more of the capabilities of the WebLogic Event Server) because EDA requires navigating around OSGi bundles, Spring Assembly Files, EPNs, and several other components in the mix. However, with this first plug-in, with its evolving set of new IDE features arriving soon, we are providing developers with capabilities to simplify the dynamic creation and deployment (publishing) of our new WebLogic Event Server applications.
With this new Java application server and tooling, BEA is arming architects and developers with the capabilities to ensure that event-driven SOA solutions work effectively and can be delivered within cost and infrastructure parameters. We enable IT to introduce new types of services and SLAs, which can lead to higher revenues. The Java Application Server also helps IT provide better customer satisfaction and retention, which again can boost revenues. EDSOA promotes more agility with proactive operations, and this can make your organization more competitive and reduce operational costs. This unique new runtime and infrastructure can help drive rapid development for a tremendous time-to-market advantage.
Robin Smith is the Senior Engineering Product Manager at BEA Systems for the WebLogic Time and Event Driven (TED) Product Family.