View Javadoc

1   //
2   //  ========================================================================
3   //  Copyright (c) 1995-2015 Mort Bay Consulting Pty. Ltd.
4   //  ------------------------------------------------------------------------
5   //  All rights reserved. This program and the accompanying materials
6   //  are made available under the terms of the Eclipse Public License v1.0
7   //  and Apache License v2.0 which accompanies this distribution.
8   //
9   //      The Eclipse Public License is available at
10  //      http://www.eclipse.org/legal/epl-v10.html
11  //
12  //      The Apache License v2.0 is available at
13  //      http://www.opensource.org/licenses/apache2.0.php
14  //
15  //  You may elect to redistribute this code under either of these licenses.
16  //  ========================================================================
17  //
18  
19  package org.eclipse.jetty.http2.client.http;
20  
21  import org.eclipse.jetty.client.HttpChannel;
22  import org.eclipse.jetty.client.HttpDestination;
23  import org.eclipse.jetty.client.HttpExchange;
24  import org.eclipse.jetty.client.HttpReceiver;
25  import org.eclipse.jetty.client.HttpSender;
26  import org.eclipse.jetty.client.api.Result;
27  import org.eclipse.jetty.http2.api.Session;
28  import org.eclipse.jetty.http2.api.Stream;
29  
30  public class HttpChannelOverHTTP2 extends HttpChannel
31  {
32      private final HttpConnectionOverHTTP2 connection;
33      private final Session session;
34      private final HttpSenderOverHTTP2 sender;
35      private final HttpReceiverOverHTTP2 receiver;
36  
37      public HttpChannelOverHTTP2(HttpDestination destination, HttpConnectionOverHTTP2 connection, Session session)
38      {
39          super(destination);
40          this.connection = connection;
41          this.session = session;
42          this.sender = new HttpSenderOverHTTP2(this);
43          this.receiver = new HttpReceiverOverHTTP2(this);
44      }
45  
46      public Session getSession()
47      {
48          return session;
49      }
50  
51      public Stream.Listener getStreamListener()
52      {
53          return receiver;
54      }
55  
56      @Override
57      protected HttpSender getHttpSender()
58      {
59          return sender;
60      }
61  
62      @Override
63      protected HttpReceiver getHttpReceiver()
64      {
65          return receiver;
66      }
67  
68      @Override
69      public void send()
70      {
71          HttpExchange exchange = getHttpExchange();
72          if (exchange != null)
73              sender.send(exchange);
74      }
75  
76      @Override
77      public void release()
78      {
79          connection.release(this);
80      }
81  
82      @Override
83      public void exchangeTerminated(HttpExchange exchange, Result result)
84      {
85          super.exchangeTerminated(exchange, result);
86          release();
87      }
88  }