<commit_before>package src.io.controller;

import java.util.HashMap;
import java.util.concurrent.ConcurrentLinkedQueue;

import src.IO_Bundle;
import src.Key_Commands;
import src.QueueCommandInterface;
import src.io.view.Viewport;
import src.io.view.display.Display;

/**
 * Abstract controller class
 *
 * @author mbregg
 *
 */
public abstract class Controller implements QueueCommandInterface<Character> {

    private KeyRemapper remap_;
    private Viewport currentView_;
    private String userName_;
    private ConcurrentLinkedQueue<Key_Commands> keyCommandQueue_ = new ConcurrentLinkedQueue<Key_Commands>();
    private ConcurrentLinkedQueue<Character> characterQueue_ = new ConcurrentLinkedQueue<Character>();
    private Thread controllerThread_ = Thread.currentThread();
    
    public void grusomelyKillTheControllerThread() {
        if(controllerThread_.isAlive()) {
            controllerThread_.stop();
        }
    }

    public void setControlling(String in) {
        userName_ = in;
    }

    public Controller(Viewport view, KeyRemapper remap, String uName) {
        remap_ = remap;
        currentView_ = view;
        userName_ = uName;
        Display.getDisplay().addDirectCommandReceiver(new QueueCommandInterface<Key_Commands>() {

            @Override
            public void enqueue(Key_Commands command) {
                keyCommandQueue_.add(command);

            }

            @Override
            public void sendInterrupt() {
                Controller.this.sendInterrupt();

            }
        });
        Display.getDisplay().addGameInputerHandler(this);
        Display.getDisplay().setView(currentView_);
        Display.getDisplay().printView();
    }

    protected void sleepLoop() {

        while (true) {
        	System.out.println("Entetered sleep loop");
        	try {
        		if(!controllerThread_.interrupted()){//If we are interuppted, don't bother sleeping again.
        			Thread.sleep(500L);
        		}
        	} catch (InterruptedException e) {}
        		System.out.println("InterruptedInnerLoop");
    			process();
    			System.out.println("InterruptedInnerLoopEnd");

        	System.out.println("Exited sleep loop"); //Exited
        }
    }

    protected void process() {
        System.out.println("Processing!");
    	if(characterQueue_.peek()!=null){
    	characterQueue_.add(characterQueue_.peek());
    	characterQueue_.add(characterQueue_.peek());
    	}
    	System.out.println("Queue Size" + characterQueue_.size());
        if(characterQueue_.size()!=0){
        	System.out.println("Qeueu size " + characterQueue_.size());
        }
        while (!keyCommandQueue_.isEmpty()) {
        	Key_Commands c = keyCommandQueue_.remove();
        	if(c!=null){
        		takeTurnandPrintTurn(c);
        	}
        }<commit_msg>PRocess is now handled correctly, done if no exception after 500 ms, or on exception, within try block.<commit_after>package src.io.controller;

import java.util.HashMap;
import java.util.concurrent.ConcurrentLinkedQueue;

import src.IO_Bundle;
import src.Key_Commands;
import src.QueueCommandInterface;
import src.io.view.Viewport;
import src.io.view.display.Display;

/**
 * Abstract controller class
 *
 * @author mbregg
 *
 */
public abstract class Controller implements QueueCommandInterface<Character> {

    private KeyRemapper remap_;
    private Viewport currentView_;
    private String userName_;
    private ConcurrentLinkedQueue<Key_Commands> keyCommandQueue_ = new ConcurrentLinkedQueue<Key_Commands>();
    private ConcurrentLinkedQueue<Character> characterQueue_ = new ConcurrentLinkedQueue<Character>();
    private Thread controllerThread_ = Thread.currentThread();
    
    public void grusomelyKillTheControllerThread() {
        if(controllerThread_.isAlive()) {
            controllerThread_.stop();
        }
    }

    public void setControlling(String in) {
        userName_ = in;
    }

    public Controller(Viewport view, KeyRemapper remap, String uName) {
        remap_ = remap;
        currentView_ = view;
        userName_ = uName;
        Display.getDisplay().addDirectCommandReceiver(new QueueCommandInterface<Key_Commands>() {

            @Override
            public void enqueue(Key_Commands command) {
                keyCommandQueue_.add(command);

            }

            @Override
            public void sendInterrupt() {
                Controller.this.sendInterrupt();

            }
        });
        Display.getDisplay().addGameInputerHandler(this);
        Display.getDisplay().setView(currentView_);
        Display.getDisplay().printView();
    }

    protected void sleepLoop() {

        while (true) {
        	System.out.println("Entetered sleep loop");
        	try {
        		if(!controllerThread_.interrupted()){//If we are interuppted, don't bother sleeping again.
        			Thread.sleep(500L);
        			process();
        		}
        	} catch (InterruptedException e) {
        		System.out.println("InterruptedInnerLoop");
    			process();
    			System.out.println("InterruptedInnerLoopEnd");
        	}


        	System.out.println("Exited sleep loop"); //Exited
        }
    }

    protected void process() {
        System.out.println("Processing!");

        while (!keyCommandQueue_.isEmpty()) {
        	Key_Commands c = keyCommandQueue_.remove();
        	if(c!=null){
        		takeTurnandPrintTurn(c);
        	}
        }
{'fraction_non_alphanumeric': 0.10284342688330872, 'fraction_numerical': 0.001846381093057607, 'mean_word_length': 2.675033921302578, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, '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': '4025912', 'n_tokens_mistral': 1503, 'n_tokens_neox': 1469, 'n_words': 286}