1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.eclipse.jetty.spdy.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.spdy.api.GoAwayInfo;
29 import org.eclipse.jetty.spdy.api.Session;
30 import org.eclipse.jetty.util.Callback;
31 import org.eclipse.jetty.util.ConcurrentHashSet;
32
33 public class HttpConnectionOverSPDY extends HttpConnection
34 {
35 private final Set<HttpChannel> channels = new ConcurrentHashSet<>();
36 private final Session session;
37
38 public HttpConnectionOverSPDY(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 HttpChannelOverSPDY(getHttpDestination(), this, session);
50 channels.add(channel);
51 channel.associate(exchange);
52 channel.send();
53 }
54
55 protected void release(HttpChannel channel)
56 {
57 channels.remove(channel);
58 }
59
60 @Override
61 public void close()
62 {
63
64
65 getHttpDestination().close(this);
66 session.goAway(new GoAwayInfo(), Callback.Adapter.INSTANCE);
67 abort(new AsynchronousCloseException());
68 }
69
70 private void abort(Throwable failure)
71 {
72 for (HttpChannel channel : channels)
73 {
74 HttpExchange exchange = channel.getHttpExchange();
75 if (exchange != null)
76 exchange.getRequest().abort(failure);
77 }
78 channels.clear();
79 }
80 }