Top Inners Fields Constructors Methods
io.netty.contrib.handler.proxy

public abstract Class ProxyHandler

extends Object
implements ChannelHandler
Class Inheritance
All Implemented Interfaces
io.netty5.channel.ChannelHandler
Known Direct Subclasses
io.netty.contrib.handler.proxy.Socks4ProxyHandler, io.netty.contrib.handler.proxy.Socks5ProxyHandler, io.netty.contrib.handler.proxy.HttpProxyHandler
Imports
io.netty5.channel.Channel, .ChannelHandler, .ChannelHandlerContext, .ChannelOption, .PendingWriteQueue, io.netty5.util.Resource, io.netty5.util.concurrent.DefaultPromise, .Future, .FutureListener, .ImmediateEventExecutor, .Promise, io.netty5.util.internal.logging.InternalLogger, .InternalLoggerFactory, java.net.SocketAddress, java.nio.channels.ConnectionPendingException, java.util.concurrent.TimeUnit

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class

Field Summary

Modifier and TypeField and Description
pack-priv static final String
AUTH_NONE

A string that signifies 'no authentication' or 'anonymous'.

private final Promise<Channel>
private Future<?>
private volatile long
private volatile ChannelHandlerContext
private static final long
DEFAULT_CONNECT_TIMEOUT_MILLIS

The default connect timeout: 10 seconds.

private volatile SocketAddress
private boolean
private boolean
private static final InternalLogger
private PendingWriteQueue
private final SocketAddress
private boolean
private final FutureListener<Void>

Constructor Summary

AccessConstructor and Description
protected

Method Summary

Modifier and TypeMethod and Description
protected abstract void
addCodec(ChannelHandlerContext ctx)

Adds the codec handlers required to communicate with the proxy server.

private void
public abstract String
authScheme()

Returns the name of the authentication scheme in use.

private void
public final void
public final void
channelExceptionCaught(ChannelHandlerContext ctx, Throwable cause)

Overrides default io.netty5.channel.ChannelHandler.channelExceptionCaught.

Gets called if a Throwable was thrown when handling inbound events.
public final void
channelInactive(ChannelHandlerContext ctx)

Overrides default io.netty5.channel.ChannelHandler.channelInactive.

The Channel of the ChannelHandlerContext was registered is now inactive and reached its end of lifetime.
public final void
channelRead(ChannelHandlerContext ctx, Object msg)

Overrides default io.netty5.channel.ChannelHandler.channelRead.

Invoked when the current Channel has read a message from the peer.
public final void
channelReadComplete(ChannelHandlerContext ctx)

Overrides default io.netty5.channel.ChannelHandler.channelReadComplete.

Invoked when the last message read by the current read operation has been consumed by channelRead(ChannelHandlerContext, Object).
public final Future<Void>
connect(ChannelHandlerContext
the ChannelHandlerContext for which the connect operation is made
ctx
,
SocketAddress
the SocketAddress to which it should connect
remoteAddress
,
SocketAddress
the SocketAddress which is used as source on connect
localAddress
)

Overrides default io.netty5.channel.ChannelHandler.connect.

Called once a connect operation is made.
public final Future<Channel>
connectFuture()

Returns a Future that is notified when the connection to the destination has been established or the connection attempt has failed.

public final long
connectTimeoutMillis()

Returns the connect timeout in millis.

public final <T extends SocketAddress> T
destinationAddress()

Returns the address of the destination to connect to via the proxy server.

protected final String
exceptionMessage(String msg)

Decorates the specified exception message with the common information such as the current protocol, authentication scheme, proxy address, and destination address.

private void
private void
public final void
flush(ChannelHandlerContext
the ChannelHandlerContext for which the flush operation is made
ctx
)

Overrides default io.netty5.channel.ChannelHandler.flush.

Called once a flush operation is made.
public final void
handlerAdded(ChannelHandlerContext ctx)

Overrides default io.netty5.channel.ChannelHandler.handlerAdded.

Gets called after the ChannelHandler was added to the actual context and it's ready to handle events.
protected abstract boolean

Returns:

true if the connection to the destination has been established, false if the connection to the destination has not been established and more messages are expected from the proxy server
handleResponse
(ChannelHandlerContext ctx, Object response)

Handles the message received from the proxy server.

public final boolean
isConnected()

Returns true if and only if the connection to the destination has been established successfully.

protected abstract Object

Returns:

the initial message, or null if the proxy server is expected to send the first message instead
newInitialMessage
(ChannelHandlerContext ctx)

Returns a new message that is sent at first time when the connection to the proxy server has been established.

public abstract String
protocol()

Returns the name of the proxy protocol in use.

public final <T extends SocketAddress> T
proxyAddress()

Returns the address of the proxy server.

private static void
protected abstract void
protected abstract void
private boolean
private boolean
private void
sendInitialMessage(final ChannelHandlerContext ctx)

Sends the initial message to be sent to the proxy server.

protected final void
sendToProxyServer(Object msg)

Sends the specified message to the proxy server.

private void
private void
public final void
setConnectTimeoutMillis(long connectTimeoutMillis)

Sets the connect timeout in millis.

public final Future<Void>
write(ChannelHandlerContext
the ChannelHandlerContext for which the write operation is made
ctx
,
Object
the message to write
msg
)

Overrides default io.netty5.channel.ChannelHandler.write.

Called once a write operation is made.
private void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

AUTH_NONEback to summary
pack-priv static final String AUTH_NONE

A string that signifies 'no authentication' or 'anonymous'.

connectPromiseback to summary
private final Promise<Channel> connectPromise
connectTimeoutFutureback to summary
private Future<?> connectTimeoutFuture
connectTimeoutMillisback to summary
private volatile long connectTimeoutMillis
ctxback to summary
private volatile ChannelHandlerContext ctx
DEFAULT_CONNECT_TIMEOUT_MILLISback to summary
private static final long DEFAULT_CONNECT_TIMEOUT_MILLIS

The default connect timeout: 10 seconds.

destinationAddressback to summary
private volatile SocketAddress destinationAddress
finishedback to summary
private boolean finished
flushedPrematurelyback to summary
private boolean flushedPrematurely
loggerback to summary
private static final InternalLogger logger
pendingWritesback to summary
private PendingWriteQueue pendingWrites
proxyAddressback to summary
private final SocketAddress proxyAddress
suppressChannelReadCompleteback to summary
private boolean suppressChannelReadComplete
writeListenerback to summary
private final FutureListener<Void> writeListener

Constructor Detail

ProxyHandlerback to summary
protected ProxyHandler(SocketAddress proxyAddress)

Method Detail

addCodecback to summary
protected abstract void addCodec(ChannelHandlerContext ctx) throws Exception

Adds the codec handlers required to communicate with the proxy server.

addPendingWriteback to summary
private void addPendingWrite(ChannelHandlerContext ctx, Object msg, Promise<Void> promise)
authSchemeback to summary
public abstract String authScheme()

Returns the name of the authentication scheme in use.

cancelConnectTimeoutFutureback to summary
private void cancelConnectTimeoutFuture()
channelActiveback to summary
public final void channelActive(ChannelHandlerContext ctx) throws Exception

Overrides default io.netty5.channel.ChannelHandler.channelActive.

Doc from io.netty5.channel.ChannelHandler.channelActive.

The Channel of the ChannelHandlerContext is now active

Annotations
@Override
channelExceptionCaughtback to summary
public final void channelExceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception

Overrides default io.netty5.channel.ChannelHandler.channelExceptionCaught.

Doc from io.netty5.channel.ChannelHandler.channelExceptionCaught.

Gets called if a Throwable was thrown when handling inbound events.

Annotations
@Override
channelInactiveback to summary
public final void channelInactive(ChannelHandlerContext ctx) throws Exception

Overrides default io.netty5.channel.ChannelHandler.channelInactive.

Doc from io.netty5.channel.ChannelHandler.channelInactive.

The Channel of the ChannelHandlerContext was registered is now inactive and reached its end of lifetime.

Annotations
@Override
channelReadback to summary
public final void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception

Overrides default io.netty5.channel.ChannelHandler.channelRead.

Doc from io.netty5.channel.ChannelHandler.channelRead.

Invoked when the current Channel has read a message from the peer.

Annotations
@Override
channelReadCompleteback to summary
public final void channelReadComplete(ChannelHandlerContext ctx) throws Exception

Overrides default io.netty5.channel.ChannelHandler.channelReadComplete.

Doc from io.netty5.channel.ChannelHandler.channelReadComplete.

Invoked when the last message read by the current read operation has been consumed by channelRead(ChannelHandlerContext, Object). If ChannelOption#AUTO_READ is off, no further attempt to read an inbound data from the current Channel will be made until ChannelOutboundInvoker#read(ReadBufferAllocator) is called.

Annotations
@Override
connectback to summary
public final Future<Void> connect(ChannelHandlerContext ctx, SocketAddress remoteAddress, SocketAddress localAddress)

Overrides default io.netty5.channel.ChannelHandler.connect.

Doc from io.netty5.channel.ChannelHandler.connect.

Called once a connect operation is made.

Parameters
ctx:ChannelHandlerContext

the ChannelHandlerContext for which the connect operation is made

remoteAddress:SocketAddress

the SocketAddress to which it should connect

localAddress:SocketAddress

the SocketAddress which is used as source on connect

Returns:Future<Void>

the Future which will be notified once the operation completes.

Annotations
@Override
connectFutureback to summary
public final Future<Channel> connectFuture()

Returns a Future that is notified when the connection to the destination has been established or the connection attempt has failed.

connectTimeoutMillisback to summary
public final long connectTimeoutMillis()

Returns the connect timeout in millis. If the connection attempt to the destination does not finish within the timeout, the connection attempt will be failed.

destinationAddressback to summary
public final <T extends SocketAddress> T destinationAddress()

Returns the address of the destination to connect to via the proxy server.

Annotations
@SuppressWarnings:unchecked
exceptionMessageback to summary
protected final String exceptionMessage(String msg)

Decorates the specified exception message with the common information such as the current protocol, authentication scheme, proxy address, and destination address.

failPendingWritesback to summary
private void failPendingWrites(Throwable cause)
failPendingWritesAndCloseback to summary
private void failPendingWritesAndClose(Throwable cause)
flushback to summary
public final void flush(ChannelHandlerContext ctx)

Overrides default io.netty5.channel.ChannelHandler.flush.

Doc from io.netty5.channel.ChannelHandler.flush.

Called once a flush operation is made. The flush operation will try to flush out all previous written messages that are pending.

Parameters
ctx:ChannelHandlerContext

the ChannelHandlerContext for which the flush operation is made

Annotations
@Override
handlerAddedback to summary
public final void handlerAdded(ChannelHandlerContext ctx) throws Exception

Overrides default io.netty5.channel.ChannelHandler.handlerAdded.

Doc from io.netty5.channel.ChannelHandler.handlerAdded.

Gets called after the ChannelHandler was added to the actual context and it's ready to handle events.

Annotations
@Override
handleResponseback to summary
protected abstract boolean handleResponse(ChannelHandlerContext ctx, Object response) throws Exception

Handles the message received from the proxy server.

Returns:boolean

true if the connection to the destination has been established, false if the connection to the destination has not been established and more messages are expected from the proxy server

isConnectedback to summary
public final boolean isConnected()

Returns true if and only if the connection to the destination has been established successfully.

newInitialMessageback to summary
protected abstract Object newInitialMessage(ChannelHandlerContext ctx) throws Exception

Returns a new message that is sent at first time when the connection to the proxy server has been established.

Returns:Object

the initial message, or null if the proxy server is expected to send the first message instead

protocolback to summary
public abstract String protocol()

Returns the name of the proxy protocol in use.

proxyAddressback to summary
public final <T extends SocketAddress> T proxyAddress()

Returns the address of the proxy server.

Annotations
@SuppressWarnings:unchecked
readIfNeededback to summary
private static void readIfNeeded(ChannelHandlerContext ctx)
removeDecoderback to summary
protected abstract void removeDecoder(ChannelHandlerContext ctx) throws Exception

Removes the decoders added in addCodec(ChannelHandlerContext).

removeEncoderback to summary
protected abstract void removeEncoder(ChannelHandlerContext ctx) throws Exception

Removes the encoders added in addCodec(ChannelHandlerContext).

safeRemoveDecoderback to summary
private boolean safeRemoveDecoder()
safeRemoveEncoderback to summary
private boolean safeRemoveEncoder()
sendInitialMessageback to summary
private void sendInitialMessage(final ChannelHandlerContext ctx) throws Exception

Sends the initial message to be sent to the proxy server. This method also starts a timeout task which marks the connectPromise as failure if the connection attempt does not success within the timeout.

sendToProxyServerback to summary
protected final void sendToProxyServer(Object msg)

Sends the specified message to the proxy server. Use this method to send a response to the proxy server in handleResponse(ChannelHandlerContext, Object).

setConnectFailureback to summary
private void setConnectFailure(Throwable cause)
setConnectSuccessback to summary
private void setConnectSuccess(ChannelHandlerContext ctx)
setConnectTimeoutMillisback to summary
public final void setConnectTimeoutMillis(long connectTimeoutMillis)

Sets the connect timeout in millis. If the connection attempt to the destination does not finish within the timeout, the connection attempt will be failed.

writeback to summary
public final Future<Void> write(ChannelHandlerContext ctx, Object msg)

Overrides default io.netty5.channel.ChannelHandler.write.

Doc from io.netty5.channel.ChannelHandler.write.

Called once a write operation is made. The write operation will write the messages through the ChannelPipeline. Those are then ready to be flushed to the actual Channel once Channel#flush() is called.

Parameters
ctx:ChannelHandlerContext

the ChannelHandlerContext for which the write operation is made

msg:Object

the message to write

Returns:Future<Void>

the Future which will be notified once the operation completes.

Annotations
@Override
writePendingWritesback to summary
private void writePendingWrites(ChannelHandlerContext ctx)
io.netty.contrib.handler.proxy back to summary

private final Class ProxyHandler.LazyPromise

extends DefaultPromise<Channel>
Class Inheritance

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
protected void
Inherited from io.netty5.util.concurrent.DefaultPromise:
acceptEitheracceptEitherAsyncacceptEitherAsyncaddListeneraddListenerapplyToEitherapplyToEitherAsyncapplyToEitherAsyncasFutureasStageawaitawaitcancelcancelcausecheckDeadLockexceptionallyexecutorfuturegetgetgetNowhandlehandleAsynchandleAsyncisCancellableisCancelledisDoneisFailedisSuccessrunAfterBothrunAfterBothAsyncrunAfterBothAsyncrunAfterEitherrunAfterEitherAsyncrunAfterEitherAsyncsetFailuresetSuccesssetUncancellablesyncthenAcceptthenAcceptAsyncthenAcceptAsyncthenAcceptBoththenAcceptBothAsyncthenAcceptBothAsyncthenApplythenApplyAsyncthenApplyAsyncthenCombinethenCombineAsyncthenCombineAsyncthenComposethenComposeAsyncthenComposeAsyncthenRunthenRunAsyncthenRunAsynctoStringtoStringBuildertryFailuretrySuccesswhenCompletewhenCompleteAsyncwhenCompleteAsync

Constructor Detail

LazyPromiseback to summary
pack-priv LazyPromise()

Method Detail

checkDeadLockback to summary
protected void checkDeadLock()

Overrides io.netty5.util.concurrent.DefaultPromise.checkDeadLock.

Annotations
@Override