Made jetty-client module compile.

This commit is contained in:
Simone Bordet 2012-11-22 11:38:50 +01:00 committed by Greg Wilkins
parent 7737dc8c76
commit b2c03b04f1
2 changed files with 21 additions and 20 deletions

View File

@ -55,8 +55,7 @@ import org.eclipse.jetty.io.MappedByteBufferPool;
import org.eclipse.jetty.io.SelectChannelEndPoint;
import org.eclipse.jetty.io.SelectorManager;
import org.eclipse.jetty.io.ssl.SslConnection;
import org.eclipse.jetty.util.Callback;
import org.eclipse.jetty.util.FutureCallback;
import org.eclipse.jetty.util.FuturePromise;
import org.eclipse.jetty.util.Jetty;
import org.eclipse.jetty.util.Promise;
import org.eclipse.jetty.util.component.ContainerLifeCycle;
@ -361,7 +360,7 @@ public class HttpClient extends ContainerLifeCycle
{
if (channel != null)
close(channel);
callback.failed(x);
promise.failed(x);
}
}
@ -660,7 +659,7 @@ public class HttpClient extends ContainerLifeCycle
// TODO: configureConnection, see above
appEndPoint.setConnection(connection);
callback.callback.succeeded();
callback.promise.succeeded(connection);
return sslConnection;
}
@ -669,7 +668,7 @@ public class HttpClient extends ContainerLifeCycle
{
HttpConnection connection = new HttpConnection(HttpClient.this, endPoint, destination);
// TODO: configureConnection, see above
callback.callback.succeeded();
callback.promise.succeeded(connection);
return connection;
}
}
@ -678,19 +677,19 @@ public class HttpClient extends ContainerLifeCycle
protected void connectionFailed(SocketChannel channel, Throwable ex, Object attachment)
{
ConnectionCallback callback = (ConnectionCallback)attachment;
callback.callback.failed(ex);
callback.promise.failed(ex);
}
}
private class ConnectionCallback extends FutureCallback<Connection>
private class ConnectionCallback extends FuturePromise<Connection>
{
private final HttpDestination destination;
private final Callback<Connection> callback;
private final Promise<Connection> promise;
private ConnectionCallback(HttpDestination destination, Callback<Connection> callback)
private ConnectionCallback(HttpDestination destination, Promise<Connection> promise)
{
this.destination = destination;
this.callback = callback;
this.promise = promise;
}
}
}

View File

@ -41,8 +41,6 @@ import org.eclipse.jetty.client.util.TimedResponseListener;
import org.eclipse.jetty.http.HttpHeader;
import org.eclipse.jetty.http.HttpMethod;
import org.eclipse.jetty.http.HttpScheme;
import org.eclipse.jetty.util.Callback;
import org.eclipse.jetty.util.FutureCallback;
import org.eclipse.jetty.util.FuturePromise;
import org.eclipse.jetty.util.Promise;
import org.eclipse.jetty.util.component.ContainerLifeCycle;
@ -161,7 +159,7 @@ public class HttpDestination implements Destination, AutoCloseable, Dumpable
public Future<Connection> newConnection()
{
FuturePromise<Connection> result = new FuturePromise<>();
newConnection(new CONNECTCallback(result));
newConnection(new CONNECTPromise(result));
return result;
}
@ -193,10 +191,10 @@ public class HttpDestination implements Destination, AutoCloseable, Dumpable
{
LOG.debug("Creating connection {}/{} for {}", next, maxConnections, this);
CONNECTCallback connectCallback = new CONNECTCallback(new Callback<Connection>()
CONNECTPromise connectPromise = new CONNECTPromise(new Promise<Connection>()
{
@Override
public void succeeded()
public void succeeded(Connection connection)
{
process(connection, true);
}
@ -210,13 +208,11 @@ public class HttpDestination implements Destination, AutoCloseable, Dumpable
public void run()
{
drain(x);
if (connection != null)
connection.close();
}
});
}
});
newConnection(new TCPPromise(next, maxConnections, connectCallback));
newConnection(new TCPPromise(next, maxConnections, connectPromise));
// Try again the idle connections
return idleConnections.poll();
}
@ -456,11 +452,11 @@ public class HttpDestination implements Destination, AutoCloseable, Dumpable
}
}
private class CONNECTCallback implements Promise<Connection>
private class CONNECTPromise implements Promise<Connection>
{
private final Promise<Connection> delegate;
private CONNECTCallback(Promise<Connection> delegate)
private CONNECTPromise(Promise<Connection> delegate)
{
this.delegate = delegate;
}
@ -499,14 +495,20 @@ public class HttpDestination implements Destination, AutoCloseable, Dumpable
if (result.isFailed())
{
failed(result.getFailure());
connection.close();
}
else
{
Response response = result.getResponse();
if (response.getStatus() == 200)
{
delegate.succeeded(connection);
}
else
{
failed(new HttpResponseException("Received " + response + " for " + result.getRequest(), response));
connection.close();
}
}
}
}));