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) if (destination == null)
{ {
destination = transport.newHttpDestination(origin); destination = transport.newHttpDestination(origin);
if (isRunning()) addManaged(destination);
{
HttpDestination existing = destinations.putIfAbsent(origin, destination); HttpDestination existing = destinations.putIfAbsent(origin, destination);
if (existing != null) if (existing != null)
{ {
removeBean(destination);
destination = existing; destination = existing;
} }
else else
{ {
addManaged(destination);
if (LOG.isDebugEnabled()) if (LOG.isDebugEnabled())
LOG.debug("Created {}", destination); LOG.debug("Created {}", destination);
} }
if (!isRunning())
removeDestination(destination);
}
} }
return destination; return destination;
} }

View File

@ -32,7 +32,7 @@ import org.eclipse.jetty.util.thread.Sweeper;
@ManagedObject @ManagedObject
public abstract class PoolingHttpDestination<C extends Connection> extends HttpDestination implements Callback public abstract class PoolingHttpDestination<C extends Connection> extends HttpDestination implements Callback
{ {
private final DuplexConnectionPool connectionPool; private DuplexConnectionPool connectionPool;
public PoolingHttpDestination(HttpClient client, Origin origin) public PoolingHttpDestination(HttpClient client, Origin origin)
{ {
@ -44,6 +44,29 @@ public abstract class PoolingHttpDestination<C extends Connection> extends HttpD
sweeper.offer(connectionPool); 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) protected DuplexConnectionPool newConnectionPool(HttpClient client)
{ {
return new DuplexConnectionPool(this, client.getMaxConnectionsPerDestination(), this); return new DuplexConnectionPool(this, client.getMaxConnectionsPerDestination(), this);