public interface SendInterceptor
There are three methods to implement, each of which executes "around" the sending of
a request, data or pipelined sequence of requests. The @{code aroundRequest} and
aroundPipelinedSequence
methods each receive an argument describing what is being
sent. All methods receive a Supplier<CompletableFuture<List<SmtpResponse>>>
called
next
that returns a future that will complete when the send has finished.
As an example, consider an interceptor used for timing commands. It can record the time
before the command/data is sent, then log the difference when the next
future completes.
class TimingInterceptor implements SendInterceptor {
private static final Logger LOG = LoggerFactory.getLogger(TimingInterceptor.class);
public CompletableFuture<List<SmtpResponse>> aroundRequest(SmtpRequest request, Supplier<CompletableFuture<List<SmtpResponse>>> next) {
long startedAt = System.currentTimeMillis();
return next.get().whenComplete((response, throwable) -> LOG.debug("{}: {}ms", request, System.currentTimeMillis() - startedAt);
}
public CompletableFuture<List<SmtpResponse>> aroundData(Supplier<CompletableFuture<List<SmtpResponse>>> next) {
long startedAt = System.currentTimeMillis();
return next.get().whenComplete((response, throwable) -> LOG.debug("data: {}ms", System.currentTimeMillis() - startedAt);
}
public CompletableFuture<List<SmtpResponse>> aroundPipelinedSequence(List<SmtpRequest> requests, Supplier<CompletableFuture<List<SmtpResponse>>> next) {
long startedAt = System.currentTimeMillis();
return next.get().whenComplete((response, throwable) -> LOG.debug("{}: {}ms", requests, System.currentTimeMillis() - startedAt);
}
}
CompositeSendInterceptor
Modifier and Type | Method and Description |
---|---|
CompletableFuture<List<io.netty.handler.codec.smtp.SmtpResponse>> |
aroundData(Supplier<CompletableFuture<List<io.netty.handler.codec.smtp.SmtpResponse>>> next)
Called before data is sent.
|
CompletableFuture<List<io.netty.handler.codec.smtp.SmtpResponse>> |
aroundPipelinedSequence(List<io.netty.handler.codec.smtp.SmtpRequest> requests,
Supplier<CompletableFuture<List<io.netty.handler.codec.smtp.SmtpResponse>>> next)
Called before a pipelined series of requests is sent.
|
CompletableFuture<List<io.netty.handler.codec.smtp.SmtpResponse>> |
aroundRequest(io.netty.handler.codec.smtp.SmtpRequest request,
Supplier<CompletableFuture<List<io.netty.handler.codec.smtp.SmtpResponse>>> next)
Called before a request is sent.
|
CompletableFuture<List<io.netty.handler.codec.smtp.SmtpResponse>> aroundRequest(io.netty.handler.codec.smtp.SmtpRequest request, Supplier<CompletableFuture<List<io.netty.handler.codec.smtp.SmtpResponse>>> next)
request
- the request that will be sentnext
- supplies a future that will complete when the request has been sent and a response receivednext.get()
, a CompletableFuture
derived from it, or an exceptional future if the send should
be abortedCompletableFuture<List<io.netty.handler.codec.smtp.SmtpResponse>> aroundData(Supplier<CompletableFuture<List<io.netty.handler.codec.smtp.SmtpResponse>>> next)
next
- supplies a future that will complete when the data has been sent and a response receivednext.get()
, a CompletableFuture
derived from it, or an exceptional future if the send should
be abortedCompletableFuture<List<io.netty.handler.codec.smtp.SmtpResponse>> aroundPipelinedSequence(List<io.netty.handler.codec.smtp.SmtpRequest> requests, Supplier<CompletableFuture<List<io.netty.handler.codec.smtp.SmtpResponse>>> next)
requests
- the requests that will be sentnext
- supplies a future that will complete when the requests have been sent and responses receivednext.get()
, a CompletableFuture
derived from it, or an exceptional future if the send should
be abortedCopyright © 2018. All rights reserved.