You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@activemq.apache.org by davis <da...@gmail.com> on 2009/01/12 17:48:04 UTC

livelock AMQPersistenceAdapter

I have a spring based JAX-RS/Jetty Servlet that also starts an embedded
ActiveMQ broker.

For unit tests, I am using Jetty.  Sometimes an error occurs and Jetty
restarts.  When this happens, I get the following:

11:36:12,136 INFO  [12882632@qtp0-3] broker.BrokerService
(BrokerService.java:454) - Using Persistence Adapter:
AMQPersistenceAdapter(activemq\data)
11:36:12,136 INFO  [12882632@qtp0-3] amq.AMQPersistenceAdapter
(AMQPersistenceAdapter.java:175) - AMQStore starting using directory:
activemq\data
11:36:12,261 INFO  [12882632@qtp0-3] impl.KahaStore (KahaStore.java:475) -
Kaha Store using data directory activemq\data\kr-store\state
11:36:12,386 INFO  [12882632@qtp0-3] amq.AMQPersistenceAdapter
(AMQPersistenceAdapter.java:233) - Active data files: [1]
11:36:12,543 INFO  [12882632@qtp0-3] broker.BrokerService
(BrokerService.java:577) - ActiveMQ null JMS Message Broker (localhost) is
starting
11:36:12,543 INFO  [12882632@qtp0-3] broker.BrokerService
(BrokerService.java:578) - For help or more information please see:
http://activemq.apache.org/
[INFO] Restart completed at Mon Jan 12 11:36:12 EST 2009
11:36:12,777 INFO  [12882632@qtp0-3] impl.KahaStore (KahaStore.java:475) -
Kaha Store using data directory activemq\data\kr-store\data
11:36:12,902 INFO  [12882632@qtp0-3] transport.TransportServerThreadSupport
(TransportServerThreadSupport.java:72) - Listening for connections at:
tcp://AN5885:61616
11:36:12,902 INFO  [12882632@qtp0-3] broker.TransportConnector
(TransportConnector.java:252) - Connector openwire Started
11:36:12,918 INFO  [12882632@qtp0-3] broker.BrokerService
(BrokerService.java:488) - ActiveMQ JMS Message Broker (localhost,
ID:AN5885-4253-1231778172605-0:0) started
11:36:14,199 INFO  [32788514@qtp0-4] support.AbstractApplicationContext
(AbstractApplicationContext.java:412) - Refreshing
org.apache.xbean.spring.context.ResourceXmlApplicationContext@152d950:
display name
[org.apache.xbean.spring.context.ResourceXmlApplicationContext@152d950];
startup date [Mon Jan 12 11:36:14 EST 2009]; parent:
org.springframework.context.support.ClassPathXmlApplicationContext@f65b5b
11:36:14,214 INFO  [32788514@qtp0-4] xml.XmlBeanDefinitionReader
(XmlBeanDefinitionReader.java:323) - Loading XML bean definitions from class
path resource [activemq.xml]
11:36:14,402 INFO  [32788514@qtp0-4] support.AbstractApplicationContext
(AbstractApplicationContext.java:427) - Bean factory for application context
[org.apache.xbean.spring.context.ResourceXmlApplicationContext@152d950]:
org.springframework.beans.factory.support.DefaultListableBeanFactory@92ed85
11:36:14,511 INFO  [32788514@qtp0-4] broker.BrokerService
(BrokerService.java:454) - Using Persistence Adapter:
AMQPersistenceAdapter(activemq\data)
11:36:14,511 WARN  [32788514@qtp0-4] amq.AMQPersistenceAdapter
(AMQPersistenceAdapter.java:1013) - Waiting to Lock the Store activemq\data

After the server restart -- AMQPersistenceAdapter is stuck waiting on a lock
-- the lock that it previously obtained and presumably left in a locked
state on the file system.

I'm sure I likely have an anti-pattern here, but what is the recommended way
to fix this?  I'm trying to figure out how to safely bootstrap the embedded
activemq broker when the servlet starts -- as a singleton...and then if an
error occurs in the server, how to safely destroy/restart the broker?  Is
there a recommended way to do this?
-- 
View this message in context: http://www.nabble.com/livelock-AMQPersistenceAdapter-tp21418331p21418331.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Re: livelock AMQPersistenceAdapter

Posted by Gary Tully <ga...@gmail.com>.
One thought, you have a boker bean and a factory using the vm protocol,
If the broker bean is not fully started before the connection factory,
you will have two brokers in the mix,

use    <property name="brokerURL"
value="vm://localhost?create=false&waitForStart=1000" />

so that the connection factory will not create a broker and will wait
till the broker bean is started,

There is also a depends-on bean attribute that you can use on the pool
to ensure that the broker is
started before the pool.

This should ensure there is a single broker in your context which
should shutdown when it is not referenced,

If the pool is holding on to references it may need an explicit
destroy method and or the broker may need an explicit stop destroy
method,

see the notes at the end of
http://activemq.apache.org/vm-transport-reference.html


2009/1/16 davis <da...@gmail.com>:
>
> This list seems a tad dead.  Is there any reason traffic is extremely low and
> many queries go unanswered?  Just curious.
>
> I've ignored this problem for now, but now it really is annoying, and I must
> fix it.  If I run a complete suite of unit tests, somewhere along the line
> the AMQPersistenceAdapter#stop() method is not getting called, and later the
> AMQPersistenceAdapter#start() is getting called, which causes the whole test
> suite to hang on the lock file.
>
>
> davis wrote:
>>
>> 11:36:14,511 WARN  [32788514@qtp0-4] amq.AMQPersistenceAdapter
>> (AMQPersistenceAdapter.java:1013) - Waiting to Lock the Store
>> activemq\data
>>
>
> I have tried to follow the recommend practices for managing AMQ with spring.
> I start an embedded broker, and this is how I do it (below).  I put a
> destroy-method="stop" on the PooledConnectionFactory.  This does not seem to
> be cleaning up things the way they should be.  How can I tie in the
> AMQPersistenceAdapter#stop() method -- which is really Service#stop() into
> Spring, so the whole thing shuts down gracefully?
>
> Thank you in advance for your help.
>
> <bean id="broker" class="org.apache.activemq.xbean.BrokerFactoryBean">
>        <property name="config" value="classpath:activemq.xml" />
>        <property name="start" value="true" />
> </bean>
>
> <bean id="myBeanDestination"
> class="org.apache.activemq.command.ActiveMQQueue">
>        <constructor-arg value="BEAN.QUEUE"/>
> </bean>
>
> <bean id="myBeanResponseDestination"
> class="org.apache.activemq.command.ActiveMQQueue">
>        <constructor-arg value="BEAN-RESPONSE.QUEUE"/>
> </bean>
>
> <!-- Pooled factory is recommended to avoid session per send -->
> <bean id="jmsFactory"
> class="org.apache.activemq.pool.PooledConnectionFactory"
> destroy-method="stop" init-method="start">
>        <property name="connectionFactory">
>                <bean class="org.apache.activemq.ActiveMQConnectionFactory">
>                        <!-- use local VM URL for efficiency -->
>                        <property name="brokerURL" value="vm://localhost" />
>                </bean>
>        </property>
> </bean>
>
> <!-- Spring JMS transaction manager -->
> <bean id="jmsTransactionManager"
> class="org.springframework.jms.connection.JmsTransactionManager">
>        <property name="connectionFactory" ref="jmsFactory" />
> </bean>
>
> <!-- Spring JMS template -->
> <bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
>        <property name="connectionFactory">
>                <ref local="jmsFactory"/>
>        </property>
> </bean>
>
> <!-- myBean sender-->
> <bean id="myBeanSender" class="com.example.MyBeanSender">
>        <property name="template" ref="jmsTemplate"/>
>        <property name="destination" ref="myBeanDestination"/>
> </bean>
>
> <!--  myBean Response Listener -->
> <bean id="myBeanResponseListener"
> class="com.example.MyBeanResponseListener"/>
>
> <!-- this auto-magically starts a listener for fax bean responses -->
> <bean
> class="org.springframework.jms.listener.DefaultMessageListenerContainer">
>        <property name="connectionFactory" ref="jmsFactory"/>
>        <property name="destination" ref="myBeanResponseDestination"/>
>        <property name="messageListener" ref="myBeanResponseListener"/>
>        <property name="transactionManager" ref="jmsTransactionManager"/>
> </bean>
> --
> View this message in context: http://www.nabble.com/livelock-AMQPersistenceAdapter-tp21418331p21503832.html
> Sent from the ActiveMQ - User mailing list archive at Nabble.com.
>
>



-- 
http://blog.garytully.com

Open Source SOA
http://FUSESource.com

Re: livelock AMQPersistenceAdapter

Posted by davis <da...@gmail.com>.
This list seems a tad dead.  Is there any reason traffic is extremely low and
many queries go unanswered?  Just curious.  

I've ignored this problem for now, but now it really is annoying, and I must
fix it.  If I run a complete suite of unit tests, somewhere along the line
the AMQPersistenceAdapter#stop() method is not getting called, and later the
AMQPersistenceAdapter#start() is getting called, which causes the whole test
suite to hang on the lock file.


davis wrote:
> 
> 11:36:14,511 WARN  [32788514@qtp0-4] amq.AMQPersistenceAdapter
> (AMQPersistenceAdapter.java:1013) - Waiting to Lock the Store
> activemq\data
> 

I have tried to follow the recommend practices for managing AMQ with spring. 
I start an embedded broker, and this is how I do it (below).  I put a
destroy-method="stop" on the PooledConnectionFactory.  This does not seem to
be cleaning up things the way they should be.  How can I tie in the
AMQPersistenceAdapter#stop() method -- which is really Service#stop() into
Spring, so the whole thing shuts down gracefully?  

Thank you in advance for your help.

<bean id="broker" class="org.apache.activemq.xbean.BrokerFactoryBean">
    	<property name="config" value="classpath:activemq.xml" />
    	<property name="start" value="true" />
</bean>

<bean id="myBeanDestination"
class="org.apache.activemq.command.ActiveMQQueue">
    	<constructor-arg value="BEAN.QUEUE"/>
</bean>
  	
<bean id="myBeanResponseDestination"
class="org.apache.activemq.command.ActiveMQQueue">
  	<constructor-arg value="BEAN-RESPONSE.QUEUE"/>
</bean>

<!-- Pooled factory is recommended to avoid session per send -->
<bean id="jmsFactory"
class="org.apache.activemq.pool.PooledConnectionFactory"
destroy-method="stop" init-method="start">
	<property name="connectionFactory">
		<bean class="org.apache.activemq.ActiveMQConnectionFactory">
			<!-- use local VM URL for efficiency -->
			<property name="brokerURL" value="vm://localhost" />
		</bean>
	</property>
</bean>
	
<!-- Spring JMS transaction manager -->
<bean id="jmsTransactionManager"
class="org.springframework.jms.connection.JmsTransactionManager">
	<property name="connectionFactory" ref="jmsFactory" />
</bean>
	
<!-- Spring JMS template -->
<bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
	<property name="connectionFactory">
		<ref local="jmsFactory"/>
	</property>
</bean>
	
<!-- myBean sender-->
<bean id="myBeanSender" class="com.example.MyBeanSender">
	<property name="template" ref="jmsTemplate"/>
	<property name="destination" ref="myBeanDestination"/>
</bean>
	
<!--  myBean Response Listener -->
<bean id="myBeanResponseListener"
class="com.example.MyBeanResponseListener"/>
	
<!-- this auto-magically starts a listener for fax bean responses -->
<bean
class="org.springframework.jms.listener.DefaultMessageListenerContainer">
	<property name="connectionFactory" ref="jmsFactory"/>
	<property name="destination" ref="myBeanResponseDestination"/>
	<property name="messageListener" ref="myBeanResponseListener"/>
	<property name="transactionManager" ref="jmsTransactionManager"/>
</bean>
-- 
View this message in context: http://www.nabble.com/livelock-AMQPersistenceAdapter-tp21418331p21503832.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.