1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.eclipse.jetty.client;
20
21 import java.util.concurrent.atomic.AtomicReference;
22
23 import org.eclipse.jetty.client.api.Result;
24 import org.eclipse.jetty.util.log.Log;
25 import org.eclipse.jetty.util.log.Logger;
26
27 public abstract class HttpChannel
28 {
29 protected static final Logger LOG = Log.getLogger(HttpChannel.class);
30
31 private final AtomicReference<HttpExchange> exchange = new AtomicReference<>();
32 private final HttpDestination destination;
33
34 protected HttpChannel(HttpDestination destination)
35 {
36 this.destination = destination;
37 }
38
39 public HttpDestination getHttpDestination()
40 {
41 return destination;
42 }
43
44 public void associate(HttpExchange exchange)
45 {
46 if (this.exchange.compareAndSet(null, exchange))
47 {
48 exchange.associate(this);
49 LOG.debug("{} associated to {}", exchange, this);
50 }
51 else
52 {
53 exchange.getRequest().abort(new UnsupportedOperationException("Pipelined requests not supported"));
54 }
55 }
56
57 public HttpExchange disassociate()
58 {
59 HttpExchange exchange = this.exchange.getAndSet(null);
60 if (exchange != null)
61 exchange.disassociate(this);
62 LOG.debug("{} disassociated from {}", exchange, this);
63 return exchange;
64 }
65
66 public HttpExchange getHttpExchange()
67 {
68 return exchange.get();
69 }
70
71 public abstract void send();
72
73 public abstract void proceed(HttpExchange exchange, Throwable failure);
74
75 public abstract boolean abort(Throwable cause);
76
77 public void exchangeTerminated(Result result)
78 {
79 disassociate();
80 }
81
82 @Override
83 public String toString()
84 {
85 return String.format("%s@%h", getClass().getSimpleName(), this);
86 }
87 }