Uploaded image for project: 'ServiceMix Components'
  1. ServiceMix Components
  2. SMXCOMP-336

PreDestroy being called for each exchange when it's not configured that way.

    XMLWordPrintableJSON

Details

    Description

      I have a sender bean and a receiver bean, both configured using <bean:endpoint ... bean="#...". The problem is that the PreDestroy method is being called after every MessageExchange is finished.

      According to the documentation:

      Attention: The Bean Endpoint schema allows to set a Bean or a Bean Name. The Bean will create a single instance of the POJO per endpoint whereas the Bean Name will create an instance per request (message exchange).

      I have in my xbean.xml:

      <?xml version="1.0" encoding="UTF-8"?>

      <beans xmlns:bean="http://servicemix.apache.org/bean/1.0"
      xmlns:example="http://servicemix.apache.org/example">

      <bean:endpoint service="example:sender" endpoint="senderEndpoint" bean="#sender"/>
      <bean:endpoint service="example:receiver" endpoint="receiverEndpoint" bean="#receiver"/>

      <bean id="sender" class="example.Sender">
      <property name="target" value="example:receiver"/>
      </bean>

      <bean id="receiver" class="example.Receiver">
      </bean>

      </beans>

      The receiver simply implements MessageExchangeListener.

      The PostConstruct and PreDestroy only gets called once on the sender
      The PostConstruct only gets called once on the receiver
      However, the PreDestroy gets called on the receiver for each request.

      I noticed in BeanEndpoint, there is the following method:

      protected void checkEndOfRequest(Request request, Object corId) {
      if (request.getExchange().getStatus() != ExchangeStatus.ACTIVE)

      { ReflectionUtils.callLifecycleMethod(request.getBean(), PreDestroy.class); //request.setBean(null); //request.setExchange(null); requests.remove(corId); }

      }

      It doesn't look like this class pays any attention to whether the bean is supposed to be a single instance of an instance-per-request, which is probably the cause of the problem.

      If you need me to attach an example, please let me know.

      Attachments

        1. fixPreDestroy.patch
          1.0 kB
          Ryan Bohn

        Activity

          People

            gnodet Guillaume Nodet
            rbohn Ryan Bohn
            Votes:
            1 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: