Details
-
Bug
-
Status: Resolved
-
Critical
-
Resolution: Fixed
-
None
-
None
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)
}
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.