Package org.littleshoot.proxy.impl
Class ConnectionFlow
java.lang.Object
org.littleshoot.proxy.impl.ConnectionFlow
Coordinates the various steps involved in establishing a connection, such as
establishing a socket connection, SSL handshaking, HTTP CONNECT request
processing, and so on.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final ClientToProxyConnectionprivate final Objectprivate ConnectionFlowStepprivate final ProxyToServerConnectionprivate final Deque<ConnectionFlowStep>private boolean -
Constructor Summary
ConstructorsConstructorDescriptionConnectionFlow(ClientToProxyConnection clientConnection, ProxyToServerConnection serverConnection, Object connectLock) Construct a newConnectionFlowfor the given client and server connections. -
Method Summary
Modifier and TypeMethodDescription(package private) voidadvance()Advances the flow.private voidDoes the work of processing the current step, checking the result and handling success/failure.(package private) voidfail()Likefail(Throwable)but with no cause.(package private) voidCalled when the flow fails at someConnectionFlowStep.(package private) ConnectionFlowfirst(ConnectionFlowStep step) Add aConnectionFlowStepto the beginning of this flow.private ProxyProtocolMessagegetHAProxyMessage(InetSocketAddress clientAddress, InetSocketAddress remoteAddress) private voidOnce we've finished recording our connection and written our initial request, we can notify anyone who is waiting on the connection that it's okay to proceed.private voidProcess the currentConnectionFlowStep.(package private) voidWhile we're in the process of connecting, any messages read by theProxyToServerConnectionare passed to this method, which passes it on toConnectionFlowStep.read(ConnectionFlow, Object)for the currentConnectionFlowStep.private void(package private) voidstart()Starts the connection flow, notifying theClientToProxyConnectionthat we've started.(package private) voidsucceed()Called when the flow is complete and successful.(package private) ConnectionFlowthen(ConnectionFlowStep step) Add aConnectionFlowStepto the end of this flow.
-
Field Details
-
steps
-
clientConnection
-
serverConnection
-
currentStep
-
suppressInitialRequest
private volatile boolean suppressInitialRequest -
connectLock
-
-
Constructor Details
-
ConnectionFlow
ConnectionFlow(ClientToProxyConnection clientConnection, ProxyToServerConnection serverConnection, Object connectLock) Construct a newConnectionFlowfor the given client and server connections.- Parameters:
clientConnection-serverConnection-connectLock- an object that's shared byConnectionFlowandProxyToServerConnectionand that is used for synchronizing the reader and writer threads that are both involved during the establishing of a connection.
-
-
Method Details
-
first
Add aConnectionFlowStepto the beginning of this flow. -
then
Add aConnectionFlowStepto the end of this flow. -
read
While we're in the process of connecting, any messages read by theProxyToServerConnectionare passed to this method, which passes it on toConnectionFlowStep.read(ConnectionFlow, Object)for the currentConnectionFlowStep. -
start
void start()Starts the connection flow, notifying theClientToProxyConnectionthat we've started. -
advance
void advance()Advances the flow.
advance()will be called until we're either out of steps, or a step has failed. -
processCurrentStep
private void processCurrentStep()Process the current
ConnectionFlowStep. With each step, we:- Change the state of the associated
ProxyConnectionto the value ofConnectionFlowStep.getState() - Call
ConnectionFlowStep.execute() - On completion of the
Futurereturned byConnectionFlowStep.execute(), check the success. - If successful, we call back into
ConnectionFlowStep.onSuccess(ConnectionFlow). - If unsuccessful, we call
fail(), stopping the connection flow
- Change the state of the associated
-
doProcessCurrentStep
Does the work of processing the current step, checking the result and handling success/failure. -
succeed
void succeed()Called when the flow is complete and successful. Notifies theProxyToServerConnectionthat we succeeded. -
relayProxyInformation
private void relayProxyInformation() -
getHAProxyMessage
private ProxyProtocolMessage getHAProxyMessage(InetSocketAddress clientAddress, InetSocketAddress remoteAddress) -
fail
Called when the flow fails at someConnectionFlowStep. Disconnects theProxyToServerConnectionand informs theClientToProxyConnectionthat our connection failed. -
fail
void fail()Likefail(Throwable)but with no cause. -
notifyThreadsWaitingForConnection
private void notifyThreadsWaitingForConnection()Once we've finished recording our connection and written our initial request, we can notify anyone who is waiting on the connection that it's okay to proceed.
-