How to register listener method for @DynamicEventTemplate?

I use below code to instantiate SimplePollingEventListenerContainer. It works fine.

    AnnotationEventListenerAdapter adaptor = new AnnotationEventListenerAdapter();
    adaptor.setDelegate(new JobListener());
    SimplePollingEventListenerContainer obj = new SimplePollingEventListenerContainer();
    obj.setEventListener(adaptor);

Now I want to use DynamicEventTemplate and i'm trying below :-

    SimplePollingEventListenerContainer obj1 = new SimplePollingEventListenerContainer();
    obj1.setDynamicTemplate(new JobListener());
    //Due to above @DynamicEventTemplate method in JobListener is getting called.

    //Now trying below to set listener method which will be invoked by SimplePollingEventListenerContainer.
    AnnotationDynamicEventTemplateProviderAdapter dynamicAdaptor=new AnnotationDynamicEventTemplateProviderAdapter();
    dynamicAdaptor.setDelegate(new JobListener());

    obj1.setEventListener(dynamicAdaptor);
    //?? How to register a listener for Dynamic Template ?   Above is not supported.

JobListener.java is class which has @DynamicEventTemplate and @SpaceDataEvent annotation methods.

asked 2014-03-24 16:22:49 -0500

Atul gravatar image
edit retag flag offensive close merge delete

Comments

Found the way to configure @DynamicTemplate

AnnotationEventListenerAdapter adaptor = new AnnotationEventListenerAdapter();
adaptor.setDelegate(new JobListener());
SimplePollingEventListenerContainer obj = new SimplePollingEventListenerContainer();
obj.setEventListener(adaptor);
obj.setDynamicTemplate(new JobListener());

JobListener is as below :- It has both @DynamicEventTemplate and @SpaceDataEvent methods.

@DynamicEventTemplate
SQLQuery<JobEvent> matchingJobs() {

    String crit = {Dynamic String}
    return new SQLQuery<JobEvent>(
        JobEvent.class,
        "id.jobName in (" + crit +
        ") and stopSignalled = false and controlState='GREEN'");
}

@SpaceDataEvent
public JobEventStatus onJob(JobEvent event) {
    logger.info(" starting processing of event " + event);
 }
Atul gravatar imageAtul ( 2014-03-25 10:36:38 -0500 )edit