<commit_before>/**
 * Copyright 2011 The Open Source Research Group,
 *                University of Erlangen-Nürnberg
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.sweble.wikitext.articlecruncher;

import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingDeque;

import org.apache.log4j.Logger;
import org.sweble.wikitext.articlecruncher.utils.AbortHandler;
import org.sweble.wikitext.articlecruncher.utils.ConsoleWriter;
import org.sweble.wikitext.articlecruncher.utils.ExecutorType;
import org.sweble.wikitext.articlecruncher.utils.MyExecutorService;
import org.sweble.wikitext.articlecruncher.utils.WorkerBase;
import org.sweble.wikitext.articlecruncher.utils.WorkerSynchronizer;

public class Nexus
{
	public static enum NexusState
	{
		INITIALIZED,
		RUNNING,
		SHUTDOWN
	}
	
	// =========================================================================
	
	private static Nexus nexus;
	
	public static Nexus get()
	{
		if (nexus == null)
			nexus = new Nexus();
		return nexus;
	}
	
	public static ConsoleWriter getConsoleWriter()
	{
		return get().consoleWriter;
	}
	
	// =========================================================================
	
	private static final Logger logger =
			Logger.getLogger(Nexus.class.getName());
	
	private static final int COMPLETION_TIMEOUT_IN_SECONDS = 60 * 5;
	
	// =========================================================================
	
	private BlockingQueue<JobWithHistory> inTray;
	
	private BlockingQueue<JobWithHistory> completedJobs;
	
	private BlockingQueue<CompletedJob> outTray;
	
	private JobTraceSet jobTraces = new JobTraceSet();
	
	private MyExecutorService executor;
	
	private Throwable emergencyCause;
	
	//private WorkerBase parser;
	
	private WorkerBase gatherer;
	
	//private WorkerBase storer;
	
	private ConsoleWriter consoleWriter;
	
	private NexusState state;
	
	private AbortHandler abortHandler;
	
	private WorkerSynchronizer synchronizer = new WorkerSynchronizer();
	
	private List<WorkerBase> jobGenerators = new ArrayList<WorkerBase>();
	
	private List<WorkerBase> processingNodes = new ArrayList<WorkerBase>();
	
	private List<WorkerBase> storers = new ArrayList<WorkerBase>();
	
	// =========================================================================
	
	private Nexus()
	{
	}
	
	// =========================================================================
	
	public void setUp(
			File dumpFile,
			int inTrayCapacity,
			int completedJobsCapacity,
			int outTrayCapacity) throws Throwable
	{
		synchronized (synchronizer.getMonitor())
		{
			if (state != null)
				throw new IllegalStateException("Can only set-up Nexus once");
			
			try
			{
				logger.info("Nexus starting");
				
				inTray = new LinkedBlockingDeque<JobWithHistory>(inTrayCapacity);
				
				completedJobs = new LinkedBlockingDeque<JobWithHistory>(completedJobsCapacity);<commit_msg>Removed uneccessary parameter<commit_after>/**
 * Copyright 2011 The Open Source Research Group,
 *                University of Erlangen-Nürnberg
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.sweble.wikitext.articlecruncher;

import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingDeque;

import org.apache.log4j.Logger;
import org.sweble.wikitext.articlecruncher.utils.AbortHandler;
import org.sweble.wikitext.articlecruncher.utils.ConsoleWriter;
import org.sweble.wikitext.articlecruncher.utils.ExecutorType;
import org.sweble.wikitext.articlecruncher.utils.MyExecutorService;
import org.sweble.wikitext.articlecruncher.utils.WorkerBase;
import org.sweble.wikitext.articlecruncher.utils.WorkerSynchronizer;

public class Nexus
{
	public static enum NexusState
	{
		INITIALIZED,
		RUNNING,
		SHUTDOWN
	}
	
	// =========================================================================
	
	private static Nexus nexus;
	
	public static Nexus get()
	{
		if (nexus == null)
			nexus = new Nexus();
		return nexus;
	}
	
	public static ConsoleWriter getConsoleWriter()
	{
		return get().consoleWriter;
	}
	
	// =========================================================================
	
	private static final Logger logger =
			Logger.getLogger(Nexus.class.getName());
	
	private static final int COMPLETION_TIMEOUT_IN_SECONDS = 60 * 5;
	
	// =========================================================================
	
	private BlockingQueue<JobWithHistory> inTray;
	
	private BlockingQueue<JobWithHistory> completedJobs;
	
	private BlockingQueue<CompletedJob> outTray;
	
	private JobTraceSet jobTraces = new JobTraceSet();
	
	private MyExecutorService executor;
	
	private Throwable emergencyCause;
	
	//private WorkerBase parser;
	
	private WorkerBase gatherer;
	
	//private WorkerBase storer;
	
	private ConsoleWriter consoleWriter;
	
	private NexusState state;
	
	private AbortHandler abortHandler;
	
	private WorkerSynchronizer synchronizer = new WorkerSynchronizer();
	
	private List<WorkerBase> jobGenerators = new ArrayList<WorkerBase>();
	
	private List<WorkerBase> processingNodes = new ArrayList<WorkerBase>();
	
	private List<WorkerBase> storers = new ArrayList<WorkerBase>();
	
	// =========================================================================
	
	private Nexus()
	{
	}
	
	// =========================================================================
	
	public void setUp(
			int inTrayCapacity,
			int completedJobsCapacity,
			int outTrayCapacity) throws Throwable
	{
		synchronized (synchronizer.getMonitor())
		{
			if (state != null)
				throw new IllegalStateException("Can only set-up Nexus once");
			
			try
			{
				logger.info("Nexus starting");
				
				inTray = new LinkedBlockingDeque<JobWithHistory>(inTrayCapacity);
				
				completedJobs = new LinkedBlockingDeque<JobWithHistory>(completedJobsCapacity);
{'fraction_non_alphanumeric': 0.1786021197364652, 'fraction_numerical': 0.0034374104841019765, 'mean_word_length': 4.868067226890756, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '4048285', 'n_tokens_mistral': 2158, 'n_tokens_neox': 1839, 'n_words': 511}