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.api;
20  
21  import org.eclipse.jetty.client.HttpClient;
22  import org.eclipse.jetty.util.FuturePromise;
23  import org.eclipse.jetty.util.Promise;
24  
25  /**
26   * {@link Destination} represents the triple made of the {@link #getScheme}, the {@link #getHost}
27   * and the {@link #getPort}.
28   * <p>
29   * {@link Destination} holds a pool of {@link Connection}s, but allows to create unpooled
30   * connections if the application wants full control over connection management via {@link #newConnection(Promise)}.
31   * <p>
32   * {@link Destination}s may be obtained via {@link HttpClient#getDestination(String, String, int)}
33   */
34  public interface Destination
35  {
36      /**
37       * @return the scheme of this destination, such as "http" or "https"
38       */
39      String getScheme();
40  
41      /**
42       * @return the host of this destination, such as "127.0.0.1" or "google.com"
43       */
44      String getHost();
45  
46      /**
47       * @return the port of this destination such as 80 or 443
48       */
49      int getPort();
50  
51      /**
52       * Creates asynchronously a new, unpooled, {@link Connection} that will be returned
53       * at a later time through the given {@link Promise}.
54       * <p>
55       * Use {@link FuturePromise} to wait for the connection:
56       * <pre>
57       * Destination destination = ...;
58       * FuturePromise&lt;Connection&gt; futureConnection = new FuturePromise&lt;&gt;();
59       * destination.newConnection(futureConnection);
60       * Connection connection = futureConnection.get(5, TimeUnit.SECONDS);
61       * </pre>
62       *
63       * @param promise the promise of a new, unpooled, {@link Connection}
64       */
65      void newConnection(Promise<Connection> promise);
66  }