I'm writing a "Custom Inbound Channel Adapter" that is event driven, and will receive events from Webmethod ESB.
So for this I'm extending MessageProducerSupport, and when the event occurs I create a Message and send this to the "outputChannel'.
When my custom adapter is used in a pipeline, each 'use' will specify an 'event type' to register for, and an outputChannel to send the message to.
My question is around threading - when I use my custom adapter each thread will block whilst waiting for an event to be received. So to this end, I thought it was necessary to start a new thread from the adapter, such that the thread separately waits for the event. On top of that to allow the pipelline to specify a concurrent receive of the 'event type', I have a property named 'noOfSubscribers'. This means the custom channel adapter will start 'n' threads where 'n' is the 'noOfSubscribers'.
To acheive the threading I have just used the java concurrency api like :-
Then in onStart() , I start a runnable thread x times, where each thread listens for the same event type.
executor = Executors.newFixedThreadPool(noOfSubscribers);
I keep a list of all the threads.
Then in onStop(), I ask each thread in the listeners List, to call disconnect() on the webmethods api.
WebmethodsMonitor monitor= new WebmethodsMonitor(......);
I would appreciate comments / review of this.
Is this the best way to do this ? as I'm aware I'm handling the threading myself, or does Spring Integration provide something else I've missed.