public abstract class AbstractTCPProxyEngine extends Object implements TCPProxyEngine
Modifier and Type | Class and Description |
---|---|
protected class |
AbstractTCPProxyEngine.FilteredStreamThread
Runnable which actively reads an input stream and writes to an
output stream, passing the data through a filter. |
protected class |
AbstractTCPProxyEngine.OutputStreamFilterTee
Filter like class that delegates to a user filter and tees the result to an
output stream.
|
protected class |
AbstractTCPProxyEngine.StreamThread
Wrapper for handling stream threads.
|
Constructor and Description |
---|
AbstractTCPProxyEngine(TCPProxySocketFactory socketFactory,
TCPProxyFilter requestFilter,
TCPProxyFilter responseFilter,
PrintWriter output,
org.slf4j.Logger logger,
EndPoint localEndPoint,
boolean useColour,
int timeout)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
protected Socket |
accept()
Accept a connection using our server socket.
|
protected EndPoint |
getListenEndPoint()
Return the EndPoint we are listening on.
|
protected org.slf4j.Logger |
getLogger()
Accessor for the logger.
|
protected TerminalColour |
getRequestColour()
Allow subclasses to access colour terminal control code for request
streams.
|
protected TCPProxyFilter |
getRequestFilter()
Allow subclasses to access request filter.
|
protected TerminalColour |
getResponseColour()
Allow subclasses to access request terminal control code for response
streams.
|
protected TCPProxyFilter |
getResponseFilter()
Allow subclasses to access response filter.
|
protected TCPProxySocketFactory |
getSocketFactory()
Allow subclasses to access socket factory.
|
boolean |
isStopped()
Check whether this engine is stopped.
|
protected void |
launchThreadPair(Socket localSocket,
Socket remoteSocket,
EndPoint sourceEndPoint,
EndPoint targetEndPoint,
boolean isSecure)
Launch a pair of threads to handle bi-directional stream communication.
|
protected String |
logIOException(IOException e)
Log IOExceptions.
|
abstract void |
run()
Main event loop.
|
void |
stop()
Stop the engine and flush filter buffer.
|
public AbstractTCPProxyEngine(TCPProxySocketFactory socketFactory, TCPProxyFilter requestFilter, TCPProxyFilter responseFilter, PrintWriter output, org.slf4j.Logger logger, EndPoint localEndPoint, boolean useColour, int timeout) throws IOException
socketFactory
- Socket factory for creating our server and client sockets.requestFilter
- Request filter.responseFilter
- Response filter.output
- Where to direct the output.logger
- Logger.localEndPoint
- Local host and port to listen on. If the EndPoint
's
port is 0, an arbitrary port will be assigned.useColour
- Whether to use colour.timeout
- Timeout for server socket in milliseconds.IOException
- If an I/O error occurs.public void stop()
stop
in interface TCPProxyEngine
public boolean isStopped()
true
=> the engine is stopped.public abstract void run()
We do not implement InterruptibleRunnable
as we are not designed to be interrupted. If we are, code will throw an
UncheckedInterruptedException
- effectively an assertion.
protected Socket accept() throws net.grinder.tools.tcpproxy.AbstractTCPProxyEngine.NoActivityTimeOutException, IOException
IOException
- If an I/O error occurred.NoActivityTimeOutException
- If the accept timed out, and we have no active threads handling
connections.net.grinder.tools.tcpproxy.AbstractTCPProxyEngine.NoActivityTimeOutException
protected EndPoint getListenEndPoint()
EndPoint
.protected final TCPProxySocketFactory getSocketFactory()
protected final TCPProxyFilter getRequestFilter()
protected final TCPProxyFilter getResponseFilter()
protected final TerminalColour getRequestColour()
protected final TerminalColour getResponseColour()
protected final void launchThreadPair(Socket localSocket, Socket remoteSocket, EndPoint sourceEndPoint, EndPoint targetEndPoint, boolean isSecure) throws IOException
localSocket
- Local socket.remoteSocket
- Remote socket.sourceEndPoint
- The local EndPoint
to be used in the logging and filter
output. This may differ from the localSocket
binding.targetEndPoint
- The remote EndPoint
to be used in the logging and filter
output. This may differ from the remoteSocket
binding. *isSecure
- Whether the connection is secure.IOException
- If an I/O error occurs.protected final String logIOException(IOException e)
e
- The exception.protected final org.slf4j.Logger getLogger()
Logger
.Copyright © 2000-2014. All Rights Reserved.