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.server;
20  
21  import java.nio.ByteBuffer;
22  
23  import org.eclipse.jetty.http.MetaData;
24  import org.eclipse.jetty.util.Callback;
25  
26  
27  /* ------------------------------------------------------------ */
28  /** Abstraction of the outbound HTTP transport.
29   */
30  public interface HttpTransport
31  {
32      /** Asynchronous call to send a response (or part) over the transport
33       * @param info The header info to send, or null if just sending more data.
34       *             The first call to send for a response must have a non null info.
35       * @param head True if the response if for a HEAD request (and the data should not be sent).
36       * @param content A buffer of content to be sent.
37       * @param lastContent True if the content is the last content for the current response.
38       * @param callback The Callback instance that success or failure of the send is notified on
39       */
40      void send(MetaData.Response info, boolean head, ByteBuffer content, boolean lastContent, Callback callback);
41  
42      /**
43       * @return true if responses can be pushed over this transport
44       */
45      boolean isPushSupported();
46  
47      /**
48       * @param request A request to use as the basis for generating a pushed response.
49       */
50      void push(MetaData.Request request);
51  
52      /**
53       * Called to indicated the end of the current request/response cycle (which may be
54       * some time after the last content is sent).
55       */
56      void onCompleted();
57      
58      /**
59       * Aborts this transport.
60       * <p>
61       * This method should terminate the transport in a way that
62       * can indicate an abnormal response to the client, for example
63       * by abruptly close the connection.
64       * <p>
65       * This method is called when an error response needs to be sent,
66       * but the response is already committed, or when a write failure
67       * is detected.  If abort is called, {@link #onCompleted()} is not
68       * called
69       *
70       * @param failure the failure that caused the abort.
71       */
72      void abort(Throwable failure);
73  
74      /* ------------------------------------------------------------ */
75      /** Is the underlying transport optimized for DirectBuffer usage
76       * @return True if direct buffers can be used optimally.
77       */
78      boolean isOptimizedForDirectBuffers();
79  }