cancel
Showing results for 
Search instead for 
Did you mean: 

Java API: Using MDM Listener in a J2EE application?

Former Member
0 Kudos

Hi everyone.

This is kind of a J2EE question, but with a specific MDM context so I'm asking it here. I'm not looking for an intro to J2EE, just a direction in which I should be looking at -- I'll do the digging and self-teaching myself.

I created a simple Java application that uses the EventDispatcher of the new API to react to events happening in the repository (specifically it reacts to record modifications). I want to explore the option of converting this application to an EE application.

My problem is how do I convert my listening thread in the standard Java app to the EE world? I currently have a simple listening loop:

while(true) {

Thread.yield();

}

which lets the EventDispatcher wait and fire events. How do I do this in an EE application given that threading is something i shouldn't touch? In which component would I initialize the EventDispatcher and how would it wait for events without a yield() loop?

Thanks

Alon

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Alon ,

Create a webProject of type Generic servlet

In the Init Method of the servlet :

a) create conncetion and session with the MDM server .

b) instantiate the class e.g "_activeListener"_ that implements TimerTask -( in its run method active the Listeners )

code snippet of run method of the activeListener class :

try {

ed = new EventDispatcher(connection.getHostname());

} catch (ConnectionException e4) {

// TODO Auto-generated catch block

e4.printStackTrace();

}

ed.addListener(ourListener);

b) timer = new Timer() ;

timer.schedule(_activeListener_,0,999999999);

In the destroy Method of the servlet :

a) timer.cancel();

b)close the MDM connection and destroy session .

In the Web.xml config file

set LoadonStartup to 1

<load-on-startup>1</load-on-startup>

this will start the servlet on deploying - i.e execute the init method on loading

You can start and stop the servlet using Visual Admin :

On start - the init menthod is called and the Listener stays active for ever

On stop - the destroy method is called which deactivates the listener and releases MDM Resources

In also works without issue in case of server restart .

Former Member
0 Kudos

Thank you for a very detailed answer Lanka, full points granted.

I'm wondering, is this the only way of making this happen? It seems like a "hack" using this kind of timer... I was hoping for a more elegant solution, something that could for example register a Message EJB to a JMS queue that will be updated by the MDM listener. I'm guessing that for that to happen the MDM framework must support this?

Thanks,

Alon

Answers (0)