Hi Imesh,

Publish() method in data publisher is not a blocking call, it's a
asynchronous call. Within data publisher the events are put into a queue
and a separate thread does the real publishing to BAM. Also in BAM
mediator, the AsyncDataPublisher is being used therefore the connection to
BAM is also made asynchronous.  Hence IMHO it's not required to spawn a new
thread externally to publish the events and make it complicated.

Thanks,
Sinthuja.


On Thu, Feb 13, 2014 at 2:15 AM, Imesh Gunaratne <[email protected]> wrote:

> Hi,
>
> This is regarding the BAM Mediator 4.2.0.
> As it looks like currently the BAM Mediator is executing the data
> publishing logic in the same thread which the current message mediation is
> happening:
>
> public class BamMediator:
>
>     public boolean mediate(MessageContext messageContext) {
>       ...
>       try {
>         stream.sendEvents(messageContext);
>       } catch (BamMediatorException e) {
>           return true;
>       }
>
>        }
> }
>
> public class Stream {
>
> ...
>
>     public void sendEvents(MessageContext messageContext) throws 
> BamMediatorException {
>         ActivityIDSetter activityIDSetter = new ActivityIDSetter();
>         activityIDSetter.setActivityIdInTransportHeader(messageContext);
>         try {
>             if (!isPublisherCreated) {
>                 initializeDataPublisher(this);
>                 isPublisherCreated = true;
>             }
>             this.publishEvent(messageContext);
>         } catch (BamMediatorException e) {
>             String errorMsg = "Problem occurred while logging events in the 
> BAM Mediator. " + e.getMessage();
>             log.error(errorMsg, e);
>             throw new BamMediatorException(errorMsg, e);
>         }
>     }
>
> ...
>
> }
>
> I think if we move this logic to a new thread we could reduce the time it
> takes to execute the data publishing logic from the main message flow. WDYT?
>
> Thanks
>
> --
> *Imesh Gunaratne*
> Technical Lead
> WSO2 Inc: http://wso2.com
> T: +94 11 214 5345 M: +94 77 374 2057
> W: http://imesh.gunaratne.org
> Lean . Enterprise . Middleware
>
>
> _______________________________________________
> Dev mailing list
> [email protected]
> http://wso2.org/cgi-bin/mailman/listinfo/dev
>
>


-- 
*Sinthuja Rajendran*
Software Engineer <http://wso2.com/>
WSO2, Inc.:http://wso2.com

Blog: http://sinthu-rajan.blogspot.com/
Mobile: +94774273955
_______________________________________________
Dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/dev

Reply via email to