This page describes the Java Implementation for Event Processing.
The Java Implementation for Event Processing is an extension of the standard SCA Java Implementation model. All the standard SCA Java implementation features continue to be available to Java implementations. The following features are added:
- Ability to define one or more methods of the implementation class to be consumer methods, consuming one or more event types
- Ability to define a field or setter method of the implementation class as an event producer, with one or more business methods producing one or more event types
- Ability to define event types as Java POJO classes
Event Types
Event types are defined through Java classes which are annotated with a @EventType annotation. The @EventType annotation has a single parameter which is the name of the event type.
@EventType(ExampleEvent)
public class ExampleEvent {
public String eventData;
}
The name may be:
- unqualified, in which case the EventType name is qualified by the package name of the class itself
- qualified, in which case the EventType name is used as it is declared
Note that the Event Type name maps to an XSD QName using the Java-to-WSDL mapping as defined by JAX-WS.
The Event type(s) handled by a consumer method or a producer method is defined in one of two ways:
- The method has a parameter that is of a class annotated with the @EventType annotation (of a single event type)
- The method is itself annotated with the @EventTypes annotation for one or more event types - where the method parameter is of some generic type such as java.lang.Object which does not specify an EventType
Event Consumer methods
Each method of the implementation that is a consumer for events is annotated with a @Consumer annotation. Each method must have a void return type and a single parameter that is either a specific event type or a superclass of one or more event types, including java.lang.Object, which is treated as the supertype of all event types.
public class ConsumerrExample {
private ExampleProducer eventProducer;
@Consumer(ExampleConsumer)
public void someBusinessMethod( ExampleEvent theEvent ) {
String businessData = theEvent.eventData;
}
}
Event Producers
Event Producers are identified as a Field or a Setter method annotated with a @Producer annotation
It is required that the Field or Setter method is typed by a Java interface. The Java interface must have one or more methods, each of which has a void return type and a single parameter that is either a specific event type or a superclass of one or more event types, including java.lang.Object, which is treated as the supertype of all event types.
@Remotable
public interface ExampleProducer {
void produceExampleEvent( ExampleEvent theEvent);
}
@EventType(ExampleEvent)
public class ExampleEvent {
public String eventData;
}
public class ProducerExample {
private ExampleProducer eventProducer;
@Producer(ExampleEvent)
public void setEventProducer( ExampleProducer theProducer ) {
eventProducer = theProducer;
return;
}
public void someBusinessMethod() {
theEvent = new ExampleEvent();
theEvent.eventData = "Some Data";
eventProducer.produceExampleEvent( theEvent );
}
}