Top Description Inners Fields Constructors Methods
org.eclipse.jetty.client.transport

public abstract Class HttpSender

extends Object
Class Inheritance
Known Direct Subclasses
org.eclipse.jetty.client.transport.internal.HttpSenderOverHTTP
Imports
java.net.URI, java.nio.ByteBuffer, java.util.concurrent.Executor, .RejectedExecutionException, java.util.concurrent.atomic.AtomicReference, org.eclipse.jetty.client.Request, .Result, org.eclipse.jetty.http.HttpHeader, .HttpHeaderValue, org.eclipse.jetty.io.Content, org.eclipse.jetty.util.BufferUtil, .Callback, .IteratingCallback, .Promise, org.slf4j.Logger, .LoggerFactory

HttpSender abstracts the algorithm to send HTTP requests, so that subclasses only implement the transport-specific code to send requests over the wire, implementing sendHeaders(HttpExchange, ByteBuffer, boolean, Callback) and sendContent(HttpExchange, ByteBuffer, boolean, Callback).

HttpSender governs the request state machines, which is updated as the various steps of sending a request are executed, see RequestState. At any point in time, a user thread may abort the request, which may (if the request has not been completely sent yet) move the request state machine to RequestState#FAILURE. The request state machine guarantees that the request steps are executed (by I/O threads) only if the request has not been failed already.

See Also
HttpReceiver

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class
private static enum
HttpSender.RequestState

The request states HttpSender goes through when sending a request.

Field Summary

Modifier and TypeField and Description
private final HttpChannel
private final HttpSender.ContentSender
private final AtomicReference<Throwable>
private static final Logger
private final AtomicReference<HttpSender.RequestState>

Constructor Summary

AccessConstructor and Description
protected

Method Summary

Modifier and TypeMethod and Description
public void
abort(HttpExchange exchange, Throwable failure, Promise<Boolean> promise)

private void
private boolean
protected boolean
protected void
private void
executeAbort(HttpExchange exchange, Throwable failure)

protected boolean
private void
private boolean
protected HttpChannel
protected HttpExchange
protected boolean
private void
public boolean
public void
proceed(HttpExchange exchange, Throwable failure)

protected boolean
protected String
protected void
public void
send(HttpExchange exchange)

protected abstract void
sendContent(HttpExchange
the exchange
exchange
,
ByteBuffer
the content to send
contentBuffer
,
boolean
whether the content is the last content to send
lastContent
,
Callback
the callback to notify
callback
)

Implementations should send the given HTTP content over the wire.

protected abstract void
sendHeaders(HttpExchange
the exchange
exchange
,
ByteBuffer
the content to send
contentBuffer
,
boolean
whether the content is the last content to send
lastContent
,
Callback
the callback to notify
callback
)

Implementations should send the HTTP headers over the wire, possibly with some content, in a single write, and notify the given callback of the result of this operation.

protected boolean
protected boolean
private void
terminateRequest(HttpExchange exchange, Throwable failure, Result result)

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

private boolean
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

channelback to summary
private final HttpChannel channel
contentSenderback to summary
private final HttpSender.ContentSender contentSender
failureback to summary
private final AtomicReference<Throwable> failure
LOGback to summary
private static final Logger LOG
requestStateback to summary
private final AtomicReference<HttpSender.RequestState> requestState

Constructor Detail

HttpSenderback to summary
protected HttpSender(HttpChannel channel)

Method Detail

abortback to summary
public void abort(HttpExchange exchange, Throwable failure, Promise<Boolean> promise)
abortRequestback to summary
private void abortRequest(HttpExchange exchange)
anyToFailureback to summary
private boolean anyToFailure(Throwable failure)
beginToHeadersback to summary
protected boolean beginToHeaders(HttpExchange exchange)
disposeback to summary
protected void dispose()
executeAbortback to summary
private void executeAbort(HttpExchange exchange, Throwable failure)
expects100Continueback to summary
protected boolean expects100Continue(Request request)
externalAbortback to summary
private void externalAbort(Throwable failure, Promise<Boolean> promise)
failRequestback to summary
private boolean failRequest(Throwable failure)
getHttpChannelback to summary
protected HttpChannel getHttpChannel()
getHttpExchangeback to summary
protected HttpExchange getHttpExchange()
headersToCommitback to summary
protected boolean headersToCommit(HttpExchange exchange)
internalAbortback to summary
private void internalAbort(HttpExchange exchange, Throwable failure)
isFailedback to summary
public boolean isFailed()
proceedback to summary
public void proceed(HttpExchange exchange, Throwable failure)
queuedToBeginback to summary
protected boolean queuedToBegin(HttpExchange exchange)
relativizeback to summary
protected String relativize(String path)
resetback to summary
protected void reset()
sendback to summary
public void send(HttpExchange exchange)
sendContentback to summary
protected abstract void sendContent(HttpExchange exchange, ByteBuffer contentBuffer, boolean lastContent, Callback callback)

Implementations should send the given HTTP content over the wire.

Parameters
exchange:HttpExchange

the exchange

contentBuffer:ByteBuffer

the content to send

lastContent:boolean

whether the content is the last content to send

callback:Callback

the callback to notify

sendHeadersback to summary
protected abstract void sendHeaders(HttpExchange exchange, ByteBuffer contentBuffer, boolean lastContent, Callback callback)

Implementations should send the HTTP headers over the wire, possibly with some content, in a single write, and notify the given callback of the result of this operation.

If there is more content to send, then sendContent(HttpExchange, ByteBuffer, boolean, Callback) will be invoked.

Parameters
exchange:HttpExchange

the exchange

contentBuffer:ByteBuffer

the content to send

lastContent:boolean

whether the content is the last content to send

callback:Callback

the callback to notify

someToContentback to summary
protected boolean someToContent(HttpExchange exchange, ByteBuffer content)
someToSuccessback to summary
protected boolean someToSuccess(HttpExchange exchange)
terminateRequestback to summary
private void terminateRequest(HttpExchange exchange, Throwable failure, Result result)
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override
updateRequestStateback to summary
private boolean updateRequestState(HttpSender.RequestState from, HttpSender.RequestState to)
org.eclipse.jetty.client.transport back to summary

private Class HttpSender.ContentSender

extends IteratingCallback
Class Inheritance

Field Summary

Modifier and TypeField and Description
private Promise<Boolean>
private Content.Chunk
private boolean
private boolean
private ByteBuffer
private HttpExchange
private boolean
private boolean

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public Invocable.InvocationType
protected void
onCompleteFailure(Throwable
the throwable to indicate cause of failure
x
)

Overrides org.eclipse.jetty.util.IteratingCallback.onCompleteFailure.

Invoked when the overall task has completed with a failure.

protected IteratingCallback.Action
process()

Implements abstract org.eclipse.jetty.util.IteratingCallback.process.

Method called by iterate() to process the asynchronous sub-task.

public boolean
reset()

Overrides org.eclipse.jetty.util.IteratingCallback.reset.

Resets this callback.

public void
succeeded()

Overrides org.eclipse.jetty.util.IteratingCallback.succeeded.

Overrides default org.eclipse.jetty.util.Callback.succeeded.

Method to invoke when the asynchronous sub-task succeeds.

Inherited from org.eclipse.jetty.util.IteratingCallback:
abortclosefailedisAbortedisClosedisFailedisSucceedediterateonCompleteSuccesstoString

Field Detail

abortback to summary
private Promise<Boolean> abort
chunkback to summary
private Content.Chunk chunk
committedback to summary
private boolean committed
completeback to summary
private boolean complete
contentBufferback to summary
private ByteBuffer contentBuffer
exchangeback to summary
private HttpExchange exchange
expect100back to summary
private boolean expect100
successback to summary
private boolean success

Constructor Detail

ContentSenderback to summary
private ContentSender()

Method Detail

getInvocationTypeback to summary
public Invocable.InvocationType getInvocationType()

Overrides default org.eclipse.jetty.util.thread.Invocable.getInvocationType.

Returns:Invocable.InvocationType

Doc from org.eclipse.jetty.util.thread.Invocable.getInvocationType.

The InvocationType of this object

Annotations
@Override
onCompleteFailureback to summary
protected void onCompleteFailure(Throwable x)

Overrides org.eclipse.jetty.util.IteratingCallback.onCompleteFailure.

Doc from org.eclipse.jetty.util.IteratingCallback.onCompleteFailure.

Invoked when the overall task has completed with a failure.

Parameters
x:Throwable

the throwable to indicate cause of failure

Annotations
@Override
processback to summary
protected IteratingCallback.Action process() throws Throwable

Implements abstract org.eclipse.jetty.util.IteratingCallback.process.

Doc from org.eclipse.jetty.util.IteratingCallback.process.

Method called by iterate() to process the asynchronous sub-task.

Implementations must initiate the asynchronous execution of the sub-task (if any) and return an appropriate action:

  • Action#IDLE when no sub tasks are available for execution but the overall job is not completed yet
  • Action#SCHEDULED when the sub task asynchronous execution has been started
  • Action#SUCCEEDED when the overall job is completed
Returns:IteratingCallback.Action

the appropriate Action

Annotations
@Override
Exceptions
Throwable:
if the sub-task processing throws
resetback to summary
public boolean reset()

Overrides org.eclipse.jetty.util.IteratingCallback.reset.

Doc from org.eclipse.jetty.util.IteratingCallback.reset.

Resets this callback.

A callback can only be reset to the idle state from the succeeded or failed states or if it is already idle.

Returns:boolean

true if the reset was successful

Annotations
@Override
succeededback to summary
public void succeeded()

Overrides org.eclipse.jetty.util.IteratingCallback.succeeded.

Overrides default org.eclipse.jetty.util.Callback.succeeded.

Doc from org.eclipse.jetty.util.IteratingCallback.succeeded.

Method to invoke when the asynchronous sub-task succeeds.

Subclasses that override this method must always remember to call super.succeeded().

Annotations
@Override
org.eclipse.jetty.client.transport back to summary

private final Enum HttpSender.RequestState

extends Enum<HttpSender.RequestState>
Class Inheritance

The request states HttpSender goes through when sending a request.

Field Summary

Modifier and TypeField and Description
public static final HttpSender.RequestState
BEGIN

The request has been dequeued

public static final HttpSender.RequestState
COMMIT

The request headers (and possibly some content) have been sent

public static final HttpSender.RequestState
CONTENT

The request content is being sent

public static final HttpSender.RequestState
FAILURE

The request is failed

public static final HttpSender.RequestState
HEADERS

The request headers (and possibly some content) is about to be sent

public static final HttpSender.RequestState
QUEUED

The request is queued, the initial state

public static final HttpSender.RequestState
TRANSIENT

One of the state transition methods is being executed.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static HttpSender.RequestState
public static HttpSender.RequestState[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

BEGINback to summary
public static final HttpSender.RequestState BEGIN

The request has been dequeued

COMMITback to summary
public static final HttpSender.RequestState COMMIT

The request headers (and possibly some content) have been sent

CONTENTback to summary
public static final HttpSender.RequestState CONTENT

The request content is being sent

FAILUREback to summary
public static final HttpSender.RequestState FAILURE

The request is failed

HEADERSback to summary
public static final HttpSender.RequestState HEADERS

The request headers (and possibly some content) is about to be sent

QUEUEDback to summary
public static final HttpSender.RequestState QUEUED

The request is queued, the initial state

TRANSIENTback to summary
public static final HttpSender.RequestState TRANSIENT

One of the state transition methods is being executed.

Constructor Detail

RequestStateback to summary
private RequestState()

Method Detail

valueOfback to summary
public static HttpSender.RequestState valueOf(String name)
valuesback to summary
public static HttpSender.RequestState[] values()