View Javadoc

1   //
2   //  ========================================================================
3   //  Copyright (c) 1995-2014 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.spdy.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.api.Result;
25  import org.eclipse.jetty.spdy.api.Session;
26  
27  public class HttpChannelOverSPDY extends HttpChannel
28  {
29      private final HttpConnectionOverSPDY connection;
30      private final Session session;
31      private final HttpSenderOverSPDY sender;
32      private final HttpReceiverOverSPDY receiver;
33  
34      public HttpChannelOverSPDY(HttpDestination destination, HttpConnectionOverSPDY connection, Session session)
35      {
36          super(destination);
37          this.connection = connection;
38          this.session = session;
39          this.sender = new HttpSenderOverSPDY(this);
40          this.receiver = new HttpReceiverOverSPDY(this);
41      }
42  
43      public Session getSession()
44      {
45          return session;
46      }
47  
48      public HttpSenderOverSPDY getHttpSender()
49      {
50          return sender;
51      }
52  
53      public HttpReceiverOverSPDY getHttpReceiver()
54      {
55          return receiver;
56      }
57  
58      @Override
59      public void send()
60      {
61          HttpExchange exchange = getHttpExchange();
62          if (exchange != null)
63              sender.send(exchange);
64      }
65  
66      @Override
67      public void proceed(HttpExchange exchange, Throwable failure)
68      {
69          sender.proceed(exchange, failure);
70      }
71  
72      @Override
73      public boolean abort(Throwable cause)
74      {
75          sender.abort(cause);
76          return receiver.abort(cause);
77      }
78  
79      @Override
80      public void exchangeTerminated(Result result)
81      {
82          super.exchangeTerminated(result);
83          connection.release(this);
84      }
85  }