1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.eclipse.jetty.http2.client.http;
20
21 import java.nio.channels.AsynchronousCloseException;
22 import java.util.Set;
23
24 import org.eclipse.jetty.client.HttpChannel;
25 import org.eclipse.jetty.client.HttpConnection;
26 import org.eclipse.jetty.client.HttpDestination;
27 import org.eclipse.jetty.client.HttpExchange;
28 import org.eclipse.jetty.http2.ErrorCode;
29 import org.eclipse.jetty.http2.api.Session;
30 import org.eclipse.jetty.util.Callback;
31 import org.eclipse.jetty.util.ConcurrentHashSet;
32
33 public class HttpConnectionOverHTTP2 extends HttpConnection
34 {
35 private final Set<HttpChannel> channels = new ConcurrentHashSet<>();
36 private final Session session;
37
38 public HttpConnectionOverHTTP2(HttpDestination destination, Session session)
39 {
40 super(destination);
41 this.session = session;
42 }
43
44 @Override
45 protected void send(HttpExchange exchange)
46 {
47 normalizeRequest(exchange.getRequest());
48
49 HttpChannel channel = new HttpChannelOverHTTP2(getHttpDestination(), this, session);
50 channels.add(channel);
51 if (channel.associate(exchange))
52 channel.send();
53 else
54 channel.release();
55 }
56
57 protected void release(HttpChannel channel)
58 {
59 channels.remove(channel);
60 }
61
62 @Override
63 public void close()
64 {
65
66
67 getHttpDestination().close(this);
68 session.close(ErrorCode.NO_ERROR.code, null, Callback.NOOP);
69 abort(new AsynchronousCloseException());
70 }
71
72 private void abort(Throwable failure)
73 {
74 for (HttpChannel channel : channels)
75 {
76 HttpExchange exchange = channel.getHttpExchange();
77 if (exchange != null)
78 exchange.getRequest().abort(failure);
79 }
80 channels.clear();
81 }
82 }