Package org.littleshoot.proxy.impl
Class ConnectionFlow
- java.lang.Object
-
- org.littleshoot.proxy.impl.ConnectionFlow
-
class ConnectionFlow extends Object
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
Fields Modifier and Type Field Description private ClientToProxyConnectionclientConnectionprivate ObjectconnectLockprivate ConnectionFlowStepcurrentStepprivate ProxyToServerConnectionserverConnectionprivate Deque<ConnectionFlowStep>stepsprivate booleansuppressInitialRequest
-
Constructor Summary
Constructors Constructor Description ConnectionFlow(ClientToProxyConnection clientConnection, ProxyToServerConnection serverConnection, Object connectLock)Construct a newConnectionFlowfor the given client and server connections.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) voidadvance()Advances the flow.private voiddoProcessCurrentStep(ProxyConnectionLogger LOG)Does 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) voidfail(Throwable cause)Called 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 voidnotifyThreadsWaitingForConnection()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.private voidprocessCurrentStep()Process the currentConnectionFlowStep.(package private) voidread(Object msg)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.private voidrelayProxyInformation()(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 Detail
-
steps
private final Deque<ConnectionFlowStep> steps
-
clientConnection
private final ClientToProxyConnection clientConnection
-
serverConnection
private final ProxyToServerConnection serverConnection
-
currentStep
private volatile ConnectionFlowStep currentStep
-
suppressInitialRequest
private volatile boolean suppressInitialRequest
-
connectLock
private final Object connectLock
-
-
Constructor Detail
-
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 Detail
-
first
ConnectionFlow first(ConnectionFlowStep step)
Add aConnectionFlowStepto the beginning of this flow.
-
then
ConnectionFlow then(ConnectionFlowStep step)
Add aConnectionFlowStepto the end of this flow.
-
read
void read(Object msg)
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
private void doProcessCurrentStep(ProxyConnectionLogger LOG)
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
void fail(Throwable cause)
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.
-
-