Fixed notification of Session's promise upon connect: it must be

notified only after we have successfully sent the preface bytes.
This commit is contained in:
Simone Bordet 2014-06-15 16:39:23 +02:00
parent 75b0a7088b
commit a500701bda
1 changed files with 20 additions and 7 deletions

View File

@ -120,19 +120,19 @@ public class HTTP2Client extends ContainerLifeCycle
Generator generator = new Generator(byteBufferPool, 4096); Generator generator = new Generator(byteBufferPool, 4096);
HTTP2Session session = new HTTP2ClientSession(endpoint, generator, context.listener, new HTTP2FlowControl(65535)); HTTP2Session session = new HTTP2ClientSession(endpoint, generator, context.listener, new HTTP2FlowControl(65535));
Parser parser = new Parser(byteBufferPool, session); Parser parser = new Parser(byteBufferPool, session);
Connection connection = new HTTP2ClientConnection(byteBufferPool, getExecutor(), endpoint, parser, 8192, session); return new HTTP2ClientConnection(byteBufferPool, getExecutor(), endpoint, parser, 8192, context.promise, session);
context.promise.succeeded(session);
return connection;
} }
} }
private class HTTP2ClientConnection extends HTTP2Connection private class HTTP2ClientConnection extends HTTP2Connection implements Callback
{ {
private final Promise<Session> promise;
private final Session session; private final Session session;
public HTTP2ClientConnection(ByteBufferPool byteBufferPool, Executor executor, EndPoint endpoint, Parser parser, int bufferSize, Session session) public HTTP2ClientConnection(ByteBufferPool byteBufferPool, Executor executor, EndPoint endpoint, Parser parser, int bufferSize, Promise<Session> promise, Session session)
{ {
super(byteBufferPool, executor, endpoint, parser, bufferSize); super(byteBufferPool, executor, endpoint, parser, bufferSize);
this.promise = promise;
this.session = session; this.session = session;
} }
@ -140,8 +140,7 @@ public class HTTP2Client extends ContainerLifeCycle
public void onOpen() public void onOpen()
{ {
super.onOpen(); super.onOpen();
sessions.offer(session); getEndPoint().write(this, ByteBuffer.wrap(PrefaceParser.PREFACE_BYTES));
getEndPoint().write(Callback.Adapter.INSTANCE, ByteBuffer.wrap(PrefaceParser.PREFACE_BYTES));
} }
@Override @Override
@ -150,6 +149,20 @@ public class HTTP2Client extends ContainerLifeCycle
super.onClose(); super.onClose();
sessions.remove(session); sessions.remove(session);
} }
@Override
public void succeeded()
{
sessions.offer(session);
promise.succeeded(session);
}
@Override
public void failed(Throwable x)
{
close();
promise.failed(x);
}
} }
private class Context private class Context