Skip to content

Esper : Creating Custom Annotations

rmuthupandian edited this page Feb 11, 2015 · 1 revision

You can follow below steps to create custom annotations which can be used in EPL statements.

  1. Define an annotation class

  2. Create a Metadata class to hold information after compiling your EPL annotation.

  3. Create a Processor class which implements com.ebay.jetstream.event.processor.esper.annotation.processor.AnnotationProcessor

    Annotation processor class should parse the corresponding annotation attributes and create a Metadata object and inject it into StatementAnnotationInfo Object with Annotation class as the key.

    public StatementAnnotationInfo process(String statement,
       	EngineMetadata engineMetadata,
                       Map<String, AnnotationConfiguration> annotConfigMap,
       	StatementAnnotationInfo stmtAnntInfo,
       	Collection<EventSink> registeredSinkList);
  4. Create a Listener class which implements com.ebay.jetstream.event.processor.esper.annotation.listener.AnnotationListener

AnnotationListener class holds processed event from EsperEventListener and Metadata.

```java
 public JetstreamEvent processMetaInformation(JetstreamEvent event,
		StatementAnnotationInfo annotationInfo);

```

StatementAnnotationInfo holds annotation metadata. Using this metadata object , information can be injected/retrieved into/from the event.

  1. Configuring Annotation to Esper Engine.

    Set below property to EsperConfiguration bean to register your annotation with Esper Engine.

    Sample configuration

	<property name="annotationConfig">
			<list>
				<bean class="com.ebay.jetstream.event.processor.esper.annotation.config.AnnotationConfiguration">
		  					<property name="annotation" value="OutputTo" />
							<property name="className" value="com.ebay.jetstream.event.processor.esper.annotation.OutputTo" />
							<property name="processor">
								<bean class="com.ebay.jetstream.event.processor.esper.annotation.processor.OutputToAnnotationProcessor" />
								</property>
							<property name="listener">
								<bean class="com.ebay.jetstream.event.processor.esper.annotation.listener.OutputToAnnotationListener" />
							</property>	
				</bean>
	</property>