Fixed HttpDestination lifecycle.

This commit is contained in:
Simone Bordet 2015-10-21 17:10:26 +02:00
parent 3fc6320881
commit 03b994a32c
2 changed files with 34 additions and 17 deletions

View File

@ -498,24 +498,18 @@ public class HttpClient extends ContainerLifeCycle
if (destination == null)
{
destination = transport.newHttpDestination(origin);
if (isRunning())
addManaged(destination);
HttpDestination existing = destinations.putIfAbsent(origin, destination);
if (existing != null)
{
HttpDestination existing = destinations.putIfAbsent(origin, destination);
if (existing != null)
{
destination = existing;
}
else
{
addManaged(destination);
if (LOG.isDebugEnabled())
LOG.debug("Created {}", destination);
}
if (!isRunning())
removeDestination(destination);
removeBean(destination);
destination = existing;
}
else
{
if (LOG.isDebugEnabled())
LOG.debug("Created {}", destination);
}
}
return destination;
}

View File

@ -32,7 +32,7 @@ import org.eclipse.jetty.util.thread.Sweeper;
@ManagedObject
public abstract class PoolingHttpDestination<C extends Connection> extends HttpDestination implements Callback
{
private final DuplexConnectionPool connectionPool;
private DuplexConnectionPool connectionPool;
public PoolingHttpDestination(HttpClient client, Origin origin)
{
@ -44,6 +44,29 @@ public abstract class PoolingHttpDestination<C extends Connection> extends HttpD
sweeper.offer(connectionPool);
}
@Override
protected void doStart() throws Exception
{
HttpClient client = getHttpClient();
this.connectionPool = newConnectionPool(client);
addBean(connectionPool);
super.doStart();
Sweeper sweeper = client.getBean(Sweeper.class);
if (sweeper != null)
sweeper.offer(connectionPool);
}
@Override
protected void doStop() throws Exception
{
HttpClient client = getHttpClient();
Sweeper sweeper = client.getBean(Sweeper.class);
if (sweeper != null)
sweeper.remove(connectionPool);
super.doStop();
removeBean(connectionPool);
}
protected DuplexConnectionPool newConnectionPool(HttpClient client)
{
return new DuplexConnectionPool(this, client.getMaxConnectionsPerDestination(), this);