Permalink
Browse files

#66 manage up / down state of server in a simpler way

the callbacks don't work the way I assumed. This is not a particularly good solution & needs something better
  • Loading branch information...
1 parent 940918e commit 081aa8b91baa80db7f1470f2927b45b4168ebe2b Rob Fletcher committed Aug 3, 2013
@@ -37,6 +37,7 @@ public InetSocketAddress run() throws Exception {
public void shutdown() throws InterruptedException {
if (channel != null) channel.close().sync();
if (group != null) group.shutdownGracefully();
+ if (group != null) group.shutdownGracefully().sync();
}
}
@@ -32,7 +32,6 @@ import static java.util.logging.Level.SEVERE
public class BetamaxChannelHandler extends ChannelInboundHandlerAdapter {
private HttpHandler handlerChain
- private boolean active = false
private static final Logger log = Logger.getLogger(BetamaxChannelHandler.class.name)
@@ -52,22 +51,6 @@ public class BetamaxChannelHandler extends ChannelInboundHandlerAdapter {
}
}
- @Override
- void channelActive(ChannelHandlerContext context) throws Exception {
- super.channelActive(context)
- active = true
- }
-
- @Override
- void channelInactive(ChannelHandlerContext context) throws Exception {
- super.channelInactive(context)
- active = false
- }
-
- boolean isActive() {
- active
- }
-
HttpHandler leftShift(HttpHandler httpHandler) {
handlerChain = httpHandler
handlerChain
@@ -32,6 +32,7 @@ class ProxyServer implements HttpInterceptor {
private final ProxyRecorder recorder
private final ProxyOverrider proxyOverrider = new ProxyOverrider()
private final SSLOverrider sslOverrider = new SSLOverrider()
+ private boolean running = false
ProxyServer(ProxyRecorder recorder) {
this.recorder = recorder
@@ -45,24 +46,27 @@ class ProxyServer implements HttpInterceptor {
@Override
boolean isRunning() {
- proxyHandler.active
+ running
}
void start() {
// def connectHandler = new CustomConnectHandler(handler, port + 1)
-
+ if (isRunning()) throw new IllegalStateException("Betamax proxy server is already running")
proxyServer.run()
+ running = true
overrideProxySettings()
overrideSSLSettings()
}
@Override
void stop() {
+ if (!isRunning()) throw new IllegalStateException("Betamax proxy server is already stopped")
restoreOriginalProxySettings()
restoreOriginalSSLSettings()
proxyServer.shutdown()
+ running = false
}
@Override

0 comments on commit 081aa8b

Please sign in to comment.