<commit_before>package nl.mpi.arbil.wicket;

import nl.mpi.arbil.data.DefaultDataNodeLoader;
import nl.mpi.arbil.data.DataNodeLoaderThreadManager;
import nl.mpi.arbil.data.DataNodeLoader;
import nl.mpi.arbil.userstorage.ArbilSessionStorage;
import nl.mpi.arbil.userstorage.SessionStorage;
import nl.mpi.arbil.util.DefaultMimeHashQueue;
import nl.mpi.arbil.util.MimeHashQueue;
import nl.mpi.arbil.util.TreeHelper;
import nl.mpi.arbil.wicket.pages.HomePage;
import org.apache.wicket.Application;
import org.apache.wicket.Request;
import org.apache.wicket.Response;
import org.apache.wicket.Session;
import org.apache.wicket.protocol.http.WebApplication;

public class ArbilWicketApplication extends WebApplication {

    /**
     * Constructor
     */
    public ArbilWicketApplication() {
	ArbilWicketInjector.injectHandlers();
    }

    /**
     * @see org.apache.wicket.Application#getHomePage()
     */
    public Class<HomePage> getHomePage() {
	return HomePage.class;
    }

    @Override
    public Session newSession(Request request, Response response) {
	// We don't want no ordinary session we don't!
	return new ArbilWicketSession(this, request);
    }

    /**
     * Creates a new arbil SessionStorage
     * @return New session storage object
     */
    public SessionStorage newSessionStorage() {
	return ArbilSessionStorage.getSingleInstance();
    }

    /**
     * 
     * @param sessionStorage Session storage the treehelper should be tied to
     * @return New treehelper object
     */
    public TreeHelper newTreeHelper(final SessionStorage sessionStorage) {
	return new ArbilWicketTreeHelper(sessionStorage);
    }

    DataNodeLoader newDataNodeLoader(ArbilWicketSession session) {
	return new DefaultDataNodeLoader(newLoaderThreadManager(session));
    }

    /**
     * 
     * @param session Session to set as session in any new loader thread (generally Session.get() will do)
     * @return New LoaderThreadManager instance
     */
    private DataNodeLoaderThreadManager newLoaderThreadManager(final Session session) {
	return new DataNodeLoaderThreadManager() {

	    @Override
	    protected void beforeExecuteLoaderThread(Thread t, Runnable r, boolean local) {
		super.beforeExecuteLoaderThread(t, r, local);
		// Set application and session copies for the new thread
		Application.set(ArbilWicketApplication.this);
		Session.set(session);
	    }

	    @Override
	    protected void afterExecuteLoaderThread(Runnable r, Throwable t, boolean local) {
		super.afterExecuteLoaderThread(r, t, local);
		// Clean up
		Application.unset();
		Session.unset();
	    }
	};
    }

    MimeHashQueue newMimeHashQueue(final ArbilWicketSession session) {
	MimeHashQueue newHashQueue = new DefaultMimeHashQueue();
	newHashQueue.startMimeHashQueueThread();
	return newHashQueue;
    }
}<commit_msg>New MimeHashQueues in Arbil Wicket Session extend DefaultMimeHashQueue to hook into mime hash queue thread and set app + session<commit_after>package nl.mpi.arbil.wicket;

import nl.mpi.arbil.data.DefaultDataNodeLoader;
import nl.mpi.arbil.data.DataNodeLoaderThreadManager;
import nl.mpi.arbil.data.DataNodeLoader;
import nl.mpi.arbil.userstorage.ArbilSessionStorage;
import nl.mpi.arbil.userstorage.SessionStorage;
import nl.mpi.arbil.util.DefaultMimeHashQueue;
import nl.mpi.arbil.util.MimeHashQueue;
import nl.mpi.arbil.util.TreeHelper;
import nl.mpi.arbil.wicket.pages.HomePage;
import org.apache.wicket.Application;
import org.apache.wicket.Request;
import org.apache.wicket.Response;
import org.apache.wicket.Session;
import org.apache.wicket.protocol.http.WebApplication;

public class ArbilWicketApplication extends WebApplication {

    /**
     * Constructor
     */
    public ArbilWicketApplication() {
	ArbilWicketInjector.injectHandlers();
    }

    /**
     * @see org.apache.wicket.Application#getHomePage()
     */
    public Class<HomePage> getHomePage() {
	return HomePage.class;
    }

    @Override
    public Session newSession(Request request, Response response) {
	// We don't want no ordinary session we don't!
	return new ArbilWicketSession(this, request);
    }

    /**
     * Creates a new arbil SessionStorage
     * @return New session storage object
     */
    public SessionStorage newSessionStorage() {
	return ArbilSessionStorage.getSingleInstance();
    }

    /**
     * 
     * @param sessionStorage Session storage the treehelper should be tied to
     * @return New treehelper object
     */
    public TreeHelper newTreeHelper(final SessionStorage sessionStorage) {
	return new ArbilWicketTreeHelper(sessionStorage);
    }

    /**
     * 
     * @param session Session to set as session in any new loader thread (generally Session.get() will do)
     * @return New DataNodeLoader instance
     */
    DataNodeLoader newDataNodeLoader(ArbilWicketSession session) {
	return new DefaultDataNodeLoader(newLoaderThreadManager(session));
    }

    /**
     * 
     * @param session Session to set as session in the mime hash queue thread (generally Session.get() will do)
     * @return New MimeHashQueue instance
     */
    public MimeHashQueue newMimeHashQueue(final ArbilWicketSession session) {
	MimeHashQueue newHashQueue = new DefaultMimeHashQueue() {

	    @Override
	    protected void beforeExecuteThread(Thread t, Runnable r) {
		super.beforeExecuteThread(t, r);
		// Set application and session copies for the new thread
		setupSessionInThread(session);
	    }

	    @Override
	    protected void afterExecuteThread(Runnable r, Throwable t) {
		super.afterExecuteThread(r, t);
		// Clean up
		cleanupSessionInThread();
	    }
	};
	newHashQueue.startMimeHashQueueThread();
	return newHashQueue;
    }

    private DataNodeLoaderThreadManager newLoaderThreadManager(final Session session) {
	return new DataNodeLoaderThreadManager() {

	    @Override
	    protected void beforeExecuteLoaderThread(Thread t, Runnable r, boolean local) {
		super.beforeExecuteLoaderThread(t, r, local);
		// Set application and session copies for the new thread
		setupSessionInThread(session);
	    }

	    @Override
	    protected void afterExecuteLoaderThread(Runnable r, Throwable t, boolean local) {
		super.afterExecuteLoaderThread(r, t, local);
		// Clean up
		cleanupSessionInThread();
	    }
	};
    }

    private void setupSessionInThread(Session session) {
	Application.set(ArbilWicketApplication.this);
	Session.set(session);
    }

    private void cleanupSessionInThread() {
	Application.unset();
	Session.unset();
    }
}
{'fraction_non_alphanumeric': 0.0879222582137899, 'fraction_numerical': 0.0, 'mean_word_length': 3.9571865443425076, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '2563533', 'n_tokens_mistral': 1943, 'n_tokens_neox': 1863, 'n_words': 452}