Initiating outbound packets from a database trigger or queue

Is there a simple way to initiate packet transmissions to clients from the database level?

Here’s the scenario:

I have a plug-in that handles custom packets. While processing these incoming packets I update some data in a separate database (or private tables in the Openfire DB, doesn’t matter, just keeping it clean). Some of these updates launch triggers that may result in some updates I need to send out to other clients.

So far all I could come up with is a sort of “message pump”, meaning I’ll have a table that represents a message queue and some server process that will poll this table every x seconds and send the packets to the relevant clients. I don’t like this idea too much because it can be too slow.

So is there any other way to bubble up messages from the low DB level into an Openfire plug-in and out to clients?

Thanks in advance.

Alexco,

What I would do is create a plug in that on initialization creates a thread that checks your databases queue every x second (producer). I would have the producer write the data to some thread safe list. You could then create a consumer thread(s) that continually pull data off the list and process it. Does that make sense? Let me know if it doesn’t and I could hack out some pseudo code for you.

Cheers,

Nate

Thanks Nate, that’s sort of what I had in mind and you made it much more structured.

Believe it or not I’m actually a .NET developer playing with Openfire Java plug-ins in my spare time. At first I felt like a vampire walking into a church at high noon but I got comfortable with Eclipse and Java after a while. Still, writing thread-related code would most likely crash my server or just make it laugh back at me, so I’d be grateful if you could point me to some sample code where a plug-in initiates new threads that perform some on-going work.

Thanks again.

Hi Alex,

You sounded like you need real time responses to incoming packets. For that, I have a different idea all together. Perhaps the better way is to register your plugin as a PacketInterceptor with which you check the packets while they are being delivered; thereafter use the appropriate Openfire API to respond with outbound packets. Performance wise, I think this is better than using database triggers.