+ private void cancelSession(UUID targetSessionId) {
+ synchronized (myBuildsInProgress) {
+ for (Iterator<Pair<RunnableFuture, CompilationTask>> it = myBuildsInProgress.iterator(); it.hasNext(); ) {
+ final Pair<RunnableFuture, CompilationTask> pair = it.next();
+ final CompilationTask task = pair.second;
+ if (task.getSessionId().equals(targetSessionId)) {
+ it.remove();
+ task.cancel();
+ pair.first.cancel(true);
+ break;
+ }
+ }
+ }
+ }
+
+ @Override
+ public void channelDisconnected(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception {
+ final Object attachment = ctx.getAttachment();
+ if (attachment instanceof UUID) {
+ cancelSession((UUID)attachment);
+ }
+ super.channelDisconnected(ctx, e);
+ }
+