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 if (LOG.isDebugEnabled())
50 LOG.debug("{} associated to {}", exchange, this);
51 }
52 else
53 {
54 exchange.getRequest().abort(new UnsupportedOperationException("Pipelined requests not supported"));
55 }
56 }
57
58 public HttpExchange disassociate()
59 {
60 HttpExchange exchange = this.exchange.getAndSet(null);
61 if (exchange != null)
62 exchange.disassociate(this);
63 if (LOG.isDebugEnabled())
64 LOG.debug("{} disassociated from {}", exchange, this);
65 return exchange;
66 }
67
68 public HttpExchange getHttpExchange()
69 {
70 return exchange.get();
71 }
72
73 public abstract void send();
74
75 public abstract void proceed(HttpExchange exchange, Throwable failure);
76
77 public abstract boolean abort(Throwable cause);
78
79 public void exchangeTerminated(Result result)
80 {
81 disassociate();
82 }
83
84 @Override
85 public String toString()
86 {
87 return String.format("%s@%h", getClass().getSimpleName(), this);
88 }
89 }