shutdown explicitly at the end of build session

This commit is contained in:
Eugene Zhuravlev
2012-05-17 23:33:35 +02:00
parent 4329e6c6e8
commit acaf96d954
2 changed files with 22 additions and 26 deletions
@@ -88,6 +88,7 @@ public class BuildMain {
public void messageReceived(final ChannelHandlerContext ctx, MessageEvent e) throws Exception {
CmdlineRemoteProto.Message message = (CmdlineRemoteProto.Message)e.getMessage();
final CmdlineRemoteProto.Message.Type type = message.getType();
final Channel channel = ctx.getChannel();
if (type == CmdlineRemoteProto.Message.Type.CONTROLLER_MESSAGE) {
final CmdlineRemoteProto.Message.ControllerMessage controllerMessage = message.getControllerMessage();
@@ -96,9 +97,19 @@ public class BuildMain {
case BUILD_PARAMETERS: {
if (mySession == null) {
final CmdlineRemoteProto.Message.ControllerMessage.FSEvent delta = controllerMessage.hasFsEvent()? controllerMessage.getFsEvent() : null;
final BuildSession session = new BuildSession(mySessionId, ctx.getChannel(), controllerMessage.getParamsMessage(), delta);
final BuildSession session = new BuildSession(mySessionId, channel, controllerMessage.getParamsMessage(), delta);
mySession = session;
SharedThreadPool.INSTANCE.submit(session);
SharedThreadPool.INSTANCE.submit(new Runnable() {
public void run() {
try {
session.run();
}
finally {
channel.close();
System.exit(0);
}
}
});
}
else {
LOG.info("Cannot start another build session because one is already running");
@@ -129,14 +140,14 @@ public class BuildMain {
}
else {
LOG.info("Cannot cancel build: no build session is running");
closeChannel(ctx.getChannel());
channel.close();
}
return;
}
}
}
Channels.write(ctx.getChannel(), CmdlineProtoUtil.toMessage(mySessionId, CmdlineProtoUtil.createFailure("Unsupported message type: " + type.name(), null)));
Channels.write(channel, CmdlineProtoUtil.toMessage(mySessionId, CmdlineProtoUtil.createFailure("Unsupported message type: " + type.name(), null)));
}
@Override
@@ -164,20 +175,11 @@ public class BuildMain {
super.channelDisconnected(ctx, e);
}
finally {
closeChannel(ctx.getChannel());
ctx.getChannel().close();
}
}
}
private static void closeChannel(final Channel channel) {
SharedThreadPool.INSTANCE.submit(new Runnable() {
@Override
public void run() {
channel.close();
}
});
}
private static void initLoggers() {
if (new File(LOG_FILE_NAME).exists()) {
DOMConfigurator.configure(LOG_FILE_NAME);
@@ -11,8 +11,6 @@ import groovy.util.Node;
import groovy.util.XmlParser;
import org.codehaus.groovy.runtime.MethodClosure;
import org.jboss.netty.channel.Channel;
import org.jboss.netty.channel.ChannelFuture;
import org.jboss.netty.channel.ChannelFutureListener;
import org.jboss.netty.channel.Channels;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.ether.dependencyView.Callbacks;
@@ -434,16 +432,12 @@ final class BuildSession implements Runnable, CanceledStatus {
lastMessage = CmdlineProtoUtil.toMessage(mySessionId, CmdlineProtoUtil.createFailure(e.getMessage(), e));
}
finally {
Channels.write(myChannel, lastMessage).addListener(new ChannelFutureListener() {
public void operationComplete(ChannelFuture future) throws Exception {
SharedThreadPool.INSTANCE.submit(new Runnable() {
@Override
public void run() {
myChannel.close();
}
});
}
});
try {
Channels.write(myChannel, lastMessage).await();
}
catch (InterruptedException e) {
LOG.info(e);
}
}
}