Author: borges
Date: 2011-10-21 10:14:30 -0400 (Fri, 21 Oct 2011)
New Revision: 11574
Modified:
trunk/hornetq-core/src/main/java/org/hornetq/core/client/impl/ServerLocatorImpl.java
Log:
Guard against race when closing ServerLocator and using it to create a session factory
Modified:
trunk/hornetq-core/src/main/java/org/hornetq/core/client/impl/ServerLocatorImpl.java
===================================================================
---
trunk/hornetq-core/src/main/java/org/hornetq/core/client/impl/ServerLocatorImpl.java 2011-10-21
14:14:17 UTC (rev 11573)
+++
trunk/hornetq-core/src/main/java/org/hornetq/core/client/impl/ServerLocatorImpl.java 2011-10-21
14:14:30 UTC (rev 11574)
@@ -602,10 +602,7 @@
public ClientSessionFactory createSessionFactory(final TransportConfiguration
transportConfiguration) throws Exception
{
- if (closed)
- {
- throw new IllegalStateException("Cannot create session factory, server
locator is closed (maybe it has been garbage collected)");
- }
+ assertOpen();
try
{
@@ -616,7 +613,11 @@
throw new HornetQException(HornetQException.INTERNAL_ERROR, "Failed to
initialise session factory", e);
}
- ClientSessionFactoryInternal factory = new ClientSessionFactoryImpl(this,
+ synchronized (this)
+ {
+ assertOpen();
+ ClientSessionFactoryInternal factory =
+ new ClientSessionFactoryImpl(this,
transportConfiguration,
callTimeout,
clientFailureCheckPeriod,
@@ -633,16 +634,22 @@
addFactory(factory);
- return factory;
+ return factory;
+ }
}
- public ClientSessionFactory createSessionFactory() throws Exception
+ private void assertOpen()
{
if (closed || closing)
{
throw new IllegalStateException("Cannot create session factory, server
locator is closed (maybe it has been garbage collected)");
}
+ }
+ public ClientSessionFactory createSessionFactory() throws Exception
+ {
+ assertOpen();
+
try
{
initialise();
@@ -669,6 +676,7 @@
synchronized (this)
{
+ assertOpen();
boolean retry;
int attempts = 0;
do
@@ -1218,6 +1226,8 @@
staticConnector.disconnect();
}
+ synchronized (this)
+ {
Set<ClientSessionFactoryInternal> clonedFactory = new
HashSet<ClientSessionFactoryInternal>(factories);
for (ClientSessionFactory factory : clonedFactory)
@@ -1233,6 +1243,7 @@
}
factories.clear();
+ }
if (shutdownPool)
{
@@ -1655,7 +1666,7 @@
class Connector
{
- private TransportConfiguration initialConnector;
+ private final TransportConfiguration initialConnector;
private volatile ClientSessionFactoryInternal factory;
Show replies by date