Class SocketProxy
close()— drops all connections and stops accepting new ones (simulates connection refused)pause()/goOn()— freezes all data flow while keeping sockets open (simulates a hung network)reopen()— restores connectivity on the same port after aclose()
The proxy sits in front of Jetty by design: the Jetty server and ZooKeeper heartbeats continue running normally while the proxy makes the node appear unreachable to clients. A Jetty Handler cannot achieve this because it requires a TCP connection to already exist.
Implementation note: each accepted connection creates a SocketProxy.Bridge backed by two SocketProxy.Bridge.Pump threads (one per direction), using blocking I/O borrowed from ActiveMQ.
TODO: Replace the blocking-I/O SocketProxy.Bridge.Pump threads with a NIO
java.nio.channels.Selector-based implementation. The current model spawns 2 OS threads per
connection; under test load with many concurrent connections this is wasteful, and the PUMP_SOCKET_TIMEOUT_MS timeout means threads linger for up to 100 s after connections are
dropped. A single-selector loop would handle all connections with O(1) threads, as Jetty itself
does internally.
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intstatic final int -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()intintgetUrl()voidgoOn()voidbooleanvoidvoidpause()voidreopen()voidsetAcceptBacklog(int acceptBacklog) voidsetPauseAtStart(boolean pauseAtStart) voidsetReceiveBufferSize(int receiveBufferSize) voidtoString()booleanwaitUntilClosed(long timeoutSeconds)
-
Field Details
-
ACCEPT_TIMEOUT_MILLIS
public static final int ACCEPT_TIMEOUT_MILLIS- See Also:
-
PUMP_SOCKET_TIMEOUT_MS
public static final int PUMP_SOCKET_TIMEOUT_MS- See Also:
-
connections
-
-
Constructor Details
-
Method Details
-
open
- Throws:
Exception
-
toString
-
setReceiveBufferSize
public void setReceiveBufferSize(int receiveBufferSize) -
setTarget
-
getListenPort
public int getListenPort() -
getUrl
-
close
public void close() -
halfClose
public void halfClose() -
waitUntilClosed
- Throws:
InterruptedException
-
reopen
public void reopen() -
pause
public void pause() -
goOn
public void goOn() -
isPauseAtStart
public boolean isPauseAtStart() -
setPauseAtStart
public void setPauseAtStart(boolean pauseAtStart) -
getAcceptBacklog
public int getAcceptBacklog() -
setAcceptBacklog
public void setAcceptBacklog(int acceptBacklog)
-