// Path: comm-library/src/utility/JSONFilter.java
// public class JSONFilter implements Filter {
// 
// 	/* (non-Javadoc)
// 	 * @see java.util.logging.Filter#isLoggable(java.util.logging.LogRecord)
// 	 */
// 	@Override
// 	public boolean isLoggable(LogRecord record) {
// 		return JSONValue.isValidJsonStrict(record.getMessage());
// 	}
// 
// }
// 
// Path: comm-library/src/utility/JSONFormatter.java
// public class JSONFormatter extends Formatter {
// 
// 	/* (non-Javadoc)
// 	 * @see java.util.logging.Formatter#format(java.util.logging.LogRecord)
// 	 */
// 	@Override
// 	public String format(LogRecord record) {
// 		if (JSONValue.isValidJson(record.getMessage())) {
// 			return record.getMessage() + "\n";
// 		} else {
// 			
// 			return null;			
// 		}
// 	}
// 
// }
// 
// Path: comm-library/src/utility/Signal.java
// public class Signal extends AbstractThread {
// 	// time to wait between signaling
// 	private final int pauseOffset;
// 	// the signal boolean
// 	private boolean signal;
// 	// a shutdown signal
// 	private boolean go;
// 
// 	public Signal(int offset) {
// 		pauseOffset = offset;
// 		signal = false;
// 		go = true;
// 	}
// 
// 	public synchronized void shutdown() {
// 		go = false;
// 	}
// 
// 	public synchronized boolean getSignal() {
// 		return signal;
// 	}
// 
// 	public synchronized void signalTrue() {
// 		signal = true;
// 	}
// 
// 	public synchronized void signalFalse() {
// 		signal = false;
// 	}
// 
// 	@Override
// 	public void run() {
// 		try {
// 			// initial sleep to allow for initialization
// 			Thread.sleep(1000 * pauseOffset);
// 			while (go) {
// 				// signal
// 				signalTrue();
// 				// sleep
// 				Thread.sleep(1000 * pauseOffset);
// 			}
// 			System.out.println("Signal: finished");
// 		} catch (InterruptedException e) {
// 			System.err.println("Signal: failed");
// 			e.printStackTrace();
// 		}
// 
// 	}
// }


import java.io.IOException;
import java.util.Map;
import java.util.concurrent.BlockingQueue;
import java.util.logging.FileHandler;
import java.util.logging.Handler;
import java.util.logging.Level;
import java.util.logging.Logger;
import net.minidev.json.JSONObject;
import utility.JSONFilter;
import utility.JSONFormatter;
import utility.Signal;
/**
 * Copyright (c) 2012 Evolutionary Design and Optimization Group
 *
 * Licensed under the MIT License.
 *
 * See the "LICENSE" file for a copy of the license.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 *
 */
package node;



/**
 * A thread for recording JSON logs
 *
 * @author Owen Derby
 */
public class Reporter extends AbstractThread {

	private final BlockingQueue<JSONObject> reportSend;
	private Signal sig;
	private final static int signalFreq = 5; // seconds
	private static Logger localLog = Logger.getLogger("node.Reporter");
	private static Logger sendLog = Logger.getLogger("node.Reporter_send");

	private JSONObject myReport;

	public Reporter(BlockingQueue<JSONObject> reportSend2) {
		Handler fh;
		try {
			localLog.setUseParentHandlers(false);
			fh = new FileHandler("reporter.json");
			fh.setFormatter(new JSONFormatter());
			fh.setFilter(new JSONFilter());
			localLog.addHandler(fh);
			localLog.setLevel(Level.ALL);
		} catch (SecurityException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		try {
// Path: comm-library/src/utility/JSONFilter.java
// public class JSONFilter implements Filter {
// 
// 	/* (non-Javadoc)
// 	 * @see java.util.logging.Filter#isLoggable(java.util.logging.LogRecord)
// 	 */
// 	@Override
// 	public boolean isLoggable(LogRecord record) {
// 		return JSONValue.isValidJsonStrict(record.getMessage());
// 	}
// 
// }
// 
// Path: comm-library/src/utility/JSONFormatter.java
// public class JSONFormatter extends Formatter {
// 
// 	/* (non-Javadoc)
// 	 * @see java.util.logging.Formatter#format(java.util.logging.LogRecord)
// 	 */
// 	@Override
// 	public String format(LogRecord record) {
// 		if (JSONValue.isValidJson(record.getMessage())) {
// 			return record.getMessage() + "\n";
// 		} else {
// 			
// 			return null;			
// 		}
// 	}
// 
// }
// 
// Path: comm-library/src/utility/Signal.java
// public class Signal extends AbstractThread {
// 	// time to wait between signaling
// 	private final int pauseOffset;
// 	// the signal boolean
// 	private boolean signal;
// 	// a shutdown signal
// 	private boolean go;
// 
// 	public Signal(int offset) {
// 		pauseOffset = offset;
// 		signal = false;
// 		go = true;
// 	}
// 
// 	public synchronized void shutdown() {
// 		go = false;
// 	}
// 
// 	public synchronized boolean getSignal() {
// 		return signal;
// 	}
// 
// 	public synchronized void signalTrue() {
// 		signal = true;
// 	}
// 
// 	public synchronized void signalFalse() {
// 		signal = false;
// 	}
// 
// 	@Override
// 	public void run() {
// 		try {
// 			// initial sleep to allow for initialization
// 			Thread.sleep(1000 * pauseOffset);
// 			while (go) {
// 				// signal
// 				signalTrue();
// 				// sleep
// 				Thread.sleep(1000 * pauseOffset);
// 			}
// 			System.out.println("Signal: finished");
// 		} catch (InterruptedException e) {
// 			System.err.println("Signal: failed");
// 			e.printStackTrace();
// 		}
// 
// 	}
// }


// Path: comm-library/src/node/Reporter.java
import java.io.IOException;
import java.util.Map;
import java.util.concurrent.BlockingQueue;
import java.util.logging.FileHandler;
import java.util.logging.Handler;
import java.util.logging.Level;
import java.util.logging.Logger;
import net.minidev.json.JSONObject;
import utility.JSONFilter;
import utility.JSONFormatter;
import utility.Signal;

/**
 * Copyright (c) 2012 Evolutionary Design and Optimization Group
 *
 * Licensed under the MIT License.
 *
 * See the "LICENSE" file for a copy of the license.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 *
 */
package node;



/**
 * A thread for recording JSON logs
 *
 * @author Owen Derby
 */
public class Reporter extends AbstractThread {

	private final BlockingQueue<JSONObject> reportSend;
	private Signal sig;
	private final static int signalFreq = 5; // seconds
	private static Logger localLog = Logger.getLogger("node.Reporter");
	private static Logger sendLog = Logger.getLogger("node.Reporter_send");

	private JSONObject myReport;

	public Reporter(BlockingQueue<JSONObject> reportSend2) {
		Handler fh;
		try {
			localLog.setUseParentHandlers(false);
			fh = new FileHandler("reporter.json");
			fh.setFormatter(new JSONFormatter());
			fh.setFilter(new JSONFilter());
			localLog.addHandler(fh);
			localLog.setLevel(Level.ALL);
		} catch (SecurityException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		try {
			sendLog.setUseParentHandlers(false);