Announcement Announcement Module
Collapse
No announcement yet.
Custom Inbound Channel Adapter - threading question Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Custom Inbound Channel Adapter - threading question

    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 :-

    Code:
    onInit() {
        executor = Executors.newFixedThreadPool(noOfSubscribers);
    }
    Then in onStart() , I start a runnable thread x times, where each thread listens for the same event type.
    I keep a list of all the threads.

    Code:
    WebmethodsMonitor monitor= new WebmethodsMonitor(......);			
    executor.execute( webmethodsMonitor);
    listeners.add(monitor);
    Then in onStop(), I ask each thread in the listeners List, to call disconnect() on the webmethods api.


    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.

  • #2
    Didnt quite understand what you are looking to achieve. Perhaps you can elaborate a bit more here. I am suggesting something before even understanding something, but have a look at ExecutorChannels in the reference manual too.

    Comment

    Working...
    X