<commit_before>package com.brewtab.irc.impl;

import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import org.jboss.netty.channel.Channel;
import org.jboss.netty.channel.ChannelFuture;
import org.jboss.netty.channel.ChannelHandlerContext;
import org.jboss.netty.channel.ChannelStateEvent;
import org.jboss.netty.channel.ExceptionEvent;
import org.jboss.netty.channel.MessageEvent;
import org.jboss.netty.channel.SimpleChannelHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.brewtab.irc.Connection;
import com.brewtab.irc.ConnectionStateListener;
import com.brewtab.irc.NotConnectedException;
import com.brewtab.irc.messages.Message;
import com.brewtab.irc.messages.MessageListener;
import com.brewtab.irc.messages.filter.MessageFilter;
import com.brewtab.irc.messages.filter.MessageFilters;

class ConnectionImpl extends SimpleChannelHandler implements Connection {
    private static final Logger log = LoggerFactory.getLogger(ConnectionImpl.class);

    private Channel channel;
    private boolean connected;
    private Map<MessageListener, MessageFilter> messageListeners;
    private List<ConnectionStateListener> connectionStateListeners;
    private ExecutorService executor;

    public ConnectionImpl() {
        channel = null;
        connected = false;

        messageListeners = new ConcurrentHashMap<MessageListener, MessageFilter>();
        connectionStateListeners = Collections.synchronizedList(new ArrayList<ConnectionStateListener>());

        executor = Executors.newCachedThreadPool();
    }

    @Override
    public void channelOpen(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception {
        log.debug("channel opened");

        channel = ctx.getChannel();
        super.channelOpen(ctx, e);
    }

    @Override
    public void channelConnected(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception {
        log.debug("channel connected");

        connected = true;

        for (final ConnectionStateListener listener : connectionStateListeners) {
            executor.execute(new Runnable() {
                @Override
                public void run() {
                    try {
                        listener.onConnectionConnected();
                    } catch (Exception e) {<commit_msg>Fix ConcurrentModificationException<commit_after>package com.brewtab.irc.impl;

import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import org.jboss.netty.channel.Channel;
import org.jboss.netty.channel.ChannelFuture;
import org.jboss.netty.channel.ChannelHandlerContext;
import org.jboss.netty.channel.ChannelStateEvent;
import org.jboss.netty.channel.ExceptionEvent;
import org.jboss.netty.channel.MessageEvent;
import org.jboss.netty.channel.SimpleChannelHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.brewtab.irc.Connection;
import com.brewtab.irc.ConnectionStateListener;
import com.brewtab.irc.NotConnectedException;
import com.brewtab.irc.messages.Message;
import com.brewtab.irc.messages.MessageListener;
import com.brewtab.irc.messages.filter.MessageFilter;
import com.brewtab.irc.messages.filter.MessageFilters;

class ConnectionImpl extends SimpleChannelHandler implements Connection {
    private static final Logger log = LoggerFactory.getLogger(ConnectionImpl.class);

    private Channel channel;
    private boolean connected;
    private Map<MessageListener, MessageFilter> messageListeners;
    private List<ConnectionStateListener> connectionStateListeners;
    private ExecutorService executor;

    public ConnectionImpl() {
        channel = null;
        connected = false;

        messageListeners = new ConcurrentHashMap<MessageListener, MessageFilter>();
        connectionStateListeners = new CopyOnWriteArrayList<ConnectionStateListener>();

        executor = Executors.newCachedThreadPool();
    }

    @Override
    public void channelOpen(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception {
        log.debug("channel opened");

        channel = ctx.getChannel();
        super.channelOpen(ctx, e);
    }

    @Override
    public void channelConnected(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception {
        log.debug("channel connected");

        connected = true;

        for (final ConnectionStateListener listener : connectionStateListeners) {
            executor.execute(new Runnable() {
                @Override
                public void run() {
                    try {
                        listener.onConnectionConnected();
                    } catch (Exception e) {
{'fraction_non_alphanumeric': 0.0844219146032365, 'fraction_numerical': 0.0007798791187365958, 'mean_word_length': 3.9613152804642167, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '532734', 'n_tokens_mistral': 1362, 'n_tokens_neox': 1317, 'n_words': 281}