<commit_before>/* 
 * Copyright (c) 2012, noxan
 * See LICENSE for details.
 */

package com.github.noxan.aves.server;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.SocketTimeoutException;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;

import com.github.noxan.aves.net.Connection;
import com.github.noxan.aves.net.SocketConnection;
import com.github.noxan.aves.util.Tuple;


public class SocketServer implements Server, Runnable {
    private String host;
    private int port;

    private BlockingQueue<Tuple<ServerEvent, Object>> serverEvents;
    private ServerHandler handler;

    private Set<Connection> connections;

    private ServerSocket server;
    private Thread serverThread;

    private EventManager manager;
    private Thread managerThread;

    public SocketServer(ServerHandler handler) {
        this("0.0.0.0", 1666, handler);
    }

    public SocketServer(String host, int port, ServerHandler handler) {
        this.host = host;
        this.port = port;
        this.handler = handler;
        serverEvents = new LinkedBlockingQueue<Tuple<ServerEvent, Object>>();
        connections = new HashSet<Connection>();
    }

    @Override
    public void start() {
        try {
            server = new ServerSocket();
            server.setSoTimeout(1000);
            server.bind(new InetSocketAddress(host, port));
            manager = new EventManager();
            serverThread = new Thread(this);
            serverThread.start();
            managerThread = new Thread(manager);
            managerThread.start();
        } catch(IOException e) {
            e.printStackTrace();
        }
    }

    @Override
    public void run() {
        while(true) {
            try {
                Socket socket = server.accept();
                Connection connection = new SocketConnection(this, socket);
                connection.start();
            } catch(SocketTimeoutException e) {
            } catch(IOException e) {
                e.printStackTrace();
            }
        }
    }

    @Override
    public Set<Connection> getConnections() {
        return Collections.unmodifiableSet(connections);
    }

    public void broadcast(Object data) throws IOException {
        for(Connection connection:connections) {<commit_msg>remove eventmanager as attribute from socketserver<commit_after>/* 
 * Copyright (c) 2012, noxan
 * See LICENSE for details.
 */

package com.github.noxan.aves.server;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.SocketTimeoutException;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;

import com.github.noxan.aves.net.Connection;
import com.github.noxan.aves.net.SocketConnection;
import com.github.noxan.aves.util.Tuple;


public class SocketServer implements Server, Runnable {
    private String host;
    private int port;

    private BlockingQueue<Tuple<ServerEvent, Object>> serverEvents;
    private ServerHandler handler;

    private Set<Connection> connections;

    private ServerSocket server;
    private Thread serverThread;

    private Thread managerThread;

    public SocketServer(ServerHandler handler) {
        this("0.0.0.0", 1666, handler);
    }

    public SocketServer(String host, int port, ServerHandler handler) {
        this.host = host;
        this.port = port;
        this.handler = handler;
        serverEvents = new LinkedBlockingQueue<Tuple<ServerEvent, Object>>();
        connections = new HashSet<Connection>();
    }

    @Override
    public void start() {
        try {
            server = new ServerSocket();
            server.setSoTimeout(1000);
            server.bind(new InetSocketAddress(host, port));
            serverThread = new Thread(this);
            serverThread.start();
            managerThread = new Thread(new EventManager());
            managerThread.start();
        } catch(IOException e) {
            e.printStackTrace();
        }
    }

    @Override
    public void run() {
        while(true) {
            try {
                Socket socket = server.accept();
                Connection connection = new SocketConnection(this, socket);
                connection.start();
            } catch(SocketTimeoutException e) {
            } catch(IOException e) {
                e.printStackTrace();
            }
        }
    }

    @Override
    public Set<Connection> getConnections() {
        return Collections.unmodifiableSet(connections);
    }

    public void broadcast(Object data) throws IOException {
        for(Connection connection:connections) {
{'fraction_non_alphanumeric': 0.09480308566788469, 'fraction_numerical': 0.006496142915144133, 'mean_word_length': 2.617474302496329, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '129661', 'n_tokens_mistral': 1323, 'n_tokens_neox': 1254, 'n_words': 314}