View Javadoc

1   //
2   //  ========================================================================
3   //  Copyright (c) 1995-2016 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.client;
20  
21  import java.net.InetSocketAddress;
22  import java.util.Map;
23  
24  import org.eclipse.jetty.io.ClientConnectionFactory;
25  
26  /**
27   * {@link HttpClientTransport} represents what transport implementations should provide
28   * in order to plug-in a different transport for {@link HttpClient}.
29   * <p>
30   * While the {@link HttpClient} APIs define the HTTP semantic (request, response, headers, etc.)
31   * <em>how</em> a HTTP exchange is carried over the network depends on implementations of this class.
32   * <p>
33   * The default implementation uses the HTTP protocol to carry over the network the HTTP exchange,
34   * but the HTTP exchange may also be carried using the FCGI protocol, the HTTP/2 protocol or,
35   * in future, other protocols.
36   */
37  public interface HttpClientTransport extends ClientConnectionFactory
38  {
39      public static final String HTTP_DESTINATION_CONTEXT_KEY = "http.destination";
40      public static final String HTTP_CONNECTION_PROMISE_CONTEXT_KEY = "http.connection.promise";
41  
42      /**
43       * Sets the {@link HttpClient} instance on this transport.
44       * <p>
45       * This is needed because of a chicken-egg problem: in order to create the {@link HttpClient}
46       * a {@link HttpClientTransport} is needed, that therefore cannot have a reference yet to the
47       * {@link HttpClient}.
48       *
49       * @param client the {@link HttpClient} that uses this transport.
50       */
51      public void setHttpClient(HttpClient client);
52  
53      /**
54       * Creates a new, transport-specific, {@link HttpDestination} object.
55       * <p>
56       * {@link HttpDestination} controls the destination-connection cardinality: protocols like
57       * HTTP have 1-N cardinality, while multiplexed protocols like HTTP/2 have a 1-1 cardinality.
58       *
59       * @param origin the destination origin
60       * @return a new, transport-specific, {@link HttpDestination} object
61       */
62      public HttpDestination newHttpDestination(Origin origin);
63  
64      /**
65       * Establishes a physical connection to the given {@code address}.
66       *
67       *  @param address the address to connect to
68       * @param context the context information to establish the connection
69       */
70      public void connect(InetSocketAddress address, Map<String, Object> context);
71  }